#define PIN_1 12
#define PIN_2 11
#define PIN_3 10
#define BUTTON_PIN 4
int arr[3] = {PIN_1, PIN_2, PIN_3};
void init_LED()
{
for(int i=0; i< sizeof(arr) / sizeof(arr[0]); i++)
{
pinMode(arr[i], OUTPUT);
//make sure all of the LEDS are first off
digitalWrite(arr[i], 0);
}
}
//function that causes lights to blink sequentially
void blinkLEDS()
{
for(int i=0; i < sizeof(arr)/sizeof(arr[0]); i++)
{
//turn the current LED on
digitalWrite(arr[i], 1);
delay(100);
digitalWrite(arr[i], 0);
}
}
void stopBlink()
{
for(int i=0; i < sizeof(arr)/sizeof(arr[0]); i++)
{
//if user presses the button, leave the current LED on
while(digitalRead(BUTTON_PIN) == 1)
{
delay(10);
digitalWrite(arr[i], 1);
}
//this happens when the button is not pressed
//turn the current LED on
digitalWrite(arr[i], 1);
delay(200);
digitalWrite(arr[i], 0);
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
//init the output button
pinMode(BUTTON_PIN, INPUT);
//initialiaze all of the LED pins
init_LED();
}
void loop() {
// put your main code here, to run repeatedly:
stopBlink();
}