-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbh-badge-animate.c
78 lines (68 loc) · 1.59 KB
/
bh-badge-animate.c
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
#include "HaD_Badge.h"
uint8_t ballX = 4;
uint8_t ballY = 9;
//Hint: look in HaD_Badge.h for function and constant definitions
void eraseBall() {
//uses global variables to erase current ball
displayPixel(ballX, ballY, OFF);
displayLatch();
}
void moveLeft() {
if (ballX > 0) {
//only move if we're not already at the edge
eraseBall();
--ballX;
displayPixel(ballX, ballY, ON);
displayLatch();
}
}
void moveRight() {
if (ballX < TOTPIXELX-1) {
//only move if we're not already at the edge
eraseBall();
++ballX;
displayPixel(ballX, ballY, ON);
displayLatch();
}
}
void moveUp() {
if (ballY > 0) {
//only move if we're not already at the edge
eraseBall();
--ballY;
displayPixel(ballX, ballY, ON);
displayLatch();
}
}
void moveDown() {
if (ballY < TOTPIXELY-1) {
//only move if we're not already at the edge
eraseBall();
++ballY;
displayPixel(ballX, ballY, ON);
displayLatch();
}
}
void animateBadge(void) {
displayPixel(ballX, ballY, ON);
displayLatch();
while(1) {
switch (getControl()) {
case (ESCAPE):
displayClose();
return;
case (LEFT):
moveLeft();
break;
case (RIGHT):
moveRight();
break;
case (UP):
moveUp();
break;
case (DOWN):
moveDown();
break;
}
}
}