/* * Programmer: R. Jordan Kreindler * Bouncing Ball Animation * August 8, 2020 */ #include LiquidCrystal_I2C lcd(0x27, 16, 2); // Set I2C address to 0x27 byte ball1[] = { B01110, B01110, B00000, B00000, B00000, B00000, B00000, B00000 }; byte ball2[] = { B00000, B00000, B00000, B00000, B00000, B00000, B01110, B01110 }; byte nothing[] = { B00000, B00000, B00000, B00000, B00000, B00000, B00000, B00000 }; int delay1 = 250; void setup() { lcd.init(); lcd.backlight(); lcd.createChar(0, ball1); lcd.createChar(1, ball2); lcd.createChar(2, nothing); lcd.home(); } void loop() { lcd.setCursor(0, 0); lcd.print(" Bouncing Ball"); // Print "Bouncing Ball" on first line of LCD for(int i = 0; i <= 15; i++) { lcd.setCursor(i, 1); // Set cursor to second line of LCD if(i%2==0)lcd.write(0); // Print ball1 if comparison is even if(i%2==!0)lcd.write(1); // Print ball2 if comparison is odd delay(delay1); // Delay long enough to see ball1 and ball2 lcd.setCursor(i, 1); // Set cursor to second line of LCD lcd.write(2); // Erase ball1 or ball2 } lcd.clear(); }