Created
October 29, 2021 21:28
-
-
Save gleicon/37beff2c6cb8dce2aa0c4a3684ad4bdd to your computer and use it in GitHub Desktop.
LCD Keypad 1602 and Arduino backlight bright control using up/down keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <LiquidCrystal.h> | |
//LCD pin to Arduino | |
const int pin_RS = 8; | |
const int pin_EN = 9; | |
const int pin_d4 = 4; | |
const int pin_d5 = 5; | |
const int pin_d6 = 6; | |
const int pin_d7 = 7; | |
const int pin_BL = 10; | |
LiquidCrystal lcd( pin_RS, pin_EN, pin_d4, pin_d5, pin_d6, pin_d7); | |
int global_bright = 120; | |
void setup() { | |
lcd.begin(16, 2); | |
lcd.setCursor(0,0); | |
lcd.print("Leronet"); | |
lcd.setCursor(0,1); | |
lcd.print("Press Key:<>"); | |
global_bright = 120; | |
} | |
void loop() { | |
int x; | |
x = analogRead (0); | |
lcd.setCursor(10,1); | |
if (x < 60) { | |
lcd.print ("Right "); | |
} | |
else if (x < 200) { | |
lcd.print ("Up "); | |
global_bright+=10; | |
} | |
else if (x < 400){ | |
lcd.print ("Down "); | |
global_bright-=10; | |
} | |
else if (x < 600){ | |
lcd.print ("Left "); | |
} | |
else if (x < 800){ | |
lcd.print ("Select"); | |
} | |
analogWrite(pin_BL, global_bright); | |
lcd.setCursor(10,0); | |
if (global_bright < 0) global_bright = 10; | |
if (global_bright > 240) global_bright = 240; | |
lcd.print(global_bright); | |
delay(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment