/*
CTC GO! CORE MODULE
LESSON 04 - Digital Inputs & Outputs
This sketch is written to accompany Activity 3 in Lesson 04 of the CTC GO! core module
*/
// Initialising the pins and other variables.
int greenLED = 13;
int redLED = 12;
int yellowLED = 11;
int dt = 250;
int button_pin = 2;
int button_state =0;
int blinkingLED = 0;
void setup()
{
// Setting up the pins as OUTPUTS.
pinMode(greenLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(redLED, OUTPUT);
pinMode(button_pin, INPUT);
}
void loop()
{
// Randomly blink the LEDs
/*blinkingLED = random(11, 14);
if (blinkingLED == greenLED)
{
digitalWrite(greenLED, HIGH);
}
else if (blinkingLED == yellowLED)
{
digitalWrite(yellowLED, HIGH);
}
else if (blinkingLED == redLED)
{
digitalWrite(redLED, HIGH);
}*/
//Note: all above lines could be replaced by
if (button_state == LOW) {
digitalWrite(random(11, 14), HIGH);
}
else if (button_state == HIGH) {
delay(dt);
digitalWrite(greenLED, LOW);
digitalWrite(yellowLED, LOW);
digitalWrite(redLED, LOW);
delay(dt);
}
delay (dt);
digitalWrite(greenLED, LOW);
digitalWrite(yellowLED, LOW);
digitalWrite(redLED, LOW);
delay(dt);
}