-
Notifications
You must be signed in to change notification settings - Fork 0
/
spider_lc.cpp
199 lines (131 loc) · 3.62 KB
/
spider_lc.cpp
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#ifdef TEENSYDUINO
#include "spider.h"
#include "bootloader.h"
#include "menu.h"
#include "grid.h"
#include "pixel_dual.h"
#include "tetris.h"
// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
//#include <spi4teensy3.h>
#endif
//#include <SPI.h>
pixelArray *strip[2];
pixelDual *dual;
color_t grid_data[GRID_TOTAL * 2];
USB Usb;
BTD Btd(&Usb);
WII *wii[PLAYERS] = {NULL, NULL};
coms *ledstrip[2] = {NULL, NULL};
elapsedMillis render_time;
void setup_arm() {
//ENABLE SERIAL COMMUNICATION FOR DEBUGGING
Serial.begin(115200);
//INITIALIZE COMS
Serial.println("ATTINY85 Strips");
ledstrip[0] = new coms(11, 12, 14, 4);
ledstrip[1] = new coms(11, 12, 14, 3);
//INITIALIZE THE MAIN LED GRID
Serial.println("Grid 0");
strip[0] = new pixelArray(17, GRID_WIDTH, GRID_HEIGHT, GRID, &grid_data[0]);
strip[0]->begin();
strip[0]->clear();
strip[0]->string("\x7F", 0, GRID_HEIGHT-5, color_t::red().right(5));
strip[0]->show();
//INITIALIZE THE SECONDARY LED GRID
Serial.println("Grid 1");
strip[1] = new pixelArray( 9, GRID_WIDTH, GRID_HEIGHT, GRID, &grid_data[GRID_TOTAL]);
strip[1]->begin();
strip[1]->clear();
strip[1]->string("\x7F", 0, GRID_HEIGHT-5, color_t::red().right(5));
strip[1]->show();
//INITIALIZE THE SECONDARY LED GRID
Serial.println("Dual Grids");
dual = new pixelDual(GRID_WIDTH*2, GRID_HEIGHT, strip[0], strip[1]);
//RANDOMIZE SEED A LITTLE BIT
Serial.println("Randomizer");
pinMode(22, INPUT); //ANALOG 8
pinMode(23, INPUT); //ANALOG 9
randomSeed((uint32_t)uint32_b(analogRead(8), analogRead(9)));
//RESET USB CONTROLLER
Serial.println("USB");
delay(100);
pinMode(7, OUTPUT);
digitalWrite(7, LOW);
delay(100);
digitalWrite(7, HIGH);
delay(100);
strip[0]->string("\x7F\x7F", 0, GRID_HEIGHT-5, color_t::red().right(5));
strip[0]->show();
//CONFIGURE BLUETOOTH SYNC BUTTON
Serial.println("Button");
pinMode(24, INPUT_PULLUP);
//CREATE WII REMOTE BLUETOOTH SERVICES
Serial.println("Players");
for (int i=0; i<PLAYERS; i++) {
wii[i] = new WII(&Btd);
}
//INITIALIZE USB
if (Usb.Init() != -1) {
strip[1]->string("\x7F\x7F", 0, GRID_HEIGHT-5, color_t::red().right(5));
strip[1]->show();
//CREATE MAIN GAME OBJECT
Serial.println("LOADED");
new bootloader();
// new tetris();
render_time = 0;
return;
}
//PROBLEM DURING HARDWARE INIT
strip[0]->clear();
strip[0]->string("OSC", 0, 0, color_t(100,0,0));
strip[0]->string("USB", 0, 5, color_t(0,0,100));
strip[0]->string("Err", 0, 10, color_t(100,0,0));
strip[0]->show();
while (1);
}
//MAIN LOOP
void loop_arm() {
//POLL USB, BLUETOOTH, WII REMOTE
Usb.Task();
//KEEP GENERATING RANDOM NUMBERS
random(255);
//ENABLE BLUETOOTH PAIRING
if (digitalRead(24) == LOW) {
Btd.pairWithWiiRemote();
}
//HANDLE ATTINY85 SPI TRANSFERS
if (!ledstrip[1]->enabled()) ledstrip[0]->loop();
if (!ledstrip[0]->enabled()) ledstrip[1]->loop();
//HANDLE GAME LOOP
animation::loop_all(strip, wii);
//FRAME AND LED RENDERING LOOP
if (render_time >= 20) {
render_time -= 20;
pixelArray::increment();
animation::frame_all(strip, wii);
strip[0]->show();
strip[1]->show();
//CLEAR BUTTON STATES
for (int i=0; i<PLAYERS; i++) {
wii[i]->clear();
}
}
//CHANGE GAME OBJECT BACK TO MAIN MENU
for (int i=0; i<PLAYERS; i++) {
if (!wii[i]->wiimoteConnected) continue;
if (!wii[i]->getButtonClick(HOME)) continue;
Serial.print("\r\nHOME");
animation::delete_all();
strip[0]->clear();
strip[1]->clear();
strip[0]->show();
strip[1]->show();
for (int x=0; x<PLAYERS; x++) {
wii[x]->clear();
}
new menu();
return;
}
}
#endif //TEENSYDUINO