From 5444b25e11bce6139a58c8a641dccd266f90a0f1 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Mon, 13 Oct 2008 15:03:20 +0000 Subject: 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 --- cores/arduino/WMath.cpp | 11 +++++------ cores/arduino/wiring.h | 12 ++++++------ cores/arduino/wiring_analog.c | 24 ++++++++++++++++-------- 3 files changed, 27 insertions(+), 20 deletions(-) (limited to 'cores/arduino') diff --git a/cores/arduino/WMath.cpp b/cores/arduino/WMath.cpp index 78667f3..294d0dd 100644 --- a/cores/arduino/WMath.cpp +++ b/cores/arduino/WMath.cpp @@ -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; diff --git a/cores/arduino/wiring.h b/cores/arduino/wiring.h index 26cba9e..3701f6d 100755 --- a/cores/arduino/wiring.h +++ b/cores/arduino/wiring.h @@ -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)) diff --git a/cores/arduino/wiring_analog.c b/cores/arduino/wiring_analog.c index 30c5642..de0372e 100755 --- a/cores/arduino/wiring_analog.c +++ b/cores/arduino/wiring_analog.c @@ -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); -- cgit v1.2.3-18-g5258