vendredi 6 mars 2015

NOT operator on Boolean in c++

I'm trying to use this Arduino code in my program, the LED will stay on for 5 sec then turns itself off



#include <elapsedMillis.h>

int led = 13 ;
elapsedMillis timer0 ;
#define interval 5000
boolean timer0Fired ;

// the setup routine runs once when you press reset:
void setup()
{
pinMode(led, OUTPUT);
digitalWrite(led, HIGH);
timer0Fired = false;
timer0 = 0; // clear the timer at the end of startup
}

void loop()
{
if ((!timer0Fired) && (timer0 > interval))
{
timer0Fired = true; // don't execute this again
digitalWrite(led, LOW); // turn led off after 5 sec
}
}


I don't understand how the if statement works inside the loop, !timer0Fired should evaluates to 1 but when I print it out it's 0, so when timer0 exceeds the interval the if statement should evaluates to be false, I tried it on a UNO and it works.


Aucun commentaire:

Enregistrer un commentaire