이하늘gledel임동교
Published © GPL3+

InoLab: RGB LED on Switch

This project was made by the Innovation Lab in Bongilcheon High School.

BeginnerShowcase (no instructions)30 minutes7,877
InoLab:  RGB LED on Switch

Things used in this project

Story

Read more

Schematics

_eUIHXyJdpj.PNG

Code

Untitled file

Arduino
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) // light the LED
{
counter++;
delay(150);
}
if (counter == 0)
{
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
}
else if (counter == 1)
{
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
}
else if (counter == 2)
{
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, LOW);
}
else if (counter == 3)
{
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, HIGH);
}
{
counter = 0;
}
}

Credits

이하늘
5 projects • 3 followers
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!"
임동교
0 projects • 12 followers

Comments