/*
||=====================||
||#####################||
|| Created by ||
|| Ferdy ||
|| Lampu RGB 1 tombol ||
||#####################||
||=====================||
*/
const int pinR = 5;
const int pinG = 18;
const int pinB = 19;
const int buttonPin = 2;
int FirstButton = 0;
int Lastbutton = 0;
int mode = 0;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(pinR, OUTPUT);
pinMode(pinG, OUTPUT);
pinMode(pinB, OUTPUT);
}
void loop() {
FirstButton = digitalRead(buttonPin);
if (FirstButton != Lastbutton) {
delay(50);
if (FirstButton == LOW) {
mode++;
if (mode > 3) {
mode = 1;
}
}
}
switch (mode) {
case 1:
digitalWrite(pinR, HIGH);
digitalWrite(pinG, HIGH);
digitalWrite(pinB, LOW);
break;
case 2:
digitalWrite(pinR, HIGH);
digitalWrite(pinG, LOW);
digitalWrite(pinB, HIGH);
break;
case 3:
digitalWrite(pinR, LOW);
digitalWrite(pinG, HIGH);
digitalWrite(pinB, HIGH);
break;
}
Lastbutton = FirstButton;
}