1
7
8#define CUSTOM_SETTINGS
9#define INCLUDE_GLCD_SHIELD
10#define INCLUDE_MUSIC_PLAYER_SHIELD
11
12
13#include <OneSheeld.h>
14int c = 0;
15int up = 3;
16int down = 4;
17int left = 5;
18int right = 6;
19int x = 0;
20int y = 0;
21GLCDTextBox score(1, 1, "score:");
22GLCDTextBox number(40, 1, "0");
23char charArray[5];
24void setup()
25{
26
27 pinMode(up, INPUT);
28 digitalWrite(up, HIGH);
29 pinMode(down, INPUT);
30 digitalWrite(down, HIGH);
31 pinMode(left, INPUT);
32 digitalWrite(left, HIGH);
33 pinMode(right, INPUT);
34 digitalWrite(right, HIGH);
35
36 OneSheeld.begin();
37
38 GLCD.clear();
39}
40void loop() {
41 MusicPlayer.play();
42 x = selectrandom();
43 delay(700);
44 y = button();
45 if (x == y)
46 {
47 MusicPlayer.play();
48 c++;
49 }
50 else
51 {
52 MusicPlayer.pause();
53 }
54 GLCD.clear();
55 String(c).toCharArray(charArray, 5);
56 number.setText(charArray);
57 GLCD.draw(score);
58 GLCD.draw(number);
59}
60
61int selectrandom()
62{
63 int x = 0;
64 x = random(1, 5);
65 if (x == 1) arrow(110, 70, 40, 40, "up");
66 if (x == 2) arrow(110, 60, 40, 40, "down");
67 if (x == 3) arrow(60, 43, 40, 40, "left");
68 if (x == 4) arrow(200, 43, 40, 40, "right");
69 return x;
70}
71int button()
72{
73 int y = 0;
74 if (digitalRead(up) == LOW) return y = 1;
75 if (digitalRead(down) == LOW) return y = 2;
76 if (digitalRead(left) == LOW) return y = 3;
77 if (digitalRead(right) == LOW) return y = 4;
78 else return y = 0;
79}
80
81void arrow(int x, int y, int width, int lenght, char *t)
82{
83 if (t == "right")
84 {
85 GLCDLine line(x, y, (x + lenght) - (0.4 * lenght), y);
86 GLCDLine line1(x, y + width, (x + lenght) - (0.4 * lenght), y + width);
87 GLCDLine line2(x, y, x, y + width);
88 GLCDLine line3((x + lenght) - (0.4 * lenght), y + width , (x + lenght) - (0.4 * lenght), y + 1.3 * width);
89 GLCDLine line4((x + lenght) - (0.4 * lenght), abs( y - .3 * width), (x + lenght) - (0.4 * lenght), y);
90 GLCDLine line5((x + lenght) - (0.4 * lenght), y + 1.3 * width, x + lenght , y + .5 * width);
91 GLCDLine line6((x + lenght) - (0.4 * lenght), abs( y - .3 * width), x + lenght, y + .5 * width);
92
93 GLCD.draw(line);
94 GLCD.draw(line1);
95 GLCD.draw(line2);
96 GLCD.draw(line3);
97 GLCD.draw(line4);
98 GLCD.draw(line5);
99 GLCD.draw(line6);
100 }
101 if (t == "left")
102 {
103 GLCDLine line(x, y, abs( (x - lenght) + (0.4 * lenght)), y);
104 GLCDLine line1(x, y + width, abs( (x - lenght) + (0.4 * lenght)), y + width);
105 GLCDLine line2(x, y, x, y + width);
106 GLCDLine line3(abs( (x - lenght) + (0.4 * lenght)), y + width , abs( (x - lenght) + (0.4 * lenght)), y + 1.3 * width);
107 GLCDLine line4(abs( (x - lenght) + (0.4 * lenght)), abs( y - .3 * width), abs( (x - lenght) + (0.4 * lenght)), y);
108 GLCDLine line5(abs( (x - lenght) + (0.4 * lenght)), y + 1.3 * width, abs( x - lenght) , y + .5 * width);
109 GLCDLine line6(abs( (x - lenght) + (0.4 * lenght)), abs( y - .3 * width), abs( x - lenght), y + .5 * width);
110
111 GLCD.draw(line);
112 GLCD.draw(line1);
113 GLCD.draw(line2);
114 GLCD.draw(line3);
115 GLCD.draw(line4);
116 GLCD.draw(line5);
117 GLCD.draw(line6);
118 }
119 if (t == "down")
120 {
121 GLCDLine line(x, y, x, (y + lenght) - (0.4 * lenght));
122 GLCDLine line1(x + width, y, x + width, (y + lenght) - (0.4 * lenght));
123 GLCDLine line2(x, y, x + width, y);
124 GLCDLine line3(x + width, (y + lenght) - (0.4 * lenght), x + 1.3 * width, (y + lenght) - (0.4 * lenght));
125 GLCDLine line4(abs( x - .3 * width), (y + lenght) - (0.4 * lenght), x, (y + lenght) - (0.4 * lenght) );
126 GLCDLine line5(x + 1.3 * width, (y + lenght) - (0.4 * lenght), x + .5 * width, y + lenght);
127 GLCDLine line6(abs( x - .3 * width), (y + lenght) - (0.4 * lenght), x + .5 * width, y + lenght);
128
129 GLCD.draw(line);
130 GLCD.draw(line1);
131 GLCD.draw(line2);
132 GLCD.draw(line3);
133 GLCD.draw(line4);
134 GLCD.draw(line5);
135 GLCD.draw(line6);
136 }
137 if (t == "up")
138 {
139 GLCDLine line(x, y, x, abs((y - lenght) + (0.4 * lenght)));
140 GLCDLine line1( x + width, y, x + width, abs((y - lenght) + (0.4 * lenght)));
141 GLCDLine line2(x, y, x + width, y);
142 GLCDLine line3(x + width , abs( (y - lenght) + (0.4 * lenght)), x + 1.3 * width, abs((y - lenght) + (0.4 * lenght)) );
143 GLCDLine line4(abs( x - .3 * width), abs( (y - lenght) + (0.4 * lenght)), x, abs((y - lenght) + (0.4 * lenght)));
144 GLCDLine line5(x + 1.3 * width, abs( (y - lenght) + (0.4 * lenght)), x + .5 * width, abs( y - lenght));
145 GLCDLine line6(abs( x - .3 * width), abs( (y - lenght) + (0.4 * lenght)), x + .5 * width, abs( y - lenght));
146
147 GLCD.draw(line);
148 GLCD.draw(line1);
149 GLCD.draw(line2);
150 GLCD.draw(line3);
151 GLCD.draw(line4);
152 GLCD.draw(line5);
153 GLCD.draw(line6);
154 }
155}
156