I2C Library for Hobby Components SmartLCD (HCMODU0122)

Useful guides, libraries, and example sketches to support our Arduino based products.
andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: I2C Library for Hobby Components SmartLCD (HCMODU0122)

Post by andrew » Fri Feb 10, 2023 3:08 pm

is it possible to write to more displays in one code?
You can do this by creating two instances of the library and then assigning a different I2C address to each instance. Here is an example of how to do it:

  1. #include "SmartLCDI2C.h"      //Include the SmartLCD I2C Library
  2.  
  3. #define I2C_ADD1 0x27         //I2C address of SmartLCD 1
  4. #define I2C_ADD2 0x28         //I2C address of SmartLCD 2
  5.  
  6. // Create two instances of the library (SmartLCD1 & SmartLCD2)
  7. // and assign them different addresses
  8. SmartLCD SmartLCD1(I2C_ADD1);
  9. SmartLCD SmartLCD2(I2C_ADD2);
  10.  
  11.  
  12. void setup()
  13. {
  14.   // Initialise both instances of the library
  15.   SmartLCD1.init();
  16.   SmartLCD2.init();
  17.  
  18.   // Clear both screens
  19.   SmartLCD1.Clear();
  20.   SmartLCD2.Clear();
  21. }
  22.  
  23.  
  24. void loop()                
  25. {
  26.   // Print something to each screen
  27.   SmartLCD1.Print("Hello");
  28.   SmartLCD2.Print("World !");
  29.  
  30.   while(1);
  31. }
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

Post Reply

Return to “Arduino”