Traffic light with button problem, help guys :)
if hold on pressing button traffic lights change ,
i wan cancel please, help?
i wan cancel please, help?
code: [select]
const int greenpin = 4; // green led pin
const int yellowpin = 3;
const int redpin = 2;
const int buttonpin = 12;
int ali = 0;
void setup() {
for (int = 2; <= 4; i++) { // setting outputs
pinmode(i, output);
}
pinmode(buttonpin, output);
}
void turnlightsoff() { // function
digitalwrite(redpin, low);
digitalwrite(yellowpin, low);
digitalwrite(greenpin, low);
}
void loop() {
boolean buttonstatus = digitalread(buttonpin);
if (buttonstatus == high) {
delay(1000);
if (buttonstatus == high) {
ali = ali + 1;
if (ali > 2) {
ali = 0;
}
}
}
if (ali == 0) {
digitalwrite(greenpin, low);
digitalwrite(redpin, high); delay(500);
}
else if (ali == 1) {
digitalwrite(redpin, low);
digitalwrite(yellowpin, high);delay(500);
}
else if (ali == 2) {
digitalwrite(yellowpin, low);
digitalwrite(greenpin, high);delay(500);
}
else
{
turnlightsoff();
}
}
Arduino Forum > Using Arduino > Programming Questions > Traffic light with button problem, help guys :)
arduino
Comments
Post a Comment