urbanspaceman
Well-known member
Hi, i have searched on this forum and on other forums without success.
Project
I want to lid 3 leds with 1 button, 1 led at time in sequence
1st press = led 1 on
2nd press = led 1 off, led 2 on
3th press = led 1 off, led 2 off, led 3 on
4th press = led 1 on, led 2 off, led 3 off
... ad libitum!
In my board i have the HT16K33 that control the leds and the switch. No problem to lid the leds and read the switch, the problem is in the loop function.
When i push the button, the 3 leds blink together, when i release the button only one led is lid but random...
this is the code
Project
I want to lid 3 leds with 1 button, 1 led at time in sequence
1st press = led 1 on
2nd press = led 1 off, led 2 on
3th press = led 1 off, led 2 off, led 3 on
4th press = led 1 on, led 2 off, led 3 off
... ad libitum!
In my board i have the HT16K33 that control the leds and the switch. No problem to lid the leds and read the switch, the problem is in the loop function.
When i push the button, the 3 leds blink together, when i release the button only one led is lid but random...
this is the code
Code:
void loop(){
if (HT.readKey(Button_a1))
{
if((!HT.getLed(Led_a1) && !HT.getLed(Led_a2) && !HT.getLed(Led_a3)) or HT.getLed(Led_a3) ){
HT.setLedNow(Led_a1);
HT.clearLedNow(Led_a2);
HT.clearLedNow(Led_a3);
}else if(HT.getLed(Led_a1) && !HT.getLed(Led_a2) && !HT.getLed(Led_a3)){
HT.setLedNow(Led_a2);
HT.clearLedNow(Led_a1);
HT.clearLedNow(Led_a3);
}else if(!HT.getLed(Led_a1) && HT.getLed(Led_a2) && !HT.getLed(Led_a3)){
HT.setLedNow(Led_a3);
HT.clearLedNow(Led_a1);
HT.clearLedNow(Led_a2);
}
}
}