How to Turn RGB LED On

When you press the button, LED turns on.

BeginnerWork in progress30 minutes6,497
How to Turn RGB LED On

Things used in this project

Schematics

schematic

Code

turning LEDs on

C/C++
This code is for arduino UNO
//8월 16일

enum { B = 2, G, R, BUTTON};
int index;

void setup()
{
  pinMode(R, OUTPUT);
  pinMode(G, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(BUTTON, INPUT);
}

void loop()
{
  while(digitalRead(BUTTON) == HIGH);
  switch (index)
  {
    case 0:
      RGB(HIGH, HIGH, LOW);
      break;
    case 1:
      RGB(HIGH, LOW, HIGH);
      break;
    case 2:
      RGB(LOW, HIGH, HIGH);
      break;
    case 3:
      RGB(LOW, LOW, LOW);
      break;
  }
  index = index == 3 ? 0 : index + 1;
  delay(100);
}

void RGB(int r, int g, int b)
{
      digitalWrite(R, r);
      digitalWrite(G, g);
      digitalWrite(B, b);
}

Credits

parksuhan
0 projects • 1 follower
경기도 파주시 금촌동
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!"
choi jin young
0 projects • 1 follower
Park Sae Joon(박세준)
0 projects • 1 follower
Kim Hyeon Gi
0 projects • 1 follower

Comments