Can you explain what the code is supposed to be doing?
Note: it would be good to use constants/defines instead of absolute numbers. This way you can right away see what pin is used for what, and if that needs to be changed, then you can do that in just one spot. (example code blow - as you can see: it also improves readability)
#define BUTTON 2
#define LED1 8
#define LED2 9
#define LED3 10
void setup()
{
pinMode(BUTTON, INPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
}
void loop()
{
buttonState = digitalRead(BUTTON);
digitalWrite(LED1, HIGH);
digitalWrite(LED2, LOW);
if (buttonState == HIGH) {
digitalWrite(LED1,LOW);
for(int i=0; i<3;i=i+1){
digitalWrite(LED3,HIGH);
delay(3000);
digitalWrite(LED3,LOW);
delay(3000);
}
digitalWrite(LED2, HIGH);
delay(1000);
}// else {
// digitalWrite(LED1, HIGH);
// digitalWrite(LED2, LOW);
// digitalWrite(LED3, LOW);
//
}
}
From what I'm reading in the code:
- LED1 on, LED2 off (LED3???)
- if BUTTON pressed then LED1 off, 2x LED3 on/off (3 seconds each).
- LED2 on
- Wait a second
- repeat
I'm not seeing where the do-while loop should be?
Tip: I wrote a little intro to Arduino programming. There is a Do-While section here that explains the use of a do-while loop.