#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const char PEACE_1_1 = 0;
byte peace_1_1[8] = {
0b00000,
0b00000,
0b00000,
0b00011,
0b00110,
0b01100,
0b01000,
0b01000
};
const char PEACE_1_2 = 1;
byte peace_1_2[8] = {
0b00000,
0b00000,
0b11111,
0b00100,
0b00100,
0b00100,
0b00100,
0b00100
};
const char PEACE_1_3 = 2;
byte peace_1_3[8] = {
0b00000,
0b00000,
0b00000,
0b11000,
0b01100,
0b00110,
0b00010,
0b00010
};
const char PEACE_2_1 = 3;
byte peace_2_1[8] = {
0b01000,
0b01000,
0b01101,
0b00110,
0b00011,
0b00000,
0b00000,
0b00000
};
const char PEACE_2_2 = 4;
byte peace_2_2[8] = {
0b01110,
0b10101,
0b00100,
0b00100,
0b00100,
0b11111,
0b00000,
0b00000
};
const char PEACE_2_3 = 5;
byte peace_2_3[8] = {
0b00010,
0b00010,
0b10110,
0b01100,
0b11000,
0b00000,
0b00000,
0b00000
};
const int STR_H = 2;
const int STR_W = 12;
char str[STR_H][STR_W] ;
void fill_array() {
for (int y = 0; y < STR_H; y++) {
for (int x = 0; x < STR_W; x++) {
str[y][x] = ' ';
}
}
str[0][0] = 'P';
str[0][1] = 'E';
str[0][2] = 'A';
str[0][3] = 'C';
str[0][4] = 'E';
}
void show() {
for (int y = 0; y < STR_H; y++) {
for (int x = 0; x < STR_W; x++) {
lcd.setCursor(4 + x, y);
lcd.print(str[y][x]);
}
}
}
void setup() {
lcd.init();
lcd.backlight();
lcd.createChar(PEACE_1_1, peace_1_1);
lcd.createChar(PEACE_1_2, peace_1_2);
lcd.createChar(PEACE_1_3, peace_1_3);
lcd.createChar(PEACE_2_1, peace_2_1);
lcd.createChar(PEACE_2_2, peace_2_2);
lcd.createChar(PEACE_2_3, peace_2_3);
fill_array();
}
const int DELAY = 2;
void move_right() {
for (int i = 0; i <= 4; i++) {
int x = 4 - i;
while ( (x + 1 < STR_W) && (str[0][x + 1] == ' ') ) {
str[0][x + 1] = str[0][x];
str[0][x] = ' ';
x++;
show();
delay(DELAY);
}
}
}
void move_left() {
for (int i = 0; i <= 4; i++) {
int x = STR_W - 5 + i;
while ( (x - 1 > 0) && (str[1][x - 1] == ' ') ) {
str[1][x - 1] = str[1][x];
str[1][x] = ' ';
x--;
show();
delay(DELAY);
}
}
}
void move_down() {
for (int i = 0; i <= 4; i++) {
int x = STR_W - 1 - i;
str[1][x] = str[0][x];
str[0][x] = ' ';
show();
delay(DELAY);
}
}
void move_up() {
for (int x = 0; x <= 4; x++) {
str[0][x] = str[1][x];
str[1][x] = ' ';
show();
delay(DELAY);
}
}
void loop() {
lcd.setCursor(0, 0);
lcd.print(PEACE_1_1);
lcd.print(PEACE_1_2);
lcd.print(PEACE_1_3);
lcd.setCursor(0, 1);
lcd.print(PEACE_2_1);
lcd.print(PEACE_2_2);
lcd.print(PEACE_2_3);
lcd.setCursor(4, 0);
move_right();
move_down();
move_left();
move_up();
}