Last active
April 25, 2025 20:03
-
-
Save matiasmicheletto/9a107c7b3e3a14d5d1447060f7ec9998 to your computer and use it in GitHub Desktop.
Just a face and flipping the bird gesture for Arduino I2C-LCD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Wire.h> | |
| #include <LiquidCrystal_I2C.h> | |
| LiquidCrystal_I2C lcd(0x27, 20, 4); | |
| int loopCtr = 0; | |
| int direction = 0; | |
| int x = random(0, 13); | |
| int y = random(0, 1); | |
| int dx = 0; | |
| int dy = 0; | |
| byte customChars[][8] = { | |
| {B00100,B00100,B00100,B01100,B11111,B11111,B11111,B01110}, // right hand | |
| {B00100,B00100,B00100,B00110,B11111,B11111,B11111,B01110}, // left hand | |
| {B11000,B01100,B00110,B00000,B00000,B00000,B00001,B00001}, // left eye | |
| {B00000,B00000,B00000,B00000,B00000,B00000,B10001,B10001}, // mid eye | |
| {B00011,B00110,B01100,B00000,B00000,B00000,B10000,B10000}, // right eye | |
| {B00000,B00000,B00000,B00000,B00000,B01000,B00100,B00011}, // left mouth | |
| {B00000,B00100,B00100,B00100,B00000,B00000,B00000,B11111}, // mid mouth | |
| {B00000,B00000,B00000,B00000,B00000,B00010,B00100,B11000} // right mouth | |
| }; | |
| void setup() { | |
| lcd.init(); | |
| lcd.backlight(); | |
| lcd.clear(); | |
| for (int i = 0; i < 8; i++) | |
| lcd.createChar(i, customChars[i]); | |
| } | |
| int clamp(int value, int min, int max) { | |
| if(value < min) return min; | |
| if(value > max) return max; | |
| return value; | |
| } | |
| void drawFace(int x, int y) { | |
| int ch = 2; | |
| for(int col = y; col < y+2; col++) | |
| for(int row = x+2; row < x+5; row++){ | |
| lcd.setCursor(row, col); | |
| lcd.write(byte(ch)); | |
| ch++; | |
| } | |
| } | |
| void drawHands(int x, int y, bool leftUp) { | |
| if(leftUp){ | |
| lcd.setCursor(x, y+1); | |
| lcd.write(byte(0)); | |
| lcd.setCursor(x+6, y+2); | |
| lcd.write(byte(1)); | |
| }else{ | |
| lcd.setCursor(x, y+2); | |
| lcd.write(byte(0)); | |
| lcd.setCursor(x+6, y+1); | |
| lcd.write(byte(1)); | |
| } | |
| } | |
| void loop() { | |
| if(loopCtr > 3) { | |
| loopCtr = 0; | |
| direction = random(0,4); | |
| } | |
| switch(direction) { | |
| case 0: | |
| dx = 1; dy = 0; | |
| break; | |
| case 1: | |
| dx = -1; dy = 0; | |
| break; | |
| case 2: | |
| dx = 0; dy = 1; | |
| break; | |
| case 3: | |
| dx = 0; dy = -1; | |
| break; | |
| } | |
| x = clamp(x+dx, 0, 13); | |
| y = clamp(y+dy, 0, 1); | |
| drawFace(x, y); | |
| drawHands(x, y, true); | |
| delay(700); | |
| lcd.clear(); | |
| drawFace(x, y); | |
| drawHands(x, y, false); | |
| delay(700); | |
| lcd.clear(); | |
| loopCtr++; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment