3 Blinking LEDs:
I used the example provided by Arduino, and added a couple LEDs. I wanted the LEDs to all turn on and off progressively, instead of taking turns blinking to I changed the order of the HIGH/LOW commands.
Code:
int red = 7;
int yellow = 6;
int blue = 5;
void setup() {
// initialize the digital pins as outputs.
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(blue, OUTPUT);
}
void loop() {
digitalWrite(red, HIGH);
delay(500);
digitalWrite(yellow, HIGH);
delay(500);
digitalWrite(blue, HIGH);
delay(500);
digitalWrite(red, LOW);
delay(500);
digitalWrite(yellow, LOW);
delay(500);
digitalWrite(blue, LOW);
delay(500);
}
Buttons and LEDs:
For this one, I used the same Arduino set up as I had for the blinking LEDs and just added buttons to the breadboard and connected them to the Arduino. As you will see in the video, one button turns on the red and yellow LEDs and the other button turns on the blue and yellow LEDs.
Code:
int switchStateRed = 0;
int switchStateBlue = 0;
void setup(){
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(2, INPUT);
pinMode(3, INPUT);
}
void loop(){
switchStateRed = digitalRead(2);
switchStateBlue = digitalRead(3);
if(switchStateRed == HIGH){
digitalWrite(7, HIGH);
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
}else if(switchStateBlue == HIGH){
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(5, HIGH);
}else{
digitalWrite(7, LOW);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
}
}
Hi Niamh, I can’t see your videos because they are private.
Woops! Sorry, I just fixed it. You should be able to view now