Hello everyone.
I am still very new to programming an Arduino. I have this code that changes states, but it does not repeat. It works once and I then need to go through all the counts again to repeat. How can I keep each state repeating without having to go through the count again.
Any help would be appreciated.
Mod: use Code Tags.E
Code below.
I am still very new to programming an Arduino. I have this code that changes states, but it does not repeat. It works once and I then need to go through all the counts again to repeat. How can I keep each state repeating without having to go through the count again.
Any help would be appreciated.
Mod: use Code Tags.E
Code below.
C-like:
int button = 4;
int pin2 = 2;
int pin7 = 7;
int oldstate = LOW;
int count = HIGH;
void setup() {
pinMode(button, INPUT);
pinMode(pin2, OUTPUT);
pinMode(pin7, OUTPUT);
}
void loop() {
int buttonstate = digitalRead(button);
if (buttonstate == oldstate && buttonstate == HIGH){
if (count == 1){
digitalWrite(pin2,HIGH);
delay(400);
digitalWrite(pin2,LOW);
delay(400);
digitalWrite(pin2,HIGH);
delay(400);
digitalWrite(pin2,LOW);
delay(400);
}
if (count == 2){
digitalWrite(pin7,HIGH);
delay(400);
digitalWrite(pin7,LOW);
delay(400);
digitalWrite(pin7,HIGH);
delay(400);
digitalWrite(pin7,LOW);
delay(400);
}
if (count < 2);
else
count = 0;
count++;
delay(50);
}
oldstate = buttonstate;
}
Last edited by a moderator: