Yun Jin Yonggledel임동교
Published © GPL3+

Innovation Lab #5: Push Button RGB LED Color Change

A Bongilcheon High School Innovation Lab project.

BeginnerShowcase (no instructions)10 minutes51,501
Innovation Lab #5: Push Button RGB LED Color Change

Things used in this project

Story

Read more

Schematics

PushButton_RGB LED

PushButton_RGB LED

Code

PushButton_RGB LED

Arduino
Press the button, RGB LED color change.
const int buttonPin = 3;
const int redPin = 11;
const int greenPin = 10;
const int bluePin = 9;
int counter = 0;

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
}

void loop() {
  int buttonState;
  buttonState = digitalRead(buttonPin);
  
  if (buttonState == LOW) {
    counter++;
    delay(150);
  }
  
  else if (counter == 0) {
    digitalWrite(red, LOW);
    digitalWrite(green, LOW);
    digitalWrite(blue, LOW);
  }
  
  else if (counter == 1) {
    digitalWrite(red, HIGH);
    digitalWrite(green, LOW);
    digitalWrite(blue, LOW);
  }
  
  else if (counter == 2) {
    digitalWrite(red, LOW);
    digitalWrite(green, HIGH);
    digitalWrite(blue, LOW);
  }
  
  else if (counter == 3) {
    digitalWrite(red, LOW);
    digitalWrite(green, LOW);
    digitalWrite(blue, HIGH);
  }
  
  else {
    counter = 0;
  }
}

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