#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
int LedPin = 11;
int LedBrigthness;
int ButtonPin1 =2;
int ButtonPin2 = 4;
int Buzer = 7;
float Tone;
void setup() {
// put your setup code here, to run once:
pinMode(LedPin, OUTPUT);
pinMode(ButtonPin1, INPUT);
pinMode(ButtonPin2, INPUT);
pinMode(Buzer, OUTPUT);
lcd.init();
lcd.backlight();
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
// Serial.print(digitalRead(ButtonPin1));
// Serial.println(digitalRead(ButtonPin2));
if(digitalRead(ButtonPin1)==0){
LedBrigthness +=5;
}
if (digitalRead(ButtonPin2)==0){
LedBrigthness -=5;
}
Serial.println(LedBrigthness);
analogWrite(LedPin, LedBrigthness);
if (LedBrigthness>255){
LedBrigthness=255;
tone(Buzer, 262, 100);
lcd.println("Stop Pressing");
lcd.setCursor(0,1);
lcd.println("The green button.");
delay(150);
lcd.clear();
}
if (LedBrigthness<0){
LedBrigthness=0;
tone(Buzer, 150, 100);
lcd.println("Stop Pressing ");
lcd.setCursor(0,1);
lcd.println("The black button.");
delay(150);
lcd.clear();
}
}