#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
int led = 11; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
void setup() {
// put your setup code here, to run once:
pinMode(led, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, INPUT_PULLUP);
Serial.begin(115200);
lcd.init();
lcd.backlight();
}
bool buttonState;
int time_old;
int time_now;
const int time_wait = 200; // [ms]
void loop() {
time_now = millis();
buttonState = digitalRead(10);
if (time_now - time_old >= time_wait) {
time_old = time_now;
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
analogWrite(led, brightness);
// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
}
if (buttonState==LOW) {
digitalWrite(9,HIGH);
}
else {
digitalWrite(9,LOW);
}
lcd.print(buttonState);
lcd.setCursor(0,0);
Serial.println(buttonState);
delay(10);
}