#include <LiquidCrystal.h>
//initailize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int potPin = A0;
int ledPin = 6;
int potValue = 0;
int brightness = 0;
int pBari = 0;
int i = 0;
//progress bar character brightness
byte pBar[8] = {
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
};
void setup() {
// put your setup code here, to run once:
// set our led as an OUTPUT
pinMode(ledPin, OUTPUT);
// set up the lcd's number of columns and rows
lcd.begin(16,2);
// print amassege to the lcd
lcd.print("LCD Brigtness");
// Create the progress bar characters
lcd.createChar(0, pBar);
}
void loop() {
// put your main code here, to run repeatedly:
// clears the LCD screen
lcd.Clear();
// print a massege to LCD
lcd.print("LCD Brigtness");
// set cursor to linre number 2
lcd.setCursor(0,1);
// read the value from the potentiometer
potValue = analogRead(potPin);
// turns the potValue into a brightness for the LED
brightness = map(potValue, 0 1024, 0, 255);
// lights up the led according to the brightness
analogWrite(ledPin, brightness);
// turns the brightness into a percentage for the bar
pBari = map(brightness, 0, 255, 0, 17);
// print he progress bar
for(i=0; i<pBari: i++){
lcd.setCursor(i,1);
lcd.write(byte(0));
}
//delay 750ms
delay(750);
}