/* * Programmer R. Jordan Kreindler * October 12, 2020 * Sketch to check if switch is pressed and display reuults on LCD * If switch not pressed value = 1 or HIGH * If switch pressed value = 0 or LOW */ #include // liquidCrystal_I2C should be enclosed in < and > brackets LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line LCD display #define Switch 8 #define delay1 500 void setup() { pinMode (Switch, INPUT_PULLUP); // Set the switch as input, so that when not pressed the value equals one (1) lcd.init(); // Initialize LCD lcd.backlight(); // Turn backlight On lcd.setCursor(0, 0); // Set cursor at position zero(0) on first line of 1602 LCD lcd.print(" Encoder Switch "); } void loop() { lcd.setCursor(0, 1); // Set cursor at position zero (0) on second line of 1602 LCD if(digitalRead(Switch) == 1) { lcd.println(" is unpressed "); } if(digitalRead(Switch) == 0) { lcd.println(" is pressed "); } delay(delay1); }