Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27, 16, 2);
- #define BTN1 7 //macros because the pins arent in order with the buttons, improves readability
- #define BTN2 6
- #define BTN3 5
- #define BTN4 4
- void setup() {
- pinMode(BTN1, INPUT_PULLUP); //set pin modes
- pinMode(BTN2, INPUT_PULLUP);
- pinMode(BTN3, INPUT_PULLUP);
- pinMode(BTN4, INPUT_PULLUP);
- lcd.init();
- lcd.backlight();
- }
- void loop() {
- while(digitalRead(BTN1) == LOW){ //also tried this with if and if else, etc...
- lcd.setCursor(0,0);
- lcd.print("BUTTON 1 PRESSED"); //when a button is pressed it should display text on the lcd
- }
- while(digitalRead(BTN2) == LOW){
- lcd.setCursor(0,0);
- lcd.print("BUTTON 2 PRESSED");
- }
- while(digitalRead(BTN3) == LOW){
- lcd.setCursor(0,0);
- lcd.print("BUTTON 3 PRESSED");
- }
- while(digitalRead(BTN4) == LOW){
- lcd.setCursor(0,0);
- lcd.print("BUTTON 4 PRESSED");
- }
- lcd.setCursor(0,0);
- lcd.print("NO BUTTON PRESSED");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement