Skip to content

Instantly share code, notes, and snippets.

@IdrisCytron
Created May 21, 2019 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IdrisCytron/7ea454da4a8614ae7ec785e1953f37e7 to your computer and use it in GitHub Desktop.
Save IdrisCytron/7ea454da4a8614ae7ec785e1953f37e7 to your computer and use it in GitHub Desktop.
I2C LCD using micro:bit
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define LCD_ADDR 0x3F
#define LCD_COL 16
#define LCD_ROW 2
LiquidCrystal_I2C lcd(LCD_ADDR, LCD_COL, LCD_ROW);
void setup()
{
Serial.begin(115200);
Serial.println("Display on I2C LCD Using micro:bit");
pinMode(PIN_BUTTON_A, INPUT);
pinMode(PIN_BUTTON_B, INPUT);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.print("Display I2C LCD ");
lcd.setCursor(0, 1);
lcd.print("Using micro:bit ");
delay(2000);
lcd.clear();
lcd.print("Press the");
lcd.setCursor(0, 1);
lcd.print("button");
}
void loop()
{
if (digitalRead(PIN_BUTTON_A) == LOW) {
Serial.println("Button A pressed.");
lcd.clear();
lcd.print("Button A pressed");
while (digitalRead(PIN_BUTTON_A) == LOW);
lcd.clear();
lcd.print("Press the");
lcd.setCursor(0, 1);
lcd.print("button");
delay(100);
}
else if (digitalRead(PIN_BUTTON_B) == LOW) {
Serial.println("Button B pressed.");
lcd.clear();
lcd.print("Button B pressed");
while (digitalRead(PIN_BUTTON_B) == LOW);
lcd.clear();
lcd.print("Press the");
lcd.setCursor(0, 1);
lcd.print("button");
delay(100);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment