Ok so i dont have a good code to explain what i want, but it is really simple so here we go;
i have 4 buttons, and a 3x3 LED display witch uses 9 pins. total 13 pins with the buttons.
the task is to make a 4 LIGHTSHOWS, and you can swich between each lightshow by pressing a button. i can swich between the lightshows, but that means i have to run a "test" after every delay, and use several short delays with a test in between each of them instead of a long delay.
no matter how i do it, the lightshow WONT swich before the current lightshow is compleated. i want to be able to INTERRUPT the lightshow, and start another one. also if posible, not having to hold the button for at least 100ms witch is not much.
i have attempted to use noInterrupts and interrupts, but dont really get how that works. made everything a total mess.
tried to use break; but i cant use that properly cause i have to use an if inside a while statement, and i cant break the while statement with that if.
here is a code, but it is NOT compleated. its just what i got so far. nothing is properly set up.
int A=0;
int TEST()
{
if (digitalRead(Btn[0]) == HIGH)
{
A = 1;
}
if (digitalRead(Btn[1]) == HIGH)
{
A = 2;
}
if (digitalRead(Btn[2]) == HIGH)
{
A = 3;
}
if (digitalRead(Btn[3]) == HIGH)
{
A = 4;
}
delay(100);
}
int LedReset()
{
for (int n = 0; n <= 8; n++)
{
digitalWrite(Led[n], LOW);
}
}
// ** * ****** * **
/*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/
void loop(){
TEST();
while(A == 1)
{
digitalWrite(Led[0], HIGH);
TEST();
digitalWrite(Led[0], LOW);
TEST();
}
while(A == 2)
{
digitalWrite(Led[1], HIGH);
TEST();
digitalWrite(Led[1], LOW);
TEST();
}
while(A == 3)
{
digitalWrite(Led[2], HIGH);
TEST();
digitalWrite(Led[2], LOW);
TEST();
}
while(A == 4)
{
digitalWrite(Led[3], HIGH);
TEST();
digitalWrite(Led[3], LOW);
TEST();
}
}
you might want to notice how i use the "TEST();"
does anyone have a tips for what i could do? if you use advanced code, please explain it.
thank you guys a lot.