-
-
Save gnawux/b3f6bb020a6f3a3e1c63 to your computer and use it in GitHub Desktop.
1602 LCD显示生日快乐走马灯效果
This file contains 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 <LCD.h> | |
#include <LiquidCrystal_I2C.h> // F Malpartida's NewLiquidCrystal library | |
#define I2C_ADDR 0x27 // Define I2C Address for controller | |
#define BACKLIGHT_PIN 3 | |
#define En_pin 2 | |
#define Rw_pin 1 | |
#define Rs_pin 0 | |
#define D4_pin 4 | |
#define D5_pin 5 | |
#define D6_pin 6 | |
#define D7_pin 7 | |
#define LED_OFF 0 | |
#define LED_ON 1 | |
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin,BACKLIGHT_PIN,POSITIVE); | |
const char* banners[] ={ | |
" Happy birthday ", | |
" to Siyi! ", | |
" Wish you have ", | |
" a better year! ", | |
"Welcome to Yi's ", | |
"Birthday party " | |
}; | |
char banner1[17]; | |
char banner2[17]; | |
int line = 0; | |
void banner_init() { | |
for(int i = 0; i<16;i++) { | |
banner1[i] = ' '; | |
banner2[i] = ' '; | |
} | |
banner1[16] = '\0'; | |
banner2[16] = '\0'; | |
} | |
void banner_transit(int step){ | |
for(int i=0; i<16; i++) { | |
strncpy(banner1, banner1 + 1, 15); | |
strncpy(banner2, banner2 + 1, 15); | |
banner1[15] = banners[line][i]; | |
banner2[15] = banners[line + 1][i]; | |
banner_display(); | |
delay(step); | |
} | |
} | |
void banner_display() { | |
lcd.setCursor(0,0); | |
lcd.print(banner1); | |
lcd.setCursor(0,1); | |
lcd.print(banner2); | |
} | |
void setup() | |
{ | |
banner_init(); | |
line = 0; | |
lcd.begin (16,2); // initialize the lcd | |
lcd.backlight(); | |
lcd.clear(); | |
lcd.home(); | |
} | |
void loop() | |
{ | |
banner_transit(30); | |
delay(2000); | |
line = (line+2) % 6; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment