#define Buzzer_Pin 5
#define Blue_Btn 1
#define Red_Btn 2
#define Yellow_Btn 3
#define Green_Btn 4
#define LEDPIN1 14
#define LEDPIN2 15
#define LEDPIN3 16
int led_delay = 800;
int led_voltage = LOW; //LOW
int last_changed = 0;
int rbt = 0, rbt_past = 0;
int ybt = 0, ybt_past = 0;
int brightness = 0;
int fadeAmount = 5;
void setup() {
// put your setup code here, to run once:
pinMode(Buzzer_Pin, OUTPUT);
pinMode(Blue_Btn, INPUT_PULLUP);
pinMode(Red_Btn, INPUT_PULLUP);
pinMode(Yellow_Btn, INPUT_PULLUP);
pinMode(Green_Btn, INPUT_PULLUP);
pinMode(LEDPIN1, OUTPUT);
pinMode(LEDPIN2, OUTPUT);
pinMode(LEDPIN3, OUTPUT);
analogWrite(LEDPIN3, OUTPUT);
}
void loop() {
if (digitalRead(Green_Btn) == LOW) {
if (brightness == 0) {
brightness = 255;
} else {
brightness = 0;
}
analogWrite(LEDPIN3, brightness);
delay(50);
}
// put your main code here, to run repeatedly:
// 3 led will be on when all of the digitalwrite Led functions will be high;
// digitalWrite(Led1, HIGH);
//delay(100);
//digitalWrite(Led1, LOW);
//delay(1000);(Repeat for 3 led)
// 3 led will blink one after another when digitalwrite Led functions will be high and low with time delay;
// C1: Press Push Blue_Btn and led will be on, it won't stop even if you press the button again.
//int PushBlue = digitalRead(Blue_Btn);
//if (PushBlue == HIGH){
//digitalWrite(Led1, HIGH);
// C1: led will blink after pressing the btn
//int PushBlue = digitalRead(Blue_Btn);
//if (PushBlue == HIGH){
//digitalWrite(Led1, HIGH);
//delay(100);
//digitalWrite(Led1, LOW);
//delay(1000);
// C2: Led will be on after running the code and when press the push botton it will be off.
//if (digitalRead(Blue_Btn) == HIGH){
//digitalWrite(Led1, HIGH );
//digitalWrite(Led1, LOW);
//digitalWrite(Buzzer_Pin, HIGH);
//delay(50);
if (digitalRead(Blue_Btn) == LOW){
digitalWrite(LEDPIN1, HIGH);
digitalWrite(LEDPIN1, LOW);
digitalWrite(Buzzer_Pin, HIGH);
digitalWrite(Buzzer_Pin, LOW);
}
if (millis() >= last_changed + led_delay){
led_voltage = !led_voltage;
digitalWrite(15, led_voltage);
last_changed = millis();
}
rbt_past = rbt;
rbt = digitalRead(Red_Btn);
if (rbt == HIGH && rbt_past == LOW){
led_delay -= 400;
}
ybt_past = ybt;
ybt = digitalRead(Yellow_Btn);
if (ybt == HIGH && ybt_past == LOW){
led_delay += 400;
}
delay(50);
}