Yun Jin Yonggledel임동교
Published © GPL3+

Innovation Lab #6: Switch Two LEDs ON/OFF

A Bongilcheon High School Innovation Lab project.

BeginnerShowcase (no instructions)10 minutes6,255
Innovation Lab #6: Switch Two LEDs ON/OFF

Things used in this project

Story

Read more

Schematics

Switch_LED

Switch_LED

Code

Switch_LED

Arduino
Slide the switch, one LED turn on and another LED turn off change.
const int switchPin = 3;
const int led1Pin = 12;
const int led2Pin = 13;

void setup() {
  pimMode(switchPin, INPUT);
  pimMode(led1Pin, OUTPUT);
  pimMode(led2Pin, OUTPUT);
}

void loop() {
  int switchVal;
  switchVal = digitalRead(switchPin);
  
  if (switchVal == HIGH) {
    digitalWrite(led1Pin, HIGH);
    delay(500);
    digitalWrite(led2Pin, LOW);
    delay(500);
  }
  
  else {
    digitalWrite(led2Pin, HIGH);
    delay(500);
    digitalWrite(led1Pin, LOW);
    delay(500);
  }
}

Credits

Yun Jin Yong

Yun Jin Yong

6 projects • 10 followers
gledel

gledel

100 projects • 115 followers
Looking back on my childhood, I was happy when I was making something and I was proud of myself. "Making is instinct!"
임동교

임동교

0 projects • 12 followers

Comments