Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- int PIN_CLK_EN_1 = 1;
- int PIN_CLK_EN_2 = 2;
- int CLK_SWITCH_DELAY_US = 50;
- // two displays with same I2C address
- LiquidCrystal_I2C lcd1 = LiquidCrystal_I2C(0x27, 16, 2);
- LiquidCrystal_I2C lcd2 = LiquidCrystal_I2C(0x27, 16, 2);
- // enable display CLK line with some delay
- void enableDisplay(int num) {
- num == 1 ? digitalWrite(PIN_CLK_EN_2, LOW) : digitalWrite(PIN_CLK_EN_1, LOW);
- delayMicroseconds(CLK_SWITCH_DELAY_US);
- num == 1 ? digitalWrite(PIN_CLK_EN_1, HIGH) : digitalWrite(PIN_CLK_EN_2, HIGH);
- delayMicroseconds(CLK_SWITCH_DELAY_US);
- }
- void setup() {
- pinMode(PIN_CLK_EN_1, OUTPUT);
- pinMode(PIN_CLK_EN_2, OUTPUT);
- // disable both CLK lines
- digitalWrite(PIN_CLK_EN_1, LOW);
- digitalWrite(PIN_CLK_EN_2, LOW);
- enableDisplay(1);
- lcd1.init();
- enableDisplay(2);
- lcd2.init();
- }
- void loop() {
- int counter = 0;
- while(true) {
- enableDisplay(1);
- lcd1.setCursor(0,0);
- lcd1.print("Display 1, count =" + counter);
- enableDisplay(2);
- lcd2.setCursor(0,0);
- lcd2.print("Display 2, count =" + counter);
- counter++;
- delay(500);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement