-
Notifications
You must be signed in to change notification settings - Fork 2
/
ArduinoInvadersDemo.ino
127 lines (107 loc) · 1.91 KB
/
ArduinoInvadersDemo.ino
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
126
127
//Space Invaders animation for a 16x2 lcd
//LCD SETUP
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//CHARACTER BYTES
byte canon[8] = {
0b00000,
0b00000,
0b00001,
0b00011,
0b11111,
0b00011,
0b00001,
0b00000
};
byte laser[8] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b01110,
0b00000,
0b00000,
0b00000
};
byte invader[8] = {
0b00110,
0b01000,
0b11111,
0b01110,
0b01110,
0b11111,
0b01000,
0b00110
};
byte poof[8] = {
0b10101,
0b01110,
0b00100,
0b11000,
0b00011,
0b00100,
0b01110,
0b10101
};
//COLUMNS & LINES
int columnInvader = 0;
int lineInvader = 0;
int lineCanon = 0;
int columnLaser = 14;
int lineLaser = 0;
void setup() {
//CHARACTERS
lcd.createChar(1, canon);
lcd.createChar(2, laser);
lcd.createChar(3, invader);
lcd.createChar(4, poof);
//STARTINT LCD
lcd.begin(16, 2);
}
void loop() {
//WRITING CANON, LASER & INVADER
lcd.setCursor(15, lineCanon);
lcd.write(1);
lcd.setCursor(columnLaser, lineLaser);
lcd.write(2);
lcd.setCursor(columnInvader, lineInvader);
lcd.write(3);
//RESETTING LASER+INVADER & INVERTING LINE
if(columnInvader == 7 && lineInvader == 0){
columnInvader = -1;
lineInvader++;
}
if(columnLaser == 7 && lineLaser == 0){
columnLaser = 15;
lineLaser++;
lineCanon++;
}
if(columnInvader == 7 && lineInvader == 1){
columnInvader = -1;
lineInvader--;
}
if(columnLaser == 7 && lineLaser == 1){
columnLaser = 15;
lineLaser--;
lineCanon--;
}
//MOVING LASER & INVADER
columnInvader++;
columnLaser--;
//DELAY & CLEAR
delay(250);
lcd.clear();
//EXPLODING INVADER
if(columnLaser == 14 && columnInvader == 0 && lineCanon == 0){
lcd.setCursor(7,1);
lcd.write(4);
}
if(columnLaser == 14 && columnInvader == 0 && lineCanon == 1){
lcd.setCursor(7,0);
lcd.write(4);
}
}
/*
Made by Thijs van Beers
Latest version: 26-5-2014
*/