aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino
diff options
context:
space:
mode:
Diffstat (limited to 'cores/arduino')
-rw-r--r--cores/arduino/WMath.cpp11
-rwxr-xr-xcores/arduino/wiring.h12
-rwxr-xr-xcores/arduino/wiring_analog.c24
3 files changed, 27 insertions, 20 deletions
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);