Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
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,318
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
6 projects • 10 followers
Contact
gledel
100 projects • 116 followers
Looking back on my childhood, I was happy when I was making something and I was proud of myself. "Making is instinct!"
Contact
임동교
0 projects • 12 followers
Contact

Comments

Please log in or sign up to comment.