Little fixes:
- changing random(max) to use stdlib.h random() - not generating .eep files to avoid warning when EEMEM isn't used - removing cast macros (since they are automatically defined in C++) - writing a digital LOW for PWM value of 0 on pins 5 or 6
This commit is contained in:
parent
b7ec38e61a
commit
5444b25e11
|
@ -29,23 +29,22 @@ extern "C" {
|
|||
|
||||
void randomSeed(unsigned int seed)
|
||||
{
|
||||
if(seed != 0){
|
||||
srand(seed);
|
||||
if (seed != 0) {
|
||||
srandom(seed);
|
||||
}
|
||||
}
|
||||
|
||||
long random(long howbig)
|
||||
{
|
||||
long value;
|
||||
if (howbig == 0){
|
||||
if (howbig == 0) {
|
||||
return 0;
|
||||
}
|
||||
return (rand() * 0x10000L + rand()) % howbig;
|
||||
return random() % howbig;
|
||||
}
|
||||
|
||||
long random(long howsmall, long howbig)
|
||||
{
|
||||
if(howsmall >= howbig){
|
||||
if (howsmall >= howbig) {
|
||||
return howsmall;
|
||||
}
|
||||
long diff = howbig - howsmall;
|
||||
|
|
|
@ -66,12 +66,12 @@ extern "C"{
|
|||
#undef abs
|
||||
#endif
|
||||
|
||||
#define int(x) ((int)(x))
|
||||
#define char(x) ((char)(x))
|
||||
#define long(x) ((long)(x))
|
||||
#define byte(x) ((uint8_t)(x))
|
||||
#define float(x) ((float)(x))
|
||||
#define boolean(x) ((uint8_t)((x)==0?0:1))
|
||||
//#define int(x) ((int)(x))
|
||||
//#define char(x) ((char)(x))
|
||||
//#define long(x) ((long)(x))
|
||||
//#define byte(x) ((uint8_t)(x))
|
||||
//#define float(x) ((float)(x))
|
||||
//#define boolean(x) ((uint8_t)((x)==0?0:1))
|
||||
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
|
|
|
@ -89,15 +89,23 @@ void analogWrite(uint8_t pin, int val)
|
|||
OCR1B = val;
|
||||
#if defined(__AVR_ATmega168__)
|
||||
} else if (digitalPinToTimer(pin) == TIMER0A) {
|
||||
// connect pwm to pin on timer 0, channel A
|
||||
sbi(TCCR0A, COM0A1);
|
||||
// set pwm duty
|
||||
OCR0A = val;
|
||||
if (val == 0) {
|
||||
digitalWrite(pin, LOW);
|
||||
} else {
|
||||
// connect pwm to pin on timer 0, channel A
|
||||
sbi(TCCR0A, COM0A1);
|
||||
// set pwm duty
|
||||
OCR0A = val;
|
||||
}
|
||||
} else if (digitalPinToTimer(pin) == TIMER0B) {
|
||||
// connect pwm to pin on timer 0, channel B
|
||||
sbi(TCCR0A, COM0B1);
|
||||
// set pwm duty
|
||||
OCR0B = val;
|
||||
if (val == 0) {
|
||||
digitalWrite(pin, LOW);
|
||||
} else {
|
||||
// connect pwm to pin on timer 0, channel B
|
||||
sbi(TCCR0A, COM0B1);
|
||||
// set pwm duty
|
||||
OCR0B = val;
|
||||
}
|
||||
} else if (digitalPinToTimer(pin) == TIMER2A) {
|
||||
// connect pwm to pin on timer 2, channel A
|
||||
sbi(TCCR2A, COM2A1);
|
||||
|
|
Loading…
Reference in New Issue