RebounD11

LCD 4x40 over I2C sanity

Nov 30th, 2020
1,023
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3.  
  4. LiquidCrystal_I2C lcd(0x27,40,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display
  5. int E1 = 7;
  6. int E2 = 6;
  7. int E = 2;
  8. volatile int line;
  9. int cycle;
  10.  
  11. void selectScreen() {
  12.   if (line >= 2) {
  13.     digitalWrite(E2, digitalRead(E));
  14.   }
  15.   else {
  16.     digitalWrite(E1, digitalRead(E));
  17.   }
  18. }
  19.  
  20. void setup()
  21. {
  22.  
  23.   pinMode(E1, OUTPUT);
  24.   pinMode(E2, OUTPUT);
  25.   attachInterrupt(digitalPinToInterrupt(E), selectScreen, CHANGE);
  26.   cycle = 0;
  27.   line = 0;
  28.   lcd.init();
  29.   line = 2;
  30.   lcd.init();
  31.   lcd.backlight();
  32.   line = 0;
  33.   lcd.setCursor(2,line);
  34.   lcd.print("Hello, world!");
  35.   line = 1;
  36.   lcd.setCursor(2,line);
  37.   lcd.print("Does it work? (upper half)");
  38.   line = 2;
  39.   lcd.setCursor(2,(line-2));
  40.   lcd.print("Hello, world!");
  41.   line = 3;
  42.   lcd.setCursor(2,(line-2));
  43.   lcd.print("Does it work? (lower half)");
  44.   delay(2000);
  45. }
  46.  
  47.  
  48. void loop()
  49. {
  50.   cycle++;
  51.   line = 0;
  52.   lcd.clear();
  53.   lcd.setCursor(2,line);
  54.   lcd.print("Cycle");
  55.   line = 1;
  56.   lcd.setCursor(2,line);
  57.   lcd.print(cycle);
  58.   delay(2000);
  59.   cycle++;
  60.   line = 2;
  61.   lcd.clear();
  62.   lcd.setCursor(2,(line-2));
  63.   lcd.print("Cycle");
  64.   line = 3;
  65.   lcd.setCursor(2,(line-2));
  66.   lcd.print(cycle);
  67.   delay(2000);
  68. }
RAW Paste Data