4.1 Two Toggling Leds
4.1 Two Toggling Leds
4.1 Two Toggling Leds
void loop()
{
digitalWrite(0, HIGH);
digitalWrite(1,LOW);
delay(2000); // Wait for 1000 millisecond(s)
digitalWrite(0, LOW);
digitalWrite(1, HIGH);
delay(2000); // Wait for 1000 millisecond(s)
}
4.2 Multiple Blinking LED
void setup(){
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
}
void loop(){
digitalWrite(1, HIGH);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
delay(300);
digitalWrite(1, LOW);
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
delay(300);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
delay(300);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
delay(300);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
delay(300);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
delay(300);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
delay(300);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
delay(300);
digitalWrite(1, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
delay(300);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
delay(300);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
delay(300);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
delay(300);
}
4.3 Seven Segment LED
int pinled [] = {0,1,2,3,4,5,6};
void setup(){
for (int i = 0; i < 7; i++) {
pinMode(pinled [i], OUTPUT);
}
}
void setup() {
pinMode(redLed, OUTPUT);
pinMode(yellowLed, OUTPUT);
pinMode(greenLed, OUTPUT);
}
void loop() {
digitalWrite(redLed, HIGH);
delay(5000);
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
delay(3000);
digitalWrite(greenLed, LOW);
digitalWrite(yellowLed, HIGH);
delay(2000);
digitalWrite(yellowLed, LOW);
}
void setup() {
pinMode(redLed1, OUTPUT);
pinMode(yellowLed1, OUTPUT);
pinMode(greenLed1, OUTPUT);
pinMode(redLed2, OUTPUT);
pinMode(yellowLed2, OUTPUT);
pinMode(greenLed2, OUTPUT);
}
void loop() {
digitalWrite(redLed1, HIGH);
digitalWrite(greenLed2, HIGH);
delay(3000);
digitalWrite(greenLed2, LOW);
digitalWrite(yellowLed2, HIGH);
delay(2000);
digitalWrite(yellowLed2, LOW);
delay(0);
digitalWrite(redLed1, LOW);
digitalWrite(redLed2, HIGH);
digitalWrite(greenLed1, HIGH);
delay(3000);
digitalWrite(greenLed1, LOW);
digitalWrite(yellowLed1, HIGH);
delay(2000);
digitalWrite(yellowLed1, LOW);
delay(0);
digitalWrite(redLed2, LOW);
}
4.7 Traffic Light with Timer
void setup(){
for (int i = 0; i < 14; i++) {
pinMode(i, OUTPUT);
}
}
void displayNumber(int i){
if (i == 0){
digitalWrite(0,( i == 0 ) ? HIGH : LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);