int Led_blue = 12;
int Led_green = 7;
int Led_red = 10;
int btn_pin = 5;
int btn_up = 3;
int btn_down = 4;
bool btn_state = false;
int counter = 0;
int brightness = 0;
int change_btn = 2;
void setup() {
pinMode(Led_red, OUTPUT);
pinMode(Led_green, OUTPUT);
pinMode(Led_blue, OUTPUT);
pinMode(btn_pin, INPUT);
pinMode(btn_up, INPUT);
pinMode(btn_down, INPUT);
pinMode(change_btn, INPUT);
Serial.begin(9600);
}
void loop() {
bool btn_status = digitalRead(btn_pin);
if (btn_status){
delay(150);
btn_state = !btn_state;
}
if (btn_state){
if (counter == 1){
analogWrite(Led_blue, brightness);
}
if (counter == 2) {
analogWrite(Led_red, brightness);
}
if (counter == 3){
analogWrite(Led_green, brightness);
}
bool btn_up_status = digitalRead(btn_up);
if (btn_up_status) {
delay(100);
brightness = brightness + 15;
if (brightness > 255) {
brightness = 255;
}
}
bool btn_dn_status = digitalRead(btn_down);
if (btn_dn_status) {
delay(100);
brightness = brightness - 15;
if (brightness < 0) {
brightness = 0;
}
}
bool btn_changeOn = digitalRead(change_btn);
if (btn_changeOn){
delay(100);
counter = counter + 1;
if (counter == 1) {
analogWrite(Led_red, false);
analogWrite(Led_blue, brightness);
analogWrite(Led_green, false);
}
if (counter == 2) {
analogWrite(Led_red, brightness);
analogWrite(Led_blue, false);
analogWrite(Led_green, false);
}
if (counter == 3) {
analogWrite(Led_red, false);
analogWrite(Led_blue, false);
analogWrite(Led_green, brightness);
}
}
}else{
delay(100);
if (Led_red){
analogWrite(Led_red, 0);
}
if (Led_blue) {
analogWrite(Led_blue, 0);
}
if (Led_green){
analogWrite(Led_green, 0);
}
}
if (counter > 3) {
counter = 0;
}
Serial.println(counter);
Serial.println(btn_state);
}