stiwdio
September 26, 2021, 4:03pm
46
StefanL38:
onst byte LedPins[5] = { 8, 9, 10, 11, 12};
unsigned long previousMillis;
int index = 0;
int updown = +1; // +1 or -1 for going left and right
int buttonstate = 0;
void setup()
{
for ( auto a : LedPins)
pinMode( a, OUTPUT);
pinMode(2 , INPUT_PULLUP); // activates the internal pull-up resistor
}
void loop ()
{
if (buttonstate == LOW)
{
unsigned long currentMillis = millis();
if ( currentMillis - previousMillis >= 80)
{
previousMillis = currentMillis;
digitalWrite( LedPins[index], LOW); // turn old led off
index += updown;
digitalWrite( LedPins[index], HIGH); // turn new led on
if ( index <= 0 || index >= 4)
updown = -updown;
}
}
else
{
}
}
Amazing, thanks Stefan! Great explanation! this will keep me going for a while to figure it out, but thats what's it about working it out
Thank you again!