Skip to content

Instantly share code, notes, and snippets.

@EmmanuelMess
Last active March 12, 2021 16:39
Show Gist options
  • Save EmmanuelMess/96d93a62cddcec4983c258d74280c9c0 to your computer and use it in GitHub Desktop.
Save EmmanuelMess/96d93a62cddcec4983c258d74280c9c0 to your computer and use it in GitHub Desktop.
It displays an image with alpha
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// make some custom characters:
byte BlankTopLeft[8] = {
0b00000,
0b00000,
0b00010,
0b00111,
0b01111,
0b00111,
0b00111,
0b00011
};
byte BlankTopRight[8] = {
0b00000,
0b00000,
0b00000,
0b10000,
0b11100,
0b11110,
0b11110,
0b11100
};
byte BlankBottomLeft[8] = {
0b00000,
0b01000,
0b01000,
0b00010,
0b00000,
0b00100,
0b00100,
0b00000
};
byte BlankBottomRight[8] = {
0b00000,
0b01000,
0b01000,
0b00010,
0b00000,
0b00100,
0b00100,
0b00000
};
byte TopLeft[8] = {
0b00000,
0b00000,
0b00000,
0b00001,
0b00111,
0b00111,
0b00111,
0b00011
};
byte TopRight[8] = {
0b00000,
0b00000,
0b00000,
0b10000,
0b11100,
0b11110,
0b11110,
0b11100
};
byte BottomLeft[8] = {
0b00000,
0b00100,
0b00100,
0b00001,
0b00001,
0b01000,
0b00010,
0b00010
};
byte BottomRight[8] = {
0b00000,
0b00100,
0b00100,
0b00001,
0b00001,
0b01000,
0b00010,
0b00010
};
void setup() {
lcd.begin(16, 2);
lcd.createChar(0, TopLeft);
lcd.createChar(1, TopRight);
lcd.createChar(2, BottomLeft);
lcd.createChar(3, BottomRight);
lcd.createChar(4, BlankTopLeft);
lcd.createChar(5, BlankTopRight);
lcd.createChar(6, BlankBottomLeft);
lcd.createChar(7, BlankBottomRight);
lcd.clear();
lcd.print(" El tiempo");
lcd.setCursor(0, 1);
lcd.print(" Lluvia");
}
inline void executionDependentDelay(unsigned long* lastTime, unsigned long millisecs) {
if(*lastTime == 0) {
*lastTime = millis();
return;
}
unsigned long timeElapsed = millis() - *lastTime;
long diff = -((long) timeElapsed) + millisecs;
delay(max(0, diff));
*lastTime = millis();
}
const unsigned long TimedDelay = 15;
inline void displayAlphaChar(int charCodeNormal, int charCodeAlpha, int col, int row) {
static unsigned long lastTime = 0;
noInterrupts();
lcd.setCursor(col, row);
lcd.write(byte(charCodeAlpha));
interrupts();
executionDependentDelay(&lastTime, TimedDelay);
noInterrupts();
lcd.setCursor(col, row);
lcd.write(byte(charCodeNormal));
interrupts();
}
void loop() {
displayAlphaChar(0, 4, 0, 0);
displayAlphaChar(1, 5, 1, 0);
displayAlphaChar(2, 6, 0, 1);
displayAlphaChar(3, 7, 1, 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment