#include <Arduino.h>
#define LED_1_PIN 19 // most left
#define LED_2_PIN 18
#define LED_3_PIN 5
#define LED_4_PIN 17
#define LED_5_PIN 16 // most right
#define BTN_LEFT_PIN 22
#define BTN_RIGHT_PIN 23
#define LED_MODE_OFF 0
#define LED_MODE_LEFT_TO_RIGHT 1
#define LED_MODE_RIGHT_TO_LEFT 2
#define DELAY_TIME 100
// Globale Variablen
int led_array[5] = {LED_1_PIN, LED_2_PIN, LED_3_PIN, LED_4_PIN, LED_5_PIN};
int direction = LED_MODE_OFF;
void setup()
{
// put your setup code here, to run once:
pinMode(BTN_LEFT_PIN, INPUT_PULLDOWN);
pinMode(BTN_RIGHT_PIN, INPUT_PULLDOWN);
// LEDS
for (int i = 0; i < 5; i++)
{
pinMode(led_array[i], OUTPUT);
}
}
void loop()
{
// put your main code here, to run repeatedly
if (HIGH == digitalRead(BTN_LEFT_PIN))
{
direction = LED_MODE_RIGHT_TO_LEFT;
}
if (HIGH == digitalRead(BTN_RIGHT_PIN))
{
direction = LED_MODE_LEFT_TO_RIGHT;
}
run_led_chaser(direction);
}
void run_led_chaser(int direction)
{
if (LED_MODE_LEFT_TO_RIGHT == direction)
{
for (int i = 0; i < 5; i++)
{
digitalWrite(led_array[i], HIGH);
delay(DELAY_TIME);
digitalWrite(led_array[i], LOW);
}
}
else if (LED_MODE_RIGHT_TO_LEFT)
{
for (int i = 4; i >= 0; i--)
{
digitalWrite(led_array[i], HIGH);
delay(DELAY_TIME);
digitalWrite(led_array[i], LOW);
}
}
}