Parkmoonsugledel
Published © CC BY-NC-SA

Button Changes the Color of the LED

I studied RGB LEDs, and I applied myself to the application phase, which changes the color of the LED.

BeginnerShowcase (no instructions)12 minutes2,279
Button Changes the Color of the LED

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
button
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

RGB LED Button Schematics

Also...

Code

RGB LED Button

Arduino
Also simple...
int buttonPin = 2;     // the number of the pushbutton pin
int ledPin =  11;      // the number of the LED pin
int buttonState = 0;         // variable for reading the pushbutton status

void setup()
{
  // 디지털출력핀 초기회
  for(int pin=11 ; pin<=13 ; pin++)
  {
    pinMode(pin, OUTPUT);
  }
  
  // 디지털입력핀 초기화
  pinMode(buttonPin, INPUT);
}

void loop()
{
  buttonState = digitalRead(buttonPin);

  if(buttonState == LOW)
  {
    ledPin++;

    if(ledPin > 13)
    {
      ledPin = 11;
    }
  }
  
  digitalWrite(ledPin, HIGH);   // LED 켜기
  delay(500);                   // 0.5초 기다리기
  digitalWrite(ledPin, LOW);    // LED 끄기
  delay(500);                   // 0.5초 기다리기
}

Credits

Parkmoonsu
1 project • 6 followers
A Korean high school student who wants to learn about Arduino!
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!"

Comments