Hi guys, i am making a project, basically it consist of 2 buttoms, and 3 leds. basically, at the beggining the first led is on, and the other ones are off... if i pushed the up buttom, it has to turn off the first led, to turn one the second.. and if i pushed the up button once more it has to clear the led one, and the led two, and turn on the third led... and it is the maximum value... now if i pushed the down button, it has to reduce the lights, about, have to turn off the third, and return just the second on... and so, on...
It seems simple... but i am getting crazy, regarding of when i pushed the first time the up button, instead to turn one the 2nd led, it turn on the third, and now with the third led on, if i pushed the down button, it is turning me on the 1st one... so basically the second one is never turning me on!!!!.
It is the code i already made, please help me. Thanks!
ARDUINO CODE
const int botup = 53;
const int botdown = 52;
int dato = 1;
void setup() {
// put your setup code here, to run once:
pinMode (botup, INPUT);
pinMode (botdown, INPUT);
DDRD = 0XFF;
PORTD = dato;
}
void loop() {
// put your main code here, to run repeatedly:
delay(10);
if (digitalRead(botup) == LOW && (dato < 3))
increase();
if (digitalRead(botdown) == LOW && (dato > 1))
decrease();
}
void increase(){
dato = dato*2;
PORTD = dato;
wait:
if (digitalRead(botup == LOW))
goto wait;
}
void decrease(){
dato = dato/2;
PORTD = dato;
wait1:
if (digitalRead(botdown == LOW))
goto wait1;
}