Monday, June 20, 2022

tinkercad I2C LCDs


#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd1(0x20,16,2);
LiquidCrystal_I2C lcd2(0x21,16,2);

byte Up[8] = {
  0b00000,
0b00100,
0b01110,
  0b11111,
  0b00100,
  0b00100,
  0b00100,
  0b00000,
};

byte Down[8] = {
  0b00000,
0b00100,
0b00100,
  0b00100,
  0b11111,
  0b01110,
  0b00100,
  0b00000,
};

void setup()
{
  lcd1.init();
  lcd1.clear(); 
  lcd1.backlight(); 
  
  lcd1.createChar(0, Up);
  lcd1.createChar(1, Down);
  
  lcd1.setCursor(4,0); 
  lcd1.print("Commodities LCD 0x20");
  lcd1.setCursor(0,1);
  lcd1.print("Brent Oil ");
  lcd1.write(0);
  lcd1.print("0.87% ");
  lcd1.print("Natural Gas ");
  lcd1.write(0);
  lcd1.print("0.43% ");
  
  lcd2.init();
  lcd2.clear(); 
  lcd2.backlight(); 
  
  lcd2.createChar(0, Up);
  lcd2.createChar(1, Down);
  
  lcd2.setCursor(4,0); 
  lcd2.print("Commodities LCD 0x21");
  lcd2.setCursor(0,1);
  lcd2.print("Gold ");
  lcd2.write(0);
  lcd2.print("0.12% ");
  lcd2.print("Soybeans ");
  lcd2.write(1);
  lcd2.print("0.84% ");
}

void loop()
{
   lcd1.scrollDisplayLeft();     
   lcd2.scrollDisplayLeft(); 
  
  delay(200);
}
//I2C address sniffer
#include <Wire.h>

void setup()
{
  Serial.begin (9600);

  // Leonardo: wait for serial port to connect
  while (!Serial) 
    {
    }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 8; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}

void loop()
{
 
}

reference:

scroll left

multiple LCDS

No comments:

Post a Comment