Hi All,
I'm a newbie to Arduino. and I'm Trying some simple codes.
I try to blink a led by increasing variable 'previousMillis' :
const int ledPin = 13;
int ledState = LOW;
long previousMillis = 0;void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
previousMillis++; //incrementing variableif (previousMillis>500) ledState=LOW; // when the value more than 500, led goes OFF
if (previousMillis==1000) { // when the value reach 1000, led goes ON
ledState=HIGH;
previousMillis=0; // set variable back to zero
}digitalWrite(ledPin, ledState); // write to pin 13
}
but after I upload it to the board, it's not working.
then I add Serial.begin() and Serial.println() to test the variable.
const int ledPin = 13;
int ledState = LOW;
long previousMillis = 0;void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
previousMillis++; //incrementing variableif (previousMillis>500) ledState=LOW; // when the value more than 500, led goes OFF
if (previousMillis==1000) { // when the value reach 1000, led goes ON
ledState=HIGH;
previousMillis=0; // set variable back to zero
}
Serial.println(previousMillis);
digitalWrite(ledPin, ledState); // write to pin 13
}
and it's WORK..
can anybody explain why the first codes is not working?