-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpacman_animation
125 lines (107 loc) · 1.6 KB
/
pacman_animation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27(Cooperate with 3 short circuit caps) for a 16 chars and 2 line display
int backlightState = LOW;
long previousMillis = 0;
long interval = 1000;
// make some custom characters:
byte pac1Def[8] = {
B00000,
B01110,
B11011,
B11111,
B11111,
B01110,
B00000,
B00000
};
byte pac2Def[8] = {
B00000,
B01110,
B10100,
B11000,
B11100,
B01110,
B00000,
B00000
};
byte pillDef[8] = {
B00000,
B00000,
B00000,
B01100,
B01100,
B00000,
B00000,
B00000
};
const byte pac1 = 0x0;
const byte pac2 = 0x1;
const byte pill = 0x2;
const int del = 250;
int x = 0;
int y = 0;
int px = 0;
int py = 0;
void setup() {
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.home();
// create a new character
lcd.createChar(0, pac1Def);
// create a new character
lcd.createChar(1, pac2Def);
// create a new character
lcd.createChar(2, pillDef);
// set up the lcd's number of columns and rows:
lcd.begin(16, 2);
// fill the display
fill();
}
void loop() {
anim();
x++;
if(x>15 && y == 0)
{
x = 0;
y = 1;
}
else if(x>15 && y == 1)
{
x = 0;
y = 0;
fill();
}
}
// Initial display fill
void fill()
{
lcd.setCursor(0,0);
lcd.write(0); //pac1
for(int j=0;j<7;j++)
{
lcd.print(" ");
lcd.write(2); //pill
}
lcd.setCursor(0,1);
lcd.write(2); //pill
for(int j=0;j<7;j++)
{
lcd.print(" ");
lcd.write(2); //pill
}
}
// character animation
void anim()
{
lcd.setCursor(px,py);
lcd.print(" ");
lcd.setCursor(x,y);
lcd.write(1); //pac2
delay(del);
lcd.setCursor(x,y);
lcd.write(0); //pac1
delay(del);
px = x;
py = y;
}