
updated 7seg controls for new 7 seg boards
Dependencies: PixelArray WS2812 mbed
Fork of frdm_pong_table_controller by
main.cpp@9:f3f194982bb3, 2017-07-11 (annotated)
- Committer:
- DanGibbons
- Date:
- Tue Jul 11 13:02:44 2017 +0000
- Revision:
- 9:f3f194982bb3
- Parent:
- 8:66dac2e00cce
- Child:
- 10:554301a1579b
Improved button behaviour.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DanGibbons | 4:2e80bd814f57 | 1 | #include "main.h" |
benswindell | 0:f2b739e846ae | 2 | |
DanGibbons | 4:2e80bd814f57 | 3 | int main() |
DanGibbons | 4:2e80bd814f57 | 4 | { |
DanGibbons | 4:2e80bd814f57 | 5 | Setup(); |
DanGibbons | 7:dc6f1f105c52 | 6 | |
DanGibbons | 9:f3f194982bb3 | 7 | pc.printf("\nSETUP(IDLE)"); |
benswindell | 0:f2b739e846ae | 8 | |
DanGibbons | 4:2e80bd814f57 | 9 | while(1) { |
DanGibbons | 4:2e80bd814f57 | 10 | |
DanGibbons | 9:f3f194982bb3 | 11 | if (idle_flag == 0) { // IDLE |
DanGibbons | 7:dc6f1f105c52 | 12 | |
DanGibbons | 9:f3f194982bb3 | 13 | IdleStateProtocol(); |
DanGibbons | 7:dc6f1f105c52 | 14 | |
DanGibbons | 4:2e80bd814f57 | 15 | } |
DanGibbons | 7:dc6f1f105c52 | 16 | |
DanGibbons | 9:f3f194982bb3 | 17 | if (idle_flag == 1) { // PLAY |
DanGibbons | 7:dc6f1f105c52 | 18 | |
DanGibbons | 9:f3f194982bb3 | 19 | PlayStateProtocol(); |
DanGibbons | 7:dc6f1f105c52 | 20 | |
DanGibbons | 7:dc6f1f105c52 | 21 | } |
DanGibbons | 9:f3f194982bb3 | 22 | |
DanGibbons | 9:f3f194982bb3 | 23 | wait(0.02); |
DanGibbons | 9:f3f194982bb3 | 24 | |
DanGibbons | 4:2e80bd814f57 | 25 | } |
DanGibbons | 6:5e8e2645cd93 | 26 | |
DanGibbons | 4:2e80bd814f57 | 27 | } |
samuelmoss | 2:ff409472bc08 | 28 | |
DanGibbons | 4:2e80bd814f57 | 29 | void Setup() |
benswindell | 0:f2b739e846ae | 30 | { |
benswindell | 0:f2b739e846ae | 31 | // Turn on green LED |
benswindell | 0:f2b739e846ae | 32 | led_green = 0; |
DanGibbons | 6:5e8e2645cd93 | 33 | |
DanGibbons | 8:66dac2e00cce | 34 | // enable the internal pull-down resistor on idleButton |
DanGibbons | 8:66dac2e00cce | 35 | idleButton.mode(PullDown); |
DanGibbons | 8:66dac2e00cce | 36 | |
DanGibbons | 6:5e8e2645cd93 | 37 | // attach idle button isr to rising edge of button press |
DanGibbons | 6:5e8e2645cd93 | 38 | idleButton.rise(&idleButtonISR); |
DanGibbons | 6:5e8e2645cd93 | 39 | |
benswindell | 1:24bc4d8ed2ae | 40 | // Set brightness of the 4 LED strips |
samuelmoss | 2:ff409472bc08 | 41 | robotScoreLED.setII(0xB0); |
benswindell | 1:24bc4d8ed2ae | 42 | robotScoreLED.useII(WS2812::GLOBAL); |
samuelmoss | 2:ff409472bc08 | 43 | playerScoreLED.setII(0xB0); |
benswindell | 1:24bc4d8ed2ae | 44 | playerScoreLED.useII(WS2812::GLOBAL); |
DanGibbons | 4:2e80bd814f57 | 45 | |
benswindell | 0:f2b739e846ae | 46 | // Set scores to 0 |
benswindell | 0:f2b739e846ae | 47 | robotScore = 0; |
benswindell | 0:f2b739e846ae | 48 | playerScore = 0; |
benswindell | 0:f2b739e846ae | 49 | numFlashes = 0; |
DanGibbons | 5:2d439ccefc7d | 50 | |
DanGibbons | 7:dc6f1f105c52 | 51 | memset(mainArray, 0, sizeof mainArray); |
DanGibbons | 7:dc6f1f105c52 | 52 | |
DanGibbons | 7:dc6f1f105c52 | 53 | // Turn off green LED |
DanGibbons | 7:dc6f1f105c52 | 54 | led_green = 1; |
DanGibbons | 7:dc6f1f105c52 | 55 | |
DanGibbons | 7:dc6f1f105c52 | 56 | } |
DanGibbons | 7:dc6f1f105c52 | 57 | |
DanGibbons | 9:f3f194982bb3 | 58 | void IdleStateProtocol() |
DanGibbons | 9:f3f194982bb3 | 59 | { |
DanGibbons | 9:f3f194982bb3 | 60 | if (idle_button_pressed == 1) { // button just pressed |
DanGibbons | 9:f3f194982bb3 | 61 | |
DanGibbons | 9:f3f194982bb3 | 62 | pc.printf("\nIDLE"); |
DanGibbons | 9:f3f194982bb3 | 63 | |
DanGibbons | 9:f3f194982bb3 | 64 | PlayToIdleTransition(); |
DanGibbons | 9:f3f194982bb3 | 65 | |
DanGibbons | 9:f3f194982bb3 | 66 | } |
DanGibbons | 9:f3f194982bb3 | 67 | |
DanGibbons | 9:f3f194982bb3 | 68 | FigureOf8Animation(true,true,true,true,1); |
DanGibbons | 9:f3f194982bb3 | 69 | CircleAnimation(true,true,true,true,1); |
DanGibbons | 9:f3f194982bb3 | 70 | |
DanGibbons | 9:f3f194982bb3 | 71 | } |
DanGibbons | 9:f3f194982bb3 | 72 | |
DanGibbons | 9:f3f194982bb3 | 73 | void PlayStateProtocol() |
DanGibbons | 9:f3f194982bb3 | 74 | { |
DanGibbons | 9:f3f194982bb3 | 75 | if (idle_button_pressed == 1) { // button just pressed |
DanGibbons | 9:f3f194982bb3 | 76 | |
DanGibbons | 9:f3f194982bb3 | 77 | pc.printf("\nPLAY"); |
DanGibbons | 9:f3f194982bb3 | 78 | |
DanGibbons | 9:f3f194982bb3 | 79 | IdleToPlayTransition(); |
DanGibbons | 9:f3f194982bb3 | 80 | |
DanGibbons | 9:f3f194982bb3 | 81 | } |
DanGibbons | 9:f3f194982bb3 | 82 | |
DanGibbons | 9:f3f194982bb3 | 83 | double rbbValue = robotBreakBeam; // Read Robot Break beam |
DanGibbons | 9:f3f194982bb3 | 84 | double pbbValue = playerBreakBeam; // Read Player Break beam |
DanGibbons | 9:f3f194982bb3 | 85 | |
DanGibbons | 9:f3f194982bb3 | 86 | // IF PLAYER HAS SCORED A GOAL |
DanGibbons | 9:f3f194982bb3 | 87 | if (((prevRbbValue - rbbValue)>0.03)|| (PB1==0)) { |
DanGibbons | 9:f3f194982bb3 | 88 | //pc.printf("Player has scored a goal \n\r"); |
DanGibbons | 9:f3f194982bb3 | 89 | HandleGoal(false); |
DanGibbons | 9:f3f194982bb3 | 90 | } |
DanGibbons | 9:f3f194982bb3 | 91 | |
DanGibbons | 9:f3f194982bb3 | 92 | // IF ROBOT HAS SCORED A GOAL |
DanGibbons | 9:f3f194982bb3 | 93 | if (((prevPbbValue - pbbValue) > 0.03)|| (PB2==0)) { |
DanGibbons | 9:f3f194982bb3 | 94 | //pc.printf("Robot has scored a goal \n\r"); |
DanGibbons | 9:f3f194982bb3 | 95 | HandleGoal(true); |
DanGibbons | 9:f3f194982bb3 | 96 | } |
DanGibbons | 9:f3f194982bb3 | 97 | |
DanGibbons | 9:f3f194982bb3 | 98 | prevRbbValue = rbbValue; |
DanGibbons | 9:f3f194982bb3 | 99 | prevPbbValue = pbbValue; |
DanGibbons | 9:f3f194982bb3 | 100 | |
DanGibbons | 9:f3f194982bb3 | 101 | //pc.printf("PlayerGoal: %f, RobotGoal: %f \r\n",pbbValue,rbbValue); |
DanGibbons | 9:f3f194982bb3 | 102 | //pc.printf("Player: %i v %i : Robot \r\n",playerScore,robotScore); |
DanGibbons | 9:f3f194982bb3 | 103 | |
DanGibbons | 9:f3f194982bb3 | 104 | } |
DanGibbons | 9:f3f194982bb3 | 105 | |
DanGibbons | 7:dc6f1f105c52 | 106 | void IdleToPlayTransition() |
DanGibbons | 7:dc6f1f105c52 | 107 | { |
DanGibbons | 9:f3f194982bb3 | 108 | // reset scores |
DanGibbons | 7:dc6f1f105c52 | 109 | robotScore = 0; |
DanGibbons | 7:dc6f1f105c52 | 110 | playerScore = 0; |
DanGibbons | 7:dc6f1f105c52 | 111 | |
DanGibbons | 9:f3f194982bb3 | 112 | // reset array |
DanGibbons | 7:dc6f1f105c52 | 113 | memset(mainArray, 0, sizeof mainArray); |
DanGibbons | 7:dc6f1f105c52 | 114 | |
DanGibbons | 9:f3f194982bb3 | 115 | // form closed loop of LEDs around exterior of display in opposite directions for robot and player scores |
DanGibbons | 9:f3f194982bb3 | 116 | for (int i = 9; i < 115; i++) { |
DanGibbons | 7:dc6f1f105c52 | 117 | |
DanGibbons | 8:66dac2e00cce | 118 | if (i < 104) { |
DanGibbons | 8:66dac2e00cce | 119 | mainArray[0][i] = 1; |
DanGibbons | 8:66dac2e00cce | 120 | } |
DanGibbons | 8:66dac2e00cce | 121 | if (i > 103) { |
DanGibbons | 8:66dac2e00cce | 122 | mainArray[0][i-104] = 1; |
DanGibbons | 8:66dac2e00cce | 123 | } |
DanGibbons | 8:66dac2e00cce | 124 | if (i < 19) { |
DanGibbons | 8:66dac2e00cce | 125 | mainArray[1][18-i] = 1; |
DanGibbons | 8:66dac2e00cce | 126 | } |
DanGibbons | 8:66dac2e00cce | 127 | if (i > 18) { |
DanGibbons | 8:66dac2e00cce | 128 | mainArray[1][122-i] = 1; |
DanGibbons | 8:66dac2e00cce | 129 | } |
DanGibbons | 7:dc6f1f105c52 | 130 | |
DanGibbons | 7:dc6f1f105c52 | 131 | wait_ms(10); |
DanGibbons | 7:dc6f1f105c52 | 132 | |
DanGibbons | 8:66dac2e00cce | 133 | WritePxAnimation(0,false,true); |
DanGibbons | 7:dc6f1f105c52 | 134 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 8:66dac2e00cce | 135 | WritePxAnimation(1,true,true); |
DanGibbons | 7:dc6f1f105c52 | 136 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 8:66dac2e00cce | 137 | |
DanGibbons | 7:dc6f1f105c52 | 138 | } |
DanGibbons | 7:dc6f1f105c52 | 139 | |
DanGibbons | 9:f3f194982bb3 | 140 | // drain closed loop away |
DanGibbons | 9:f3f194982bb3 | 141 | DrainAnimation(true,true,true,true); |
DanGibbons | 5:2d439ccefc7d | 142 | |
DanGibbons | 7:dc6f1f105c52 | 143 | wait(1); |
DanGibbons | 7:dc6f1f105c52 | 144 | |
DanGibbons | 9:f3f194982bb3 | 145 | // flash 0-0 on display |
DanGibbons | 8:66dac2e00cce | 146 | WriteScores(); |
DanGibbons | 8:66dac2e00cce | 147 | |
DanGibbons | 8:66dac2e00cce | 148 | idleButton.enable_irq(); |
DanGibbons | 5:2d439ccefc7d | 149 | |
DanGibbons | 9:f3f194982bb3 | 150 | idle_button_pressed = 0; |
DanGibbons | 9:f3f194982bb3 | 151 | |
DanGibbons | 7:dc6f1f105c52 | 152 | } |
samuelmoss | 2:ff409472bc08 | 153 | |
DanGibbons | 7:dc6f1f105c52 | 154 | void PlayToIdleTransition() |
DanGibbons | 7:dc6f1f105c52 | 155 | { |
DanGibbons | 9:f3f194982bb3 | 156 | // reset scores and main array |
DanGibbons | 7:dc6f1f105c52 | 157 | robotScore = 0; |
DanGibbons | 7:dc6f1f105c52 | 158 | playerScore = 0; |
DanGibbons | 7:dc6f1f105c52 | 159 | memset(mainArray, 0, sizeof mainArray); |
DanGibbons | 7:dc6f1f105c52 | 160 | |
DanGibbons | 9:f3f194982bb3 | 161 | FigureOf8Animation(true,true,true,true,1); |
DanGibbons | 9:f3f194982bb3 | 162 | |
DanGibbons | 8:66dac2e00cce | 163 | idleButton.enable_irq(); |
DanGibbons | 9:f3f194982bb3 | 164 | |
DanGibbons | 9:f3f194982bb3 | 165 | idle_button_pressed = 0; |
DanGibbons | 8:66dac2e00cce | 166 | |
benswindell | 0:f2b739e846ae | 167 | } |
benswindell | 0:f2b739e846ae | 168 | |
DanGibbons | 5:2d439ccefc7d | 169 | // set segment number patterns |
DanGibbons | 4:2e80bd814f57 | 170 | void SetNumberPatterns() |
benswindell | 0:f2b739e846ae | 171 | { |
DanGibbons | 4:2e80bd814f57 | 172 | for (int num = 0; num < 11; num++) { |
benswindell | 0:f2b739e846ae | 173 | |
DanGibbons | 4:2e80bd814f57 | 174 | switch (num) { |
DanGibbons | 4:2e80bd814f57 | 175 | case 0 : |
DanGibbons | 4:2e80bd814f57 | 176 | // 0 |
DanGibbons | 4:2e80bd814f57 | 177 | seg1A = 1; |
DanGibbons | 4:2e80bd814f57 | 178 | seg1B = 1; |
DanGibbons | 4:2e80bd814f57 | 179 | seg1C = 1; |
DanGibbons | 4:2e80bd814f57 | 180 | seg1D = 1; |
DanGibbons | 4:2e80bd814f57 | 181 | seg1E = 1; |
DanGibbons | 4:2e80bd814f57 | 182 | seg1F = 1; |
DanGibbons | 4:2e80bd814f57 | 183 | seg1G = 0; |
benswindell | 0:f2b739e846ae | 184 | |
DanGibbons | 4:2e80bd814f57 | 185 | SetLEDArray(0); |
DanGibbons | 4:2e80bd814f57 | 186 | break; |
benswindell | 0:f2b739e846ae | 187 | |
DanGibbons | 4:2e80bd814f57 | 188 | case 1 : |
DanGibbons | 4:2e80bd814f57 | 189 | // 1 |
DanGibbons | 4:2e80bd814f57 | 190 | seg1A = 0; |
DanGibbons | 4:2e80bd814f57 | 191 | seg1B = 1; |
DanGibbons | 4:2e80bd814f57 | 192 | seg1C = 1; |
DanGibbons | 4:2e80bd814f57 | 193 | seg1D = 0; |
DanGibbons | 4:2e80bd814f57 | 194 | seg1E = 0; |
DanGibbons | 4:2e80bd814f57 | 195 | seg1F = 0; |
DanGibbons | 4:2e80bd814f57 | 196 | seg1G = 0; |
benswindell | 0:f2b739e846ae | 197 | |
DanGibbons | 4:2e80bd814f57 | 198 | SetLEDArray(1); |
DanGibbons | 4:2e80bd814f57 | 199 | break; |
benswindell | 0:f2b739e846ae | 200 | |
DanGibbons | 4:2e80bd814f57 | 201 | case 2 : |
DanGibbons | 4:2e80bd814f57 | 202 | // 2 |
DanGibbons | 4:2e80bd814f57 | 203 | seg1A = 1; |
DanGibbons | 4:2e80bd814f57 | 204 | seg1B = 1; |
DanGibbons | 4:2e80bd814f57 | 205 | seg1C = 0; |
DanGibbons | 4:2e80bd814f57 | 206 | seg1D = 1; |
DanGibbons | 4:2e80bd814f57 | 207 | seg1E = 1; |
DanGibbons | 4:2e80bd814f57 | 208 | seg1F = 0; |
DanGibbons | 4:2e80bd814f57 | 209 | seg1G = 1; |
benswindell | 0:f2b739e846ae | 210 | |
DanGibbons | 4:2e80bd814f57 | 211 | SetLEDArray(2); |
DanGibbons | 4:2e80bd814f57 | 212 | break; |
benswindell | 0:f2b739e846ae | 213 | |
DanGibbons | 4:2e80bd814f57 | 214 | case 3 : |
DanGibbons | 4:2e80bd814f57 | 215 | // 3 |
DanGibbons | 4:2e80bd814f57 | 216 | seg1A = 1; |
DanGibbons | 4:2e80bd814f57 | 217 | seg1B = 1; |
DanGibbons | 4:2e80bd814f57 | 218 | seg1C = 1; |
DanGibbons | 4:2e80bd814f57 | 219 | seg1D = 1; |
DanGibbons | 4:2e80bd814f57 | 220 | seg1E = 0; |
DanGibbons | 4:2e80bd814f57 | 221 | seg1F = 0; |
DanGibbons | 4:2e80bd814f57 | 222 | seg1G = 1; |
benswindell | 0:f2b739e846ae | 223 | |
DanGibbons | 4:2e80bd814f57 | 224 | SetLEDArray(3); |
DanGibbons | 4:2e80bd814f57 | 225 | break; |
benswindell | 0:f2b739e846ae | 226 | |
DanGibbons | 4:2e80bd814f57 | 227 | case 4: |
DanGibbons | 4:2e80bd814f57 | 228 | // 4 |
DanGibbons | 4:2e80bd814f57 | 229 | seg1A = 0; |
DanGibbons | 4:2e80bd814f57 | 230 | seg1B = 1; |
DanGibbons | 4:2e80bd814f57 | 231 | seg1C = 1; |
DanGibbons | 4:2e80bd814f57 | 232 | seg1D = 0; |
DanGibbons | 4:2e80bd814f57 | 233 | seg1E = 0; |
DanGibbons | 4:2e80bd814f57 | 234 | seg1F = 1; |
DanGibbons | 4:2e80bd814f57 | 235 | seg1G = 1; |
benswindell | 0:f2b739e846ae | 236 | |
DanGibbons | 4:2e80bd814f57 | 237 | SetLEDArray(4); |
DanGibbons | 4:2e80bd814f57 | 238 | break; |
benswindell | 0:f2b739e846ae | 239 | |
DanGibbons | 4:2e80bd814f57 | 240 | case 5: |
DanGibbons | 4:2e80bd814f57 | 241 | // 5 |
DanGibbons | 4:2e80bd814f57 | 242 | seg1A = 1; |
DanGibbons | 4:2e80bd814f57 | 243 | seg1B = 0; |
DanGibbons | 4:2e80bd814f57 | 244 | seg1C = 1; |
DanGibbons | 4:2e80bd814f57 | 245 | seg1D = 1; |
DanGibbons | 4:2e80bd814f57 | 246 | seg1E = 0; |
DanGibbons | 4:2e80bd814f57 | 247 | seg1F = 1; |
DanGibbons | 4:2e80bd814f57 | 248 | seg1G = 1; |
benswindell | 0:f2b739e846ae | 249 | |
DanGibbons | 4:2e80bd814f57 | 250 | SetLEDArray(5); |
DanGibbons | 4:2e80bd814f57 | 251 | break; |
benswindell | 0:f2b739e846ae | 252 | |
DanGibbons | 4:2e80bd814f57 | 253 | case 6: |
DanGibbons | 4:2e80bd814f57 | 254 | // 6 |
DanGibbons | 4:2e80bd814f57 | 255 | seg1A = 1; |
DanGibbons | 4:2e80bd814f57 | 256 | seg1B = 0; |
DanGibbons | 4:2e80bd814f57 | 257 | seg1C = 1; |
DanGibbons | 4:2e80bd814f57 | 258 | seg1D = 1; |
DanGibbons | 4:2e80bd814f57 | 259 | seg1E = 1; |
DanGibbons | 4:2e80bd814f57 | 260 | seg1F = 1; |
DanGibbons | 4:2e80bd814f57 | 261 | seg1G = 1; |
benswindell | 0:f2b739e846ae | 262 | |
DanGibbons | 4:2e80bd814f57 | 263 | SetLEDArray(6); |
DanGibbons | 4:2e80bd814f57 | 264 | break; |
benswindell | 0:f2b739e846ae | 265 | |
DanGibbons | 4:2e80bd814f57 | 266 | case 7: |
DanGibbons | 4:2e80bd814f57 | 267 | // 7 |
DanGibbons | 4:2e80bd814f57 | 268 | seg1A = 1; |
DanGibbons | 4:2e80bd814f57 | 269 | seg1B = 1; |
DanGibbons | 4:2e80bd814f57 | 270 | seg1C = 1; |
DanGibbons | 4:2e80bd814f57 | 271 | seg1D = 0; |
DanGibbons | 4:2e80bd814f57 | 272 | seg1E = 0; |
DanGibbons | 4:2e80bd814f57 | 273 | seg1F = 0; |
DanGibbons | 4:2e80bd814f57 | 274 | seg1G = 0; |
benswindell | 0:f2b739e846ae | 275 | |
DanGibbons | 4:2e80bd814f57 | 276 | SetLEDArray(7); |
DanGibbons | 4:2e80bd814f57 | 277 | break; |
benswindell | 0:f2b739e846ae | 278 | |
DanGibbons | 4:2e80bd814f57 | 279 | case 8: |
DanGibbons | 4:2e80bd814f57 | 280 | // 8 |
DanGibbons | 4:2e80bd814f57 | 281 | seg1A = 1; |
DanGibbons | 4:2e80bd814f57 | 282 | seg1B = 1; |
DanGibbons | 4:2e80bd814f57 | 283 | seg1C = 1; |
DanGibbons | 4:2e80bd814f57 | 284 | seg1D = 1; |
DanGibbons | 4:2e80bd814f57 | 285 | seg1E = 1; |
DanGibbons | 4:2e80bd814f57 | 286 | seg1F = 1; |
DanGibbons | 4:2e80bd814f57 | 287 | seg1G = 1; |
benswindell | 0:f2b739e846ae | 288 | |
DanGibbons | 4:2e80bd814f57 | 289 | SetLEDArray(8); |
DanGibbons | 4:2e80bd814f57 | 290 | break; |
benswindell | 0:f2b739e846ae | 291 | |
DanGibbons | 4:2e80bd814f57 | 292 | case 9: |
DanGibbons | 4:2e80bd814f57 | 293 | // 9 |
DanGibbons | 4:2e80bd814f57 | 294 | seg1A = 1; |
DanGibbons | 4:2e80bd814f57 | 295 | seg1B = 1; |
DanGibbons | 4:2e80bd814f57 | 296 | seg1C = 1; |
DanGibbons | 4:2e80bd814f57 | 297 | seg1D = 0; |
DanGibbons | 4:2e80bd814f57 | 298 | seg1E = 0; |
DanGibbons | 4:2e80bd814f57 | 299 | seg1F = 1; |
DanGibbons | 4:2e80bd814f57 | 300 | seg1G = 1; |
benswindell | 0:f2b739e846ae | 301 | |
DanGibbons | 4:2e80bd814f57 | 302 | SetLEDArray(9); |
DanGibbons | 4:2e80bd814f57 | 303 | break; |
benswindell | 0:f2b739e846ae | 304 | |
DanGibbons | 4:2e80bd814f57 | 305 | case 10: |
DanGibbons | 4:2e80bd814f57 | 306 | // OFF |
DanGibbons | 4:2e80bd814f57 | 307 | seg1A = 0; |
DanGibbons | 4:2e80bd814f57 | 308 | seg1B = 0; |
DanGibbons | 4:2e80bd814f57 | 309 | seg1C = 0; |
DanGibbons | 4:2e80bd814f57 | 310 | seg1D = 0; |
DanGibbons | 4:2e80bd814f57 | 311 | seg1E = 0; |
DanGibbons | 4:2e80bd814f57 | 312 | seg1F = 0; |
DanGibbons | 4:2e80bd814f57 | 313 | seg1G = 0; |
benswindell | 0:f2b739e846ae | 314 | |
DanGibbons | 4:2e80bd814f57 | 315 | SetLEDArray(10); |
DanGibbons | 4:2e80bd814f57 | 316 | break; |
benswindell | 0:f2b739e846ae | 317 | |
DanGibbons | 4:2e80bd814f57 | 318 | default : |
benswindell | 0:f2b739e846ae | 319 | |
DanGibbons | 4:2e80bd814f57 | 320 | break; |
DanGibbons | 4:2e80bd814f57 | 321 | |
DanGibbons | 4:2e80bd814f57 | 322 | } |
benswindell | 0:f2b739e846ae | 323 | |
benswindell | 0:f2b739e846ae | 324 | } |
DanGibbons | 4:2e80bd814f57 | 325 | |
DanGibbons | 4:2e80bd814f57 | 326 | } |
DanGibbons | 4:2e80bd814f57 | 327 | |
benswindell | 0:f2b739e846ae | 328 | // Write segment config to main array |
benswindell | 0:f2b739e846ae | 329 | void SetLEDArray(int x) |
benswindell | 0:f2b739e846ae | 330 | { |
benswindell | 0:f2b739e846ae | 331 | for (int i = 0; i < WS2812_BUF; i++) { |
samuelmoss | 2:ff409472bc08 | 332 | if (i < 18) { |
DanGibbons | 5:2d439ccefc7d | 333 | mainArray[x][i] = seg1A; |
benswindell | 0:f2b739e846ae | 334 | } |
benswindell | 0:f2b739e846ae | 335 | |
samuelmoss | 2:ff409472bc08 | 336 | if ( i >= 18 && i < 35) { |
benswindell | 0:f2b739e846ae | 337 | mainArray[x][i] = seg1B; |
benswindell | 0:f2b739e846ae | 338 | } |
benswindell | 0:f2b739e846ae | 339 | |
samuelmoss | 2:ff409472bc08 | 340 | if (i >= 35 && i < 52) { |
benswindell | 0:f2b739e846ae | 341 | mainArray[x][i] = seg1C; |
benswindell | 0:f2b739e846ae | 342 | } |
benswindell | 0:f2b739e846ae | 343 | |
samuelmoss | 2:ff409472bc08 | 344 | if (i >= 52 && i < 70) { |
benswindell | 0:f2b739e846ae | 345 | mainArray[x][i]= seg1D; |
benswindell | 0:f2b739e846ae | 346 | } |
benswindell | 0:f2b739e846ae | 347 | |
samuelmoss | 2:ff409472bc08 | 348 | if ( i >= 70 && i < 87) { |
benswindell | 0:f2b739e846ae | 349 | mainArray[x][i] = seg1E; |
benswindell | 0:f2b739e846ae | 350 | } |
benswindell | 0:f2b739e846ae | 351 | |
samuelmoss | 2:ff409472bc08 | 352 | if (i >= 87 && i < 104) { |
benswindell | 0:f2b739e846ae | 353 | mainArray[x][i] = seg1F; |
benswindell | 0:f2b739e846ae | 354 | } |
benswindell | 0:f2b739e846ae | 355 | |
samuelmoss | 2:ff409472bc08 | 356 | if ( i >= 104 && i < 122) { |
benswindell | 0:f2b739e846ae | 357 | mainArray[x][i] = seg1G; |
benswindell | 0:f2b739e846ae | 358 | } |
DanGibbons | 4:2e80bd814f57 | 359 | } |
benswindell | 0:f2b739e846ae | 360 | } |
benswindell | 0:f2b739e846ae | 361 | |
benswindell | 1:24bc4d8ed2ae | 362 | // Update both Score LEDs with the current score |
DanGibbons | 8:66dac2e00cce | 363 | void WriteScores() |
benswindell | 0:f2b739e846ae | 364 | { |
DanGibbons | 8:66dac2e00cce | 365 | SetNumberPatterns(); |
DanGibbons | 6:5e8e2645cd93 | 366 | WritePxAnimation(playerScore,false,false); |
benswindell | 1:24bc4d8ed2ae | 367 | playerScoreLED.write(playerScorePx.getBuf()); |
benswindell | 0:f2b739e846ae | 368 | wait(0.01); |
DanGibbons | 6:5e8e2645cd93 | 369 | WritePxAnimation(robotScore,true,false); |
benswindell | 1:24bc4d8ed2ae | 370 | robotScoreLED.write(robotScorePx.getBuf()); |
benswindell | 0:f2b739e846ae | 371 | } |
benswindell | 0:f2b739e846ae | 372 | |
DanGibbons | 6:5e8e2645cd93 | 373 | // Write Pixel array with either random colour pattern or in standard blue |
DanGibbons | 6:5e8e2645cd93 | 374 | void WritePxAnimation(int line_num,bool isRobot,bool colour) |
benswindell | 0:f2b739e846ae | 375 | { |
DanGibbons | 6:5e8e2645cd93 | 376 | if (colour == true) { // random colours |
DanGibbons | 6:5e8e2645cd93 | 377 | if(isRobot == true) { |
benswindell | 1:24bc4d8ed2ae | 378 | |
DanGibbons | 6:5e8e2645cd93 | 379 | for (int i = 0; i < WS2812_BUF; i++) { |
DanGibbons | 6:5e8e2645cd93 | 380 | if (mainArray[line_num][i] == 0) { |
DanGibbons | 6:5e8e2645cd93 | 381 | robotScorePx.Set(i,OFF); |
DanGibbons | 6:5e8e2645cd93 | 382 | } |
DanGibbons | 5:2d439ccefc7d | 383 | |
DanGibbons | 6:5e8e2645cd93 | 384 | if (mainArray[line_num][i] == 1) { |
DanGibbons | 6:5e8e2645cd93 | 385 | robotScorePx.Set(i,rand_colors[rand() % 10]); |
DanGibbons | 6:5e8e2645cd93 | 386 | } |
DanGibbons | 5:2d439ccefc7d | 387 | } |
DanGibbons | 6:5e8e2645cd93 | 388 | } else { |
DanGibbons | 6:5e8e2645cd93 | 389 | for (int i = 0; i < WS2812_BUF; i++) { |
DanGibbons | 6:5e8e2645cd93 | 390 | if (mainArray[line_num][i] == 0) { |
DanGibbons | 6:5e8e2645cd93 | 391 | playerScorePx.Set(i,OFF); |
DanGibbons | 6:5e8e2645cd93 | 392 | } |
DanGibbons | 5:2d439ccefc7d | 393 | |
DanGibbons | 6:5e8e2645cd93 | 394 | if (mainArray[line_num][i] == 1) { |
DanGibbons | 6:5e8e2645cd93 | 395 | playerScorePx.Set(i,rand_colors[rand() % 10]); |
DanGibbons | 6:5e8e2645cd93 | 396 | } |
DanGibbons | 5:2d439ccefc7d | 397 | } |
DanGibbons | 5:2d439ccefc7d | 398 | } |
DanGibbons | 6:5e8e2645cd93 | 399 | } else { // blue |
DanGibbons | 6:5e8e2645cd93 | 400 | if(isRobot == true) { |
DanGibbons | 6:5e8e2645cd93 | 401 | |
DanGibbons | 6:5e8e2645cd93 | 402 | for (int i = 0; i < WS2812_BUF; i++) { |
DanGibbons | 6:5e8e2645cd93 | 403 | if (mainArray[line_num][i] == 0) { |
DanGibbons | 6:5e8e2645cd93 | 404 | robotScorePx.Set(i,OFF); |
DanGibbons | 6:5e8e2645cd93 | 405 | } |
DanGibbons | 6:5e8e2645cd93 | 406 | |
DanGibbons | 6:5e8e2645cd93 | 407 | if (mainArray[line_num][i] == 1) { |
DanGibbons | 6:5e8e2645cd93 | 408 | robotScorePx.Set(i,BLUE); |
DanGibbons | 6:5e8e2645cd93 | 409 | } |
DanGibbons | 5:2d439ccefc7d | 410 | } |
DanGibbons | 6:5e8e2645cd93 | 411 | } else { |
DanGibbons | 6:5e8e2645cd93 | 412 | for (int i = 0; i < WS2812_BUF; i++) { |
DanGibbons | 6:5e8e2645cd93 | 413 | if (mainArray[line_num][i] == 0) { |
DanGibbons | 6:5e8e2645cd93 | 414 | playerScorePx.Set(i,OFF); |
DanGibbons | 6:5e8e2645cd93 | 415 | } |
DanGibbons | 5:2d439ccefc7d | 416 | |
DanGibbons | 6:5e8e2645cd93 | 417 | if (mainArray[line_num][i] == 1) { |
DanGibbons | 6:5e8e2645cd93 | 418 | playerScorePx.Set(i,BLUE); |
DanGibbons | 6:5e8e2645cd93 | 419 | } |
DanGibbons | 5:2d439ccefc7d | 420 | } |
DanGibbons | 5:2d439ccefc7d | 421 | } |
DanGibbons | 5:2d439ccefc7d | 422 | |
DanGibbons | 6:5e8e2645cd93 | 423 | } |
DanGibbons | 6:5e8e2645cd93 | 424 | } |
benswindell | 0:f2b739e846ae | 425 | |
DanGibbons | 6:5e8e2645cd93 | 426 | // Handle behaviour for the goal scored event |
benswindell | 0:f2b739e846ae | 427 | void HandleGoal(bool hasRobotScored) |
benswindell | 0:f2b739e846ae | 428 | { |
DanGibbons | 4:2e80bd814f57 | 429 | GoalAnimation(hasRobotScored); |
benswindell | 1:24bc4d8ed2ae | 430 | |
DanGibbons | 9:f3f194982bb3 | 431 | // If either player reaches the score limit, then call HandleWin() |
benswindell | 1:24bc4d8ed2ae | 432 | if(robotScore == scoreLimit || playerScore == scoreLimit) { |
benswindell | 1:24bc4d8ed2ae | 433 | HandleWin(); |
samuelmoss | 2:ff409472bc08 | 434 | } |
benswindell | 1:24bc4d8ed2ae | 435 | } |
benswindell | 1:24bc4d8ed2ae | 436 | |
benswindell | 1:24bc4d8ed2ae | 437 | // Handle behaviour when either the player or robot has won a game. |
benswindell | 1:24bc4d8ed2ae | 438 | void HandleWin() |
benswindell | 1:24bc4d8ed2ae | 439 | { |
benswindell | 1:24bc4d8ed2ae | 440 | // Initalise variable as true |
benswindell | 1:24bc4d8ed2ae | 441 | bool isRobotWinner = true; |
benswindell | 1:24bc4d8ed2ae | 442 | |
benswindell | 1:24bc4d8ed2ae | 443 | // Decide if the robot is the winner. If not, then change isRobotWinner to false |
benswindell | 1:24bc4d8ed2ae | 444 | if(playerScore == scoreLimit) { |
DanGibbons | 4:2e80bd814f57 | 445 | |
benswindell | 1:24bc4d8ed2ae | 446 | isRobotWinner = false; |
benswindell | 1:24bc4d8ed2ae | 447 | pc.printf("Player won!"); |
DanGibbons | 4:2e80bd814f57 | 448 | WinAnimation(isRobotWinner); |
benswindell | 1:24bc4d8ed2ae | 449 | |
benswindell | 1:24bc4d8ed2ae | 450 | } else { |
benswindell | 1:24bc4d8ed2ae | 451 | pc.printf("Robot won!"); |
DanGibbons | 4:2e80bd814f57 | 452 | WinAnimation(isRobotWinner); |
benswindell | 1:24bc4d8ed2ae | 453 | |
benswindell | 1:24bc4d8ed2ae | 454 | } |
benswindell | 1:24bc4d8ed2ae | 455 | |
benswindell | 1:24bc4d8ed2ae | 456 | // Reset scores then write to LEDs |
benswindell | 1:24bc4d8ed2ae | 457 | robotScore = 0; |
benswindell | 1:24bc4d8ed2ae | 458 | playerScore = 0; |
DanGibbons | 5:2d439ccefc7d | 459 | |
DanGibbons | 9:f3f194982bb3 | 460 | // IDLE state |
DanGibbons | 7:dc6f1f105c52 | 461 | idle_flag = 0; |
DanGibbons | 5:2d439ccefc7d | 462 | |
DanGibbons | 7:dc6f1f105c52 | 463 | memset(mainArray, 0, sizeof mainArray); |
DanGibbons | 6:5e8e2645cd93 | 464 | |
benswindell | 0:f2b739e846ae | 465 | } |
benswindell | 0:f2b739e846ae | 466 | |
DanGibbons | 5:2d439ccefc7d | 467 | // animation for when a goal is scored |
DanGibbons | 4:2e80bd814f57 | 468 | void GoalAnimation(bool hasRobotScored) |
benswindell | 0:f2b739e846ae | 469 | { |
DanGibbons | 4:2e80bd814f57 | 470 | if(hasRobotScored == true) { |
DanGibbons | 6:5e8e2645cd93 | 471 | |
DanGibbons | 9:f3f194982bb3 | 472 | // clear current score |
DanGibbons | 6:5e8e2645cd93 | 473 | switch (robotScore) { |
DanGibbons | 6:5e8e2645cd93 | 474 | case 0: |
DanGibbons | 6:5e8e2645cd93 | 475 | ZeroOutAnimation(true,false,false,false); |
DanGibbons | 6:5e8e2645cd93 | 476 | break; |
DanGibbons | 6:5e8e2645cd93 | 477 | case 1: |
DanGibbons | 6:5e8e2645cd93 | 478 | OneOutAnimation(true,false,false,false); |
DanGibbons | 6:5e8e2645cd93 | 479 | break; |
DanGibbons | 6:5e8e2645cd93 | 480 | case 2: |
DanGibbons | 6:5e8e2645cd93 | 481 | TwoOutAnimation(true,false,false,false); |
DanGibbons | 6:5e8e2645cd93 | 482 | break; |
DanGibbons | 6:5e8e2645cd93 | 483 | case 3: |
DanGibbons | 6:5e8e2645cd93 | 484 | ThreeOutAnimation(true,false,false,false); |
DanGibbons | 6:5e8e2645cd93 | 485 | default : |
DanGibbons | 6:5e8e2645cd93 | 486 | break; |
DanGibbons | 6:5e8e2645cd93 | 487 | } |
DanGibbons | 9:f3f194982bb3 | 488 | |
DanGibbons | 9:f3f194982bb3 | 489 | // increment score |
DanGibbons | 4:2e80bd814f57 | 490 | robotScore++; |
DanGibbons | 5:2d439ccefc7d | 491 | wait_ms(250); |
DanGibbons | 6:5e8e2645cd93 | 492 | |
DanGibbons | 9:f3f194982bb3 | 493 | // write new score |
DanGibbons | 6:5e8e2645cd93 | 494 | switch (robotScore) { |
DanGibbons | 6:5e8e2645cd93 | 495 | case 0: |
DanGibbons | 6:5e8e2645cd93 | 496 | ZeroInAnimation(true,false,false,false); |
DanGibbons | 6:5e8e2645cd93 | 497 | break; |
DanGibbons | 6:5e8e2645cd93 | 498 | case 1: |
DanGibbons | 6:5e8e2645cd93 | 499 | OneInAnimation(true,false,false,false); |
DanGibbons | 6:5e8e2645cd93 | 500 | break; |
DanGibbons | 6:5e8e2645cd93 | 501 | case 2: |
DanGibbons | 6:5e8e2645cd93 | 502 | TwoInAnimation(true,false,false,false); |
DanGibbons | 6:5e8e2645cd93 | 503 | break; |
DanGibbons | 6:5e8e2645cd93 | 504 | case 3: |
DanGibbons | 9:f3f194982bb3 | 505 | ThreeInAnimation(true,true,false,false); // with random colour pattern |
DanGibbons | 6:5e8e2645cd93 | 506 | default : |
DanGibbons | 6:5e8e2645cd93 | 507 | break; |
DanGibbons | 6:5e8e2645cd93 | 508 | } |
DanGibbons | 4:2e80bd814f57 | 509 | |
DanGibbons | 4:2e80bd814f57 | 510 | } else { |
DanGibbons | 6:5e8e2645cd93 | 511 | |
DanGibbons | 9:f3f194982bb3 | 512 | // clear current score |
DanGibbons | 6:5e8e2645cd93 | 513 | switch (playerScore) { |
DanGibbons | 6:5e8e2645cd93 | 514 | case 0: |
DanGibbons | 6:5e8e2645cd93 | 515 | ZeroOutAnimation(false,false,true,false); |
DanGibbons | 6:5e8e2645cd93 | 516 | break; |
DanGibbons | 6:5e8e2645cd93 | 517 | case 1: |
DanGibbons | 6:5e8e2645cd93 | 518 | OneOutAnimation(false,false,true,false); |
DanGibbons | 6:5e8e2645cd93 | 519 | break; |
DanGibbons | 6:5e8e2645cd93 | 520 | case 2: |
DanGibbons | 6:5e8e2645cd93 | 521 | TwoOutAnimation(false,false,true,false); |
DanGibbons | 6:5e8e2645cd93 | 522 | break; |
DanGibbons | 6:5e8e2645cd93 | 523 | case 3: |
DanGibbons | 6:5e8e2645cd93 | 524 | ThreeOutAnimation(false,false ,true,false); |
DanGibbons | 6:5e8e2645cd93 | 525 | default : |
DanGibbons | 6:5e8e2645cd93 | 526 | break; |
DanGibbons | 6:5e8e2645cd93 | 527 | } |
DanGibbons | 9:f3f194982bb3 | 528 | |
DanGibbons | 9:f3f194982bb3 | 529 | // increment score |
DanGibbons | 4:2e80bd814f57 | 530 | playerScore++; |
DanGibbons | 5:2d439ccefc7d | 531 | wait_ms(250); |
DanGibbons | 6:5e8e2645cd93 | 532 | |
DanGibbons | 9:f3f194982bb3 | 533 | // write new score |
DanGibbons | 6:5e8e2645cd93 | 534 | switch (playerScore) { |
DanGibbons | 6:5e8e2645cd93 | 535 | case 0: |
DanGibbons | 6:5e8e2645cd93 | 536 | ZeroInAnimation(false,false,true,false); |
DanGibbons | 6:5e8e2645cd93 | 537 | break; |
DanGibbons | 6:5e8e2645cd93 | 538 | case 1: |
DanGibbons | 6:5e8e2645cd93 | 539 | OneInAnimation(false,false,true,false); |
DanGibbons | 6:5e8e2645cd93 | 540 | break; |
DanGibbons | 6:5e8e2645cd93 | 541 | case 2: |
DanGibbons | 6:5e8e2645cd93 | 542 | TwoInAnimation(false,false,true,false); |
DanGibbons | 6:5e8e2645cd93 | 543 | break; |
DanGibbons | 6:5e8e2645cd93 | 544 | case 3: |
DanGibbons | 9:f3f194982bb3 | 545 | ThreeInAnimation(false,false,true,true); // with random colour pattern |
DanGibbons | 6:5e8e2645cd93 | 546 | default : |
DanGibbons | 6:5e8e2645cd93 | 547 | break; |
DanGibbons | 6:5e8e2645cd93 | 548 | } |
DanGibbons | 4:2e80bd814f57 | 549 | } |
DanGibbons | 4:2e80bd814f57 | 550 | |
DanGibbons | 4:2e80bd814f57 | 551 | } |
benswindell | 0:f2b739e846ae | 552 | |
DanGibbons | 5:2d439ccefc7d | 553 | // animation when player or robot win the game |
DanGibbons | 4:2e80bd814f57 | 554 | void WinAnimation(bool isRobotWinner) |
DanGibbons | 4:2e80bd814f57 | 555 | { |
DanGibbons | 4:2e80bd814f57 | 556 | if(isRobotWinner == false) { |
DanGibbons | 4:2e80bd814f57 | 557 | |
DanGibbons | 6:5e8e2645cd93 | 558 | // dim brightness of the robot score because it lost |
DanGibbons | 6:5e8e2645cd93 | 559 | robotScoreLED.setII(0x20); |
DanGibbons | 6:5e8e2645cd93 | 560 | robotScoreLED.useII(WS2812::GLOBAL); |
DanGibbons | 6:5e8e2645cd93 | 561 | robotScoreLED.write(robotScorePx.getBuf()); // rewrite buffer to change brightness |
DanGibbons | 6:5e8e2645cd93 | 562 | |
DanGibbons | 6:5e8e2645cd93 | 563 | for (int i = 0; i < 80; i++) { // flash player score with changing random colours |
DanGibbons | 6:5e8e2645cd93 | 564 | WritePxAnimation(playerScore,false,true); |
DanGibbons | 5:2d439ccefc7d | 565 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 566 | wait_ms(50); |
DanGibbons | 5:2d439ccefc7d | 567 | } |
DanGibbons | 5:2d439ccefc7d | 568 | |
DanGibbons | 9:f3f194982bb3 | 569 | DrainAnimation(true,false,true,true); // drain both scores away with the player score in random colours |
DanGibbons | 6:5e8e2645cd93 | 570 | |
DanGibbons | 6:5e8e2645cd93 | 571 | // reset robot score brightness |
DanGibbons | 6:5e8e2645cd93 | 572 | robotScoreLED.setII(0xB0); |
DanGibbons | 6:5e8e2645cd93 | 573 | robotScoreLED.useII(WS2812::GLOBAL); |
DanGibbons | 5:2d439ccefc7d | 574 | |
DanGibbons | 4:2e80bd814f57 | 575 | } else { |
DanGibbons | 4:2e80bd814f57 | 576 | |
DanGibbons | 6:5e8e2645cd93 | 577 | // dim brightness of the player score because they lost |
DanGibbons | 6:5e8e2645cd93 | 578 | playerScoreLED.setII(0x20); |
DanGibbons | 6:5e8e2645cd93 | 579 | playerScoreLED.useII(WS2812::GLOBAL); |
DanGibbons | 6:5e8e2645cd93 | 580 | playerScoreLED.write(playerScorePx.getBuf()); // rewrite buffer to change brightness |
DanGibbons | 6:5e8e2645cd93 | 581 | |
DanGibbons | 6:5e8e2645cd93 | 582 | for (int i = 0; i < 80; i++) { // flash robot score with changing random colours |
DanGibbons | 6:5e8e2645cd93 | 583 | WritePxAnimation(robotScore,true,true); |
DanGibbons | 5:2d439ccefc7d | 584 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 585 | wait_ms(50); |
DanGibbons | 5:2d439ccefc7d | 586 | } |
DanGibbons | 4:2e80bd814f57 | 587 | |
DanGibbons | 9:f3f194982bb3 | 588 | DrainAnimation(true,true,true,false); // drain both scores away with the robot score in random colours |
DanGibbons | 6:5e8e2645cd93 | 589 | |
DanGibbons | 6:5e8e2645cd93 | 590 | // reset player score brightness |
DanGibbons | 6:5e8e2645cd93 | 591 | playerScoreLED.setII(0xB0); |
DanGibbons | 6:5e8e2645cd93 | 592 | playerScoreLED.useII(WS2812::GLOBAL); |
benswindell | 0:f2b739e846ae | 593 | } |
DanGibbons | 4:2e80bd814f57 | 594 | |
DanGibbons | 5:2d439ccefc7d | 595 | wait(3); |
DanGibbons | 5:2d439ccefc7d | 596 | |
DanGibbons | 4:2e80bd814f57 | 597 | } |
DanGibbons | 4:2e80bd814f57 | 598 | |
DanGibbons | 9:f3f194982bb3 | 599 | // LEDs snake in a figure of 8 pattern in a group of 10 |
DanGibbons | 9:f3f194982bb3 | 600 | void FigureOf8Animation(bool robot, bool robotColour, bool player, bool playerColour, int numberOfRepititions) |
DanGibbons | 9:f3f194982bb3 | 601 | { |
DanGibbons | 9:f3f194982bb3 | 602 | for (int loops = 0; loops < numberOfRepititions; loops++) { |
DanGibbons | 6:5e8e2645cd93 | 603 | |
DanGibbons | 9:f3f194982bb3 | 604 | for (int i = 0; i < 9; i++) { // loop for LED snake to separate from centre of segment A |
DanGibbons | 9:f3f194982bb3 | 605 | |
DanGibbons | 9:f3f194982bb3 | 606 | mainArray[0][9+i] = 1; |
DanGibbons | 9:f3f194982bb3 | 607 | mainArray[1][8-i] = 1; |
DanGibbons | 9:f3f194982bb3 | 608 | if (i < 9) { |
DanGibbons | 9:f3f194982bb3 | 609 | mainArray[0][i] = 0; |
DanGibbons | 9:f3f194982bb3 | 610 | mainArray[1][17-i] = 0; |
DanGibbons | 9:f3f194982bb3 | 611 | } |
DanGibbons | 9:f3f194982bb3 | 612 | wait_ms(10); |
DanGibbons | 9:f3f194982bb3 | 613 | |
DanGibbons | 9:f3f194982bb3 | 614 | if (player == true) { |
DanGibbons | 9:f3f194982bb3 | 615 | WritePxAnimation(0,false,playerColour); |
DanGibbons | 9:f3f194982bb3 | 616 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 9:f3f194982bb3 | 617 | } |
DanGibbons | 9:f3f194982bb3 | 618 | if (robot == true) { |
DanGibbons | 9:f3f194982bb3 | 619 | WritePxAnimation(1,true,robotColour); |
DanGibbons | 9:f3f194982bb3 | 620 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 9:f3f194982bb3 | 621 | } |
DanGibbons | 9:f3f194982bb3 | 622 | } |
DanGibbons | 9:f3f194982bb3 | 623 | |
DanGibbons | 9:f3f194982bb3 | 624 | for (int i = 0; i < 17; i++) { // loop for LED snake to go down segments B and F |
DanGibbons | 9:f3f194982bb3 | 625 | |
DanGibbons | 9:f3f194982bb3 | 626 | mainArray[0][18+i] = 1; |
DanGibbons | 9:f3f194982bb3 | 627 | mainArray[1][103-i] = 1; |
DanGibbons | 9:f3f194982bb3 | 628 | mainArray[0][9+i] = 0; |
DanGibbons | 9:f3f194982bb3 | 629 | if (i < 9) { |
DanGibbons | 9:f3f194982bb3 | 630 | mainArray[1][8-i] = 0; |
DanGibbons | 9:f3f194982bb3 | 631 | } else { |
DanGibbons | 9:f3f194982bb3 | 632 | mainArray[1][112-i] = 0; |
DanGibbons | 9:f3f194982bb3 | 633 | } |
DanGibbons | 9:f3f194982bb3 | 634 | wait_ms(10); |
DanGibbons | 9:f3f194982bb3 | 635 | |
DanGibbons | 9:f3f194982bb3 | 636 | if (player == true) { |
DanGibbons | 9:f3f194982bb3 | 637 | WritePxAnimation(0,false,playerColour); |
DanGibbons | 9:f3f194982bb3 | 638 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 9:f3f194982bb3 | 639 | } |
DanGibbons | 9:f3f194982bb3 | 640 | if (robot == true) { |
DanGibbons | 9:f3f194982bb3 | 641 | WritePxAnimation(1,true,robotColour); |
DanGibbons | 9:f3f194982bb3 | 642 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 9:f3f194982bb3 | 643 | } |
DanGibbons | 9:f3f194982bb3 | 644 | } |
DanGibbons | 9:f3f194982bb3 | 645 | |
DanGibbons | 9:f3f194982bb3 | 646 | for (int i = 0; i < 18; i++) { // loop for LED snake to pass through segment G |
DanGibbons | 9:f3f194982bb3 | 647 | |
DanGibbons | 9:f3f194982bb3 | 648 | mainArray[0][121-i] = 1; |
DanGibbons | 9:f3f194982bb3 | 649 | mainArray[1][104+i] = 1; |
DanGibbons | 9:f3f194982bb3 | 650 | if (i < 9) { |
DanGibbons | 9:f3f194982bb3 | 651 | mainArray[0][26+i] = 0; |
DanGibbons | 9:f3f194982bb3 | 652 | mainArray[1][95-i] = 0; |
DanGibbons | 9:f3f194982bb3 | 653 | } else { |
DanGibbons | 9:f3f194982bb3 | 654 | mainArray[0][130-i] = 0; |
DanGibbons | 9:f3f194982bb3 | 655 | mainArray[1][95+i] = 0; |
DanGibbons | 9:f3f194982bb3 | 656 | } |
DanGibbons | 9:f3f194982bb3 | 657 | wait_ms(10); |
DanGibbons | 9:f3f194982bb3 | 658 | |
DanGibbons | 9:f3f194982bb3 | 659 | if (player == true) { |
DanGibbons | 9:f3f194982bb3 | 660 | WritePxAnimation(0,false,playerColour); |
DanGibbons | 9:f3f194982bb3 | 661 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 9:f3f194982bb3 | 662 | } |
DanGibbons | 9:f3f194982bb3 | 663 | if (robot == true) { |
DanGibbons | 9:f3f194982bb3 | 664 | WritePxAnimation(1,true,robotColour); |
DanGibbons | 9:f3f194982bb3 | 665 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 9:f3f194982bb3 | 666 | } |
DanGibbons | 9:f3f194982bb3 | 667 | } |
DanGibbons | 9:f3f194982bb3 | 668 | |
DanGibbons | 9:f3f194982bb3 | 669 | for (int i = 0; i < 17; i++) { // loop for LED snake to pass down through segments E and C |
DanGibbons | 9:f3f194982bb3 | 670 | |
DanGibbons | 9:f3f194982bb3 | 671 | mainArray[0][86-i] = 1; |
DanGibbons | 9:f3f194982bb3 | 672 | mainArray[1][35+i] = 1; |
DanGibbons | 9:f3f194982bb3 | 673 | if (i < 9) { |
DanGibbons | 9:f3f194982bb3 | 674 | mainArray[0][112-i] = 0; |
DanGibbons | 9:f3f194982bb3 | 675 | mainArray[1][113+i] = 0; |
DanGibbons | 9:f3f194982bb3 | 676 | } else { |
DanGibbons | 9:f3f194982bb3 | 677 | mainArray[0][95-i] = 0; |
DanGibbons | 9:f3f194982bb3 | 678 | mainArray[1][26+i] = 0; |
DanGibbons | 9:f3f194982bb3 | 679 | } |
DanGibbons | 9:f3f194982bb3 | 680 | wait_ms(10); |
DanGibbons | 9:f3f194982bb3 | 681 | |
DanGibbons | 9:f3f194982bb3 | 682 | if (player == true) { |
DanGibbons | 9:f3f194982bb3 | 683 | WritePxAnimation(0,false,playerColour); |
DanGibbons | 9:f3f194982bb3 | 684 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 9:f3f194982bb3 | 685 | } |
DanGibbons | 9:f3f194982bb3 | 686 | if (robot == true) { |
DanGibbons | 9:f3f194982bb3 | 687 | WritePxAnimation(1,true,robotColour); |
DanGibbons | 9:f3f194982bb3 | 688 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 9:f3f194982bb3 | 689 | } |
DanGibbons | 9:f3f194982bb3 | 690 | } |
DanGibbons | 9:f3f194982bb3 | 691 | |
DanGibbons | 9:f3f194982bb3 | 692 | for (int i = 0; i < 35; i++) { // loop for LED snake to pass through segments D and E AND D and C |
DanGibbons | 9:f3f194982bb3 | 693 | |
DanGibbons | 9:f3f194982bb3 | 694 | mainArray[0][69-i] = 1; |
DanGibbons | 9:f3f194982bb3 | 695 | mainArray[1][52+i] = 1; |
DanGibbons | 9:f3f194982bb3 | 696 | mainArray[0][80-i] = 0; |
DanGibbons | 9:f3f194982bb3 | 697 | mainArray[1][43+i] = 0; |
DanGibbons | 9:f3f194982bb3 | 698 | |
DanGibbons | 9:f3f194982bb3 | 699 | wait_ms(10); |
DanGibbons | 9:f3f194982bb3 | 700 | |
DanGibbons | 9:f3f194982bb3 | 701 | if (player == true) { |
DanGibbons | 9:f3f194982bb3 | 702 | WritePxAnimation(0,false,playerColour); |
DanGibbons | 9:f3f194982bb3 | 703 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 9:f3f194982bb3 | 704 | } |
DanGibbons | 9:f3f194982bb3 | 705 | if (robot == true) { |
DanGibbons | 9:f3f194982bb3 | 706 | WritePxAnimation(1,true,robotColour); |
DanGibbons | 9:f3f194982bb3 | 707 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 9:f3f194982bb3 | 708 | } |
DanGibbons | 9:f3f194982bb3 | 709 | } |
DanGibbons | 9:f3f194982bb3 | 710 | |
DanGibbons | 9:f3f194982bb3 | 711 | for (int i = 0; i < 18; i++) { // loop for LED snake to pass through segment G |
DanGibbons | 9:f3f194982bb3 | 712 | |
DanGibbons | 9:f3f194982bb3 | 713 | mainArray[0][121-i] = 1; |
DanGibbons | 9:f3f194982bb3 | 714 | mainArray[1][104+i] = 1; |
DanGibbons | 9:f3f194982bb3 | 715 | if (i < 9) { //////////////// |
DanGibbons | 9:f3f194982bb3 | 716 | mainArray[0][45-i] = 0; |
DanGibbons | 9:f3f194982bb3 | 717 | mainArray[1][78+i] = 0; |
DanGibbons | 9:f3f194982bb3 | 718 | if (i == 8) { |
DanGibbons | 9:f3f194982bb3 | 719 | mainArray[0][36] = 0; |
DanGibbons | 9:f3f194982bb3 | 720 | mainArray[0][35] = 0; |
DanGibbons | 9:f3f194982bb3 | 721 | } |
DanGibbons | 9:f3f194982bb3 | 722 | } else { |
DanGibbons | 9:f3f194982bb3 | 723 | mainArray[0][130-i] = 0; |
DanGibbons | 9:f3f194982bb3 | 724 | mainArray[1][95+i] = 0; |
DanGibbons | 9:f3f194982bb3 | 725 | } |
DanGibbons | 9:f3f194982bb3 | 726 | wait_ms(10); |
DanGibbons | 9:f3f194982bb3 | 727 | |
DanGibbons | 9:f3f194982bb3 | 728 | if (player == true) { |
DanGibbons | 9:f3f194982bb3 | 729 | WritePxAnimation(0,false,playerColour); |
DanGibbons | 9:f3f194982bb3 | 730 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 9:f3f194982bb3 | 731 | } |
DanGibbons | 9:f3f194982bb3 | 732 | if (robot == true) { |
DanGibbons | 9:f3f194982bb3 | 733 | WritePxAnimation(1,true,robotColour); |
DanGibbons | 9:f3f194982bb3 | 734 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 9:f3f194982bb3 | 735 | } |
DanGibbons | 9:f3f194982bb3 | 736 | } |
DanGibbons | 9:f3f194982bb3 | 737 | |
DanGibbons | 9:f3f194982bb3 | 738 | for (int i = 0; i < 17; i++) { // loop for LED snake to go up segments B and F |
DanGibbons | 9:f3f194982bb3 | 739 | |
DanGibbons | 9:f3f194982bb3 | 740 | mainArray[0][87+i] = 1; |
DanGibbons | 9:f3f194982bb3 | 741 | mainArray[1][34-i] = 1; |
DanGibbons | 9:f3f194982bb3 | 742 | if (i < 9) { |
DanGibbons | 9:f3f194982bb3 | 743 | mainArray[0][112-i] = 0; |
DanGibbons | 9:f3f194982bb3 | 744 | mainArray[1][113+i] = 0; |
DanGibbons | 9:f3f194982bb3 | 745 | } else { |
DanGibbons | 9:f3f194982bb3 | 746 | mainArray[0][78+i] = 0; |
DanGibbons | 9:f3f194982bb3 | 747 | mainArray[1][43-i] = 0; |
DanGibbons | 9:f3f194982bb3 | 748 | } |
DanGibbons | 9:f3f194982bb3 | 749 | wait_ms(10); |
DanGibbons | 9:f3f194982bb3 | 750 | |
DanGibbons | 9:f3f194982bb3 | 751 | if (player == true) { |
DanGibbons | 9:f3f194982bb3 | 752 | WritePxAnimation(0,false,playerColour); |
DanGibbons | 9:f3f194982bb3 | 753 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 9:f3f194982bb3 | 754 | } |
DanGibbons | 9:f3f194982bb3 | 755 | if (robot == true) { |
DanGibbons | 9:f3f194982bb3 | 756 | WritePxAnimation(1,true,robotColour); |
DanGibbons | 9:f3f194982bb3 | 757 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 9:f3f194982bb3 | 758 | } |
DanGibbons | 9:f3f194982bb3 | 759 | } |
DanGibbons | 9:f3f194982bb3 | 760 | |
DanGibbons | 9:f3f194982bb3 | 761 | for (int i = 0; i < 9; i++) { // loop for LED snake to pass through the centre of segment A |
DanGibbons | 9:f3f194982bb3 | 762 | |
DanGibbons | 9:f3f194982bb3 | 763 | mainArray[0][i] = 1; |
DanGibbons | 9:f3f194982bb3 | 764 | mainArray[1][17-i] = 1; |
DanGibbons | 9:f3f194982bb3 | 765 | if (i < 9) { |
DanGibbons | 9:f3f194982bb3 | 766 | mainArray[0][95+i] = 0; |
DanGibbons | 9:f3f194982bb3 | 767 | mainArray[1][26-i] = 0; |
DanGibbons | 9:f3f194982bb3 | 768 | } else { |
DanGibbons | 9:f3f194982bb3 | 769 | mainArray[0][i-9] = 0; |
DanGibbons | 9:f3f194982bb3 | 770 | mainArray[1][26-i] = 0; |
DanGibbons | 9:f3f194982bb3 | 771 | } |
DanGibbons | 9:f3f194982bb3 | 772 | wait_ms(10); |
DanGibbons | 9:f3f194982bb3 | 773 | |
DanGibbons | 9:f3f194982bb3 | 774 | if (player == true) { |
DanGibbons | 9:f3f194982bb3 | 775 | WritePxAnimation(0,false,playerColour); |
DanGibbons | 9:f3f194982bb3 | 776 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 9:f3f194982bb3 | 777 | } |
DanGibbons | 9:f3f194982bb3 | 778 | if (robot == true) { |
DanGibbons | 9:f3f194982bb3 | 779 | WritePxAnimation(1,true,robotColour); |
DanGibbons | 9:f3f194982bb3 | 780 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 9:f3f194982bb3 | 781 | } |
DanGibbons | 9:f3f194982bb3 | 782 | } |
DanGibbons | 9:f3f194982bb3 | 783 | |
DanGibbons | 9:f3f194982bb3 | 784 | |
DanGibbons | 9:f3f194982bb3 | 785 | } |
DanGibbons | 9:f3f194982bb3 | 786 | |
DanGibbons | 9:f3f194982bb3 | 787 | } |
DanGibbons | 9:f3f194982bb3 | 788 | |
DanGibbons | 9:f3f194982bb3 | 789 | // LEDs snake in a figure of 8 pattern in a group of 10 |
DanGibbons | 6:5e8e2645cd93 | 790 | void CircleAnimation(bool robot, bool robotColour, bool player, bool playerColour, int numberOfRepititions) |
DanGibbons | 7:dc6f1f105c52 | 791 | { |
DanGibbons | 6:5e8e2645cd93 | 792 | for (int loops = 0; loops < numberOfRepititions; loops++) { |
DanGibbons | 6:5e8e2645cd93 | 793 | |
DanGibbons | 7:dc6f1f105c52 | 794 | for (int i = 9; i < 115; i++) { // loop to set LEDs around the circle from start of segment A to end of Segment F |
DanGibbons | 5:2d439ccefc7d | 795 | |
DanGibbons | 8:66dac2e00cce | 796 | if (i < 104) { |
DanGibbons | 6:5e8e2645cd93 | 797 | mainArray[0][i] = 1; |
DanGibbons | 8:66dac2e00cce | 798 | for (int j = 0; j < i-10; j++) { // Loop to clear previously set LEDs so that the chain that animates round the display is 10 LEDs long |
DanGibbons | 8:66dac2e00cce | 799 | mainArray[0][j] = 0; |
DanGibbons | 8:66dac2e00cce | 800 | } |
DanGibbons | 8:66dac2e00cce | 801 | } |
DanGibbons | 8:66dac2e00cce | 802 | if (i > 103) { |
DanGibbons | 8:66dac2e00cce | 803 | mainArray[0][i-104] = 1; |
DanGibbons | 8:66dac2e00cce | 804 | for (int j = 90; j < i-10; j++) { // Loop to clear previously set LEDs so that the chain that animates round the display is 10 LEDs long |
DanGibbons | 7:dc6f1f105c52 | 805 | mainArray[0][j] = 0; |
DanGibbons | 7:dc6f1f105c52 | 806 | } |
DanGibbons | 6:5e8e2645cd93 | 807 | } |
DanGibbons | 8:66dac2e00cce | 808 | if (i < 19) { |
DanGibbons | 8:66dac2e00cce | 809 | mainArray[1][18-i] = 1; |
DanGibbons | 8:66dac2e00cce | 810 | for (int j = 17; j > 25-i; j--) { // Loop to clear previously set LEDs so that the chain that animates round the display is 10 LEDs long |
DanGibbons | 8:66dac2e00cce | 811 | mainArray[1][j] = 0; |
DanGibbons | 8:66dac2e00cce | 812 | } |
DanGibbons | 8:66dac2e00cce | 813 | } |
DanGibbons | 8:66dac2e00cce | 814 | if (i > 18) { |
DanGibbons | 8:66dac2e00cce | 815 | |
DanGibbons | 8:66dac2e00cce | 816 | mainArray[1][122-i] = 1; |
DanGibbons | 8:66dac2e00cce | 817 | |
DanGibbons | 8:66dac2e00cce | 818 | if (i < 29) { |
DanGibbons | 8:66dac2e00cce | 819 | for (int j = 9; j > 27-i; j--) { // Loop to clear previously set LEDs so that the chain that animates round the display is 10 LEDs long |
DanGibbons | 8:66dac2e00cce | 820 | mainArray[1][j] = 0; |
DanGibbons | 8:66dac2e00cce | 821 | } |
DanGibbons | 8:66dac2e00cce | 822 | } |
DanGibbons | 8:66dac2e00cce | 823 | if (i > 28) { |
DanGibbons | 8:66dac2e00cce | 824 | for (int j = 103; j > 131-i; j--) { // Loop to clear previously set LEDs so that the chain that animates round the display is 10 LEDs long |
DanGibbons | 8:66dac2e00cce | 825 | mainArray[1][j] = 0; |
DanGibbons | 8:66dac2e00cce | 826 | } |
DanGibbons | 7:dc6f1f105c52 | 827 | } |
DanGibbons | 6:5e8e2645cd93 | 828 | } |
DanGibbons | 7:dc6f1f105c52 | 829 | |
DanGibbons | 6:5e8e2645cd93 | 830 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 831 | |
DanGibbons | 6:5e8e2645cd93 | 832 | if (player == true) { |
DanGibbons | 7:dc6f1f105c52 | 833 | WritePxAnimation(0,false,playerColour); |
DanGibbons | 5:2d439ccefc7d | 834 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 835 | } |
DanGibbons | 6:5e8e2645cd93 | 836 | if (robot == true) { |
DanGibbons | 8:66dac2e00cce | 837 | WritePxAnimation(1,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 838 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 839 | } |
DanGibbons | 8:66dac2e00cce | 840 | |
DanGibbons | 6:5e8e2645cd93 | 841 | } |
DanGibbons | 8:66dac2e00cce | 842 | |
DanGibbons | 6:5e8e2645cd93 | 843 | } |
DanGibbons | 6:5e8e2645cd93 | 844 | |
DanGibbons | 5:2d439ccefc7d | 845 | } |
DanGibbons | 5:2d439ccefc7d | 846 | |
DanGibbons | 5:2d439ccefc7d | 847 | // animation that drains the display from the top segment A to the bottom segment D |
DanGibbons | 9:f3f194982bb3 | 848 | void DrainAnimation(bool robot, bool robotColour,bool player, bool playerColour) |
DanGibbons | 5:2d439ccefc7d | 849 | { |
DanGibbons | 8:66dac2e00cce | 850 | SetNumberPatterns(); |
DanGibbons | 8:66dac2e00cce | 851 | |
DanGibbons | 9:f3f194982bb3 | 852 | for (int i = 0; i < 10; i++) { // drain A from the centre of the segment |
DanGibbons | 6:5e8e2645cd93 | 853 | mainArray[robotScore][9+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 854 | mainArray[robotScore][9-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 855 | mainArray[playerScore][9+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 856 | mainArray[playerScore][9-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 857 | wait_ms(30); |
DanGibbons | 6:5e8e2645cd93 | 858 | if (player == true){ |
DanGibbons | 6:5e8e2645cd93 | 859 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 5:2d439ccefc7d | 860 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 861 | } |
DanGibbons | 6:5e8e2645cd93 | 862 | if (robot == true) { |
DanGibbons | 6:5e8e2645cd93 | 863 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 864 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 865 | } |
DanGibbons | 6:5e8e2645cd93 | 866 | } |
DanGibbons | 9:f3f194982bb3 | 867 | for (int i = 0; i < 18; i++) { // drain B and F downwards |
DanGibbons | 6:5e8e2645cd93 | 868 | mainArray[robotScore][18+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 869 | mainArray[robotScore][103-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 870 | mainArray[playerScore][18+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 871 | mainArray[playerScore][103-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 872 | wait_ms(30); |
DanGibbons | 6:5e8e2645cd93 | 873 | if (player == true){ |
DanGibbons | 6:5e8e2645cd93 | 874 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 5:2d439ccefc7d | 875 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 876 | } |
DanGibbons | 6:5e8e2645cd93 | 877 | if (robot == true) { |
DanGibbons | 6:5e8e2645cd93 | 878 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 879 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 880 | } |
DanGibbons | 6:5e8e2645cd93 | 881 | } |
DanGibbons | 6:5e8e2645cd93 | 882 | if (robotScore != 0 | playerScore != 0) { // endgame - at least one score is three |
DanGibbons | 6:5e8e2645cd93 | 883 | |
DanGibbons | 9:f3f194982bb3 | 884 | for (int i = 0; i < 18; i++) { // drain G across |
DanGibbons | 6:5e8e2645cd93 | 885 | mainArray[robotScore][104+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 886 | mainArray[playerScore][104+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 887 | if (player == true) { |
DanGibbons | 6:5e8e2645cd93 | 888 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 889 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 890 | } |
DanGibbons | 6:5e8e2645cd93 | 891 | if (robot == true) { |
DanGibbons | 6:5e8e2645cd93 | 892 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 893 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 894 | } |
DanGibbons | 6:5e8e2645cd93 | 895 | } |
DanGibbons | 6:5e8e2645cd93 | 896 | } else { // start of game - both scores are 0 |
DanGibbons | 9:f3f194982bb3 | 897 | for (int i = 0; i < 18; i++) { // instantly delete G |
DanGibbons | 5:2d439ccefc7d | 898 | mainArray[robotScore][104+i] = 0; |
DanGibbons | 5:2d439ccefc7d | 899 | mainArray[playerScore][104+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 900 | } |
DanGibbons | 6:5e8e2645cd93 | 901 | if (player == true) { |
DanGibbons | 6:5e8e2645cd93 | 902 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 903 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 904 | } |
DanGibbons | 6:5e8e2645cd93 | 905 | if (robot == true) { |
DanGibbons | 6:5e8e2645cd93 | 906 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 907 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 908 | } |
DanGibbons | 6:5e8e2645cd93 | 909 | } |
DanGibbons | 6:5e8e2645cd93 | 910 | |
DanGibbons | 9:f3f194982bb3 | 911 | for (int i = 0; i < 18; i++) { // drain C and E downwards |
DanGibbons | 6:5e8e2645cd93 | 912 | mainArray[robotScore][35+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 913 | mainArray[robotScore][86-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 914 | mainArray[playerScore][35+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 915 | mainArray[playerScore][86-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 916 | wait_ms(30); |
DanGibbons | 6:5e8e2645cd93 | 917 | if (player == true){ |
DanGibbons | 6:5e8e2645cd93 | 918 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 919 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 920 | } |
DanGibbons | 6:5e8e2645cd93 | 921 | if (robot == true) { |
DanGibbons | 6:5e8e2645cd93 | 922 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 5:2d439ccefc7d | 923 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 924 | } |
DanGibbons | 6:5e8e2645cd93 | 925 | } |
DanGibbons | 9:f3f194982bb3 | 926 | for (int i = 0; i < 10; i++) { // drain D from edges to centre |
DanGibbons | 6:5e8e2645cd93 | 927 | mainArray[robotScore][52+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 928 | mainArray[robotScore][70-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 929 | mainArray[playerScore][52+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 930 | mainArray[playerScore][70-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 931 | wait_ms(30); |
DanGibbons | 6:5e8e2645cd93 | 932 | if (player == true){ |
DanGibbons | 6:5e8e2645cd93 | 933 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 934 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 935 | } |
DanGibbons | 6:5e8e2645cd93 | 936 | if (robot == true) { |
DanGibbons | 6:5e8e2645cd93 | 937 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 938 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 939 | } |
DanGibbons | 6:5e8e2645cd93 | 940 | } |
DanGibbons | 6:5e8e2645cd93 | 941 | |
DanGibbons | 6:5e8e2645cd93 | 942 | |
DanGibbons | 8:66dac2e00cce | 943 | memset(mainArray, 0, sizeof mainArray); |
DanGibbons | 6:5e8e2645cd93 | 944 | |
DanGibbons | 6:5e8e2645cd93 | 945 | } |
DanGibbons | 6:5e8e2645cd93 | 946 | |
DanGibbons | 6:5e8e2645cd93 | 947 | void ZeroInAnimation(bool robot, bool robotColour, bool player, bool playerColour) |
DanGibbons | 6:5e8e2645cd93 | 948 | { |
DanGibbons | 6:5e8e2645cd93 | 949 | memset(mainArray, 0, sizeof mainArray); |
DanGibbons | 6:5e8e2645cd93 | 950 | |
DanGibbons | 6:5e8e2645cd93 | 951 | if (player == true && robot == true) { |
DanGibbons | 6:5e8e2645cd93 | 952 | |
DanGibbons | 9:f3f194982bb3 | 953 | for (int i = 0; i < 10; i++) { // write A from centre |
DanGibbons | 6:5e8e2645cd93 | 954 | mainArray[0][9+i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 955 | mainArray[0][9-i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 956 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 957 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 958 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 959 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 960 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 961 | } |
DanGibbons | 9:f3f194982bb3 | 962 | for (int i = 0; i < 18; i++) { // write B and F downwards |
DanGibbons | 6:5e8e2645cd93 | 963 | mainArray[0][18+i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 964 | mainArray[0][103-i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 965 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 966 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 967 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 968 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 969 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 970 | } |
DanGibbons | 9:f3f194982bb3 | 971 | for (int i = 0; i < 18; i++) { // write C and E downwards |
DanGibbons | 6:5e8e2645cd93 | 972 | mainArray[0][35+i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 973 | mainArray[0][86-i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 974 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 975 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 5:2d439ccefc7d | 976 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 977 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 5:2d439ccefc7d | 978 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 979 | } |
DanGibbons | 9:f3f194982bb3 | 980 | for (int i = 0; i < 10; i++) { // write D from edges to centre |
DanGibbons | 6:5e8e2645cd93 | 981 | mainArray[0][52+i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 982 | mainArray[0][70-i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 983 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 984 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 985 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 986 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 987 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 988 | } |
DanGibbons | 6:5e8e2645cd93 | 989 | |
DanGibbons | 6:5e8e2645cd93 | 990 | } |
DanGibbons | 6:5e8e2645cd93 | 991 | |
DanGibbons | 6:5e8e2645cd93 | 992 | if (player == true && robot == false) { |
DanGibbons | 6:5e8e2645cd93 | 993 | |
DanGibbons | 6:5e8e2645cd93 | 994 | for (int i = 0; i < 10; i++) { // A |
DanGibbons | 6:5e8e2645cd93 | 995 | mainArray[0][9+i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 996 | mainArray[0][9-i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 997 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 998 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 999 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1000 | } |
DanGibbons | 6:5e8e2645cd93 | 1001 | for (int i = 0; i < 18; i++) { // B and F |
DanGibbons | 6:5e8e2645cd93 | 1002 | mainArray[0][18+i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1003 | mainArray[0][103-i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1004 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1005 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1006 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1007 | } |
DanGibbons | 6:5e8e2645cd93 | 1008 | for (int i = 0; i < 18; i++) { // G |
DanGibbons | 6:5e8e2645cd93 | 1009 | mainArray[0][104+i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1010 | } |
DanGibbons | 6:5e8e2645cd93 | 1011 | |
DanGibbons | 6:5e8e2645cd93 | 1012 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1013 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1014 | |
DanGibbons | 6:5e8e2645cd93 | 1015 | for (int i = 0; i < 18; i++) { // C and E |
DanGibbons | 6:5e8e2645cd93 | 1016 | mainArray[0][35+i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1017 | mainArray[0][86-i] = 1; |
DanGibbons | 5:2d439ccefc7d | 1018 | wait_ms(30); |
DanGibbons | 6:5e8e2645cd93 | 1019 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1020 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1021 | } |
DanGibbons | 6:5e8e2645cd93 | 1022 | for (int i = 0; i < 10; i++) { // D |
DanGibbons | 6:5e8e2645cd93 | 1023 | mainArray[0][52+i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1024 | mainArray[0][70-i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1025 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1026 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 5:2d439ccefc7d | 1027 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1028 | } |
DanGibbons | 6:5e8e2645cd93 | 1029 | |
DanGibbons | 6:5e8e2645cd93 | 1030 | } |
DanGibbons | 6:5e8e2645cd93 | 1031 | |
DanGibbons | 6:5e8e2645cd93 | 1032 | if (player == false && robot == true) { |
DanGibbons | 6:5e8e2645cd93 | 1033 | |
DanGibbons | 6:5e8e2645cd93 | 1034 | for (int i = 0; i < 10; i++) { // A |
DanGibbons | 6:5e8e2645cd93 | 1035 | mainArray[0][9+i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1036 | mainArray[0][9-i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1037 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1038 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1039 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1040 | } |
DanGibbons | 6:5e8e2645cd93 | 1041 | for (int i = 0; i < 18; i++) { // B and F |
DanGibbons | 6:5e8e2645cd93 | 1042 | mainArray[0][18+i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1043 | mainArray[0][103-i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1044 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1045 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 5:2d439ccefc7d | 1046 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1047 | } |
DanGibbons | 6:5e8e2645cd93 | 1048 | for (int i = 0; i < 18; i++) { // G |
DanGibbons | 6:5e8e2645cd93 | 1049 | mainArray[0][104+i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1050 | } |
DanGibbons | 6:5e8e2645cd93 | 1051 | |
DanGibbons | 6:5e8e2645cd93 | 1052 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1053 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1054 | |
DanGibbons | 6:5e8e2645cd93 | 1055 | for (int i = 0; i < 18; i++) { // C and E |
DanGibbons | 6:5e8e2645cd93 | 1056 | mainArray[0][35+i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1057 | mainArray[0][86-i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1058 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1059 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1060 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1061 | } |
DanGibbons | 6:5e8e2645cd93 | 1062 | for (int i = 0; i < 10; i++) { // D |
DanGibbons | 6:5e8e2645cd93 | 1063 | mainArray[0][52+i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1064 | mainArray[0][70-i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1065 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1066 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1067 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1068 | } |
DanGibbons | 6:5e8e2645cd93 | 1069 | |
DanGibbons | 9:f3f194982bb3 | 1070 | } |
DanGibbons | 6:5e8e2645cd93 | 1071 | |
DanGibbons | 6:5e8e2645cd93 | 1072 | } |
DanGibbons | 6:5e8e2645cd93 | 1073 | |
DanGibbons | 6:5e8e2645cd93 | 1074 | void ZeroOutAnimation(bool robot, bool robotColour, bool player, bool playerColour) |
DanGibbons | 6:5e8e2645cd93 | 1075 | { |
DanGibbons | 6:5e8e2645cd93 | 1076 | if (player == true && robot == true) { |
DanGibbons | 6:5e8e2645cd93 | 1077 | |
DanGibbons | 5:2d439ccefc7d | 1078 | for (int i = 0; i < 10; i++) { // A |
DanGibbons | 6:5e8e2645cd93 | 1079 | mainArray[0][9+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1080 | mainArray[0][9-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1081 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1082 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1083 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1084 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1085 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1086 | } |
DanGibbons | 6:5e8e2645cd93 | 1087 | for (int i = 0; i < 18; i++) { // B and F |
DanGibbons | 6:5e8e2645cd93 | 1088 | mainArray[0][18+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1089 | mainArray[0][103-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1090 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1091 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1092 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1093 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1094 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1095 | } |
DanGibbons | 6:5e8e2645cd93 | 1096 | for (int i = 0; i < 18; i++) { // G |
DanGibbons | 6:5e8e2645cd93 | 1097 | mainArray[0][104+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1098 | } |
DanGibbons | 6:5e8e2645cd93 | 1099 | |
DanGibbons | 6:5e8e2645cd93 | 1100 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1101 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1102 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1103 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1104 | |
DanGibbons | 6:5e8e2645cd93 | 1105 | for (int i = 0; i < 18; i++) { // C and E |
DanGibbons | 6:5e8e2645cd93 | 1106 | mainArray[0][35+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1107 | mainArray[0][86-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1108 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1109 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1110 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1111 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1112 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1113 | } |
DanGibbons | 6:5e8e2645cd93 | 1114 | for (int i = 0; i < 10; i++) { // D |
DanGibbons | 6:5e8e2645cd93 | 1115 | mainArray[0][52+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1116 | mainArray[0][70-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1117 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1118 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1119 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1120 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1121 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1122 | } |
DanGibbons | 6:5e8e2645cd93 | 1123 | |
DanGibbons | 6:5e8e2645cd93 | 1124 | } |
DanGibbons | 6:5e8e2645cd93 | 1125 | |
DanGibbons | 6:5e8e2645cd93 | 1126 | if (player == true && robot == false) { |
DanGibbons | 6:5e8e2645cd93 | 1127 | |
DanGibbons | 6:5e8e2645cd93 | 1128 | for (int i = 0; i < 10; i++) { // A |
DanGibbons | 6:5e8e2645cd93 | 1129 | mainArray[0][9+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1130 | mainArray[0][9-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1131 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1132 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 5:2d439ccefc7d | 1133 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 1134 | } |
DanGibbons | 5:2d439ccefc7d | 1135 | for (int i = 0; i < 18; i++) { // B and F |
DanGibbons | 6:5e8e2645cd93 | 1136 | mainArray[0][18+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1137 | mainArray[0][103-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1138 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1139 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 5:2d439ccefc7d | 1140 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1141 | } |
DanGibbons | 5:2d439ccefc7d | 1142 | for (int i = 0; i < 18; i++) { // G |
DanGibbons | 6:5e8e2645cd93 | 1143 | mainArray[0][104+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1144 | } |
DanGibbons | 6:5e8e2645cd93 | 1145 | |
DanGibbons | 6:5e8e2645cd93 | 1146 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1147 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1148 | |
DanGibbons | 5:2d439ccefc7d | 1149 | for (int i = 0; i < 18; i++) { // C and E |
DanGibbons | 6:5e8e2645cd93 | 1150 | mainArray[0][35+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1151 | mainArray[0][86-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1152 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1153 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 5:2d439ccefc7d | 1154 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1155 | } |
DanGibbons | 5:2d439ccefc7d | 1156 | for (int i = 0; i < 10; i++) { // D |
DanGibbons | 6:5e8e2645cd93 | 1157 | mainArray[0][52+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1158 | mainArray[0][70-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1159 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1160 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 5:2d439ccefc7d | 1161 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1162 | } |
DanGibbons | 6:5e8e2645cd93 | 1163 | |
DanGibbons | 6:5e8e2645cd93 | 1164 | } |
DanGibbons | 6:5e8e2645cd93 | 1165 | |
DanGibbons | 5:2d439ccefc7d | 1166 | if (player == false && robot == true) { |
DanGibbons | 6:5e8e2645cd93 | 1167 | |
DanGibbons | 5:2d439ccefc7d | 1168 | for (int i = 0; i < 10; i++) { // A |
DanGibbons | 6:5e8e2645cd93 | 1169 | mainArray[0][9+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1170 | mainArray[0][9-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1171 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1172 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 5:2d439ccefc7d | 1173 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 1174 | } |
DanGibbons | 5:2d439ccefc7d | 1175 | for (int i = 0; i < 18; i++) { // B and F |
DanGibbons | 6:5e8e2645cd93 | 1176 | mainArray[0][18+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1177 | mainArray[0][103-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1178 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1179 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 5:2d439ccefc7d | 1180 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1181 | } |
DanGibbons | 5:2d439ccefc7d | 1182 | for (int i = 0; i < 18; i++) { // G |
DanGibbons | 6:5e8e2645cd93 | 1183 | mainArray[0][104+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1184 | } |
DanGibbons | 6:5e8e2645cd93 | 1185 | |
DanGibbons | 6:5e8e2645cd93 | 1186 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1187 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1188 | |
DanGibbons | 5:2d439ccefc7d | 1189 | for (int i = 0; i < 18; i++) { // C and E |
DanGibbons | 6:5e8e2645cd93 | 1190 | mainArray[0][35+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1191 | mainArray[0][86-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1192 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1193 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 5:2d439ccefc7d | 1194 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1195 | } |
DanGibbons | 5:2d439ccefc7d | 1196 | for (int i = 0; i < 10; i++) { // D |
DanGibbons | 6:5e8e2645cd93 | 1197 | mainArray[0][52+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1198 | mainArray[0][70-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1199 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1200 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1201 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1202 | } |
DanGibbons | 6:5e8e2645cd93 | 1203 | |
DanGibbons | 9:f3f194982bb3 | 1204 | } |
DanGibbons | 6:5e8e2645cd93 | 1205 | |
DanGibbons | 6:5e8e2645cd93 | 1206 | } |
DanGibbons | 6:5e8e2645cd93 | 1207 | |
DanGibbons | 6:5e8e2645cd93 | 1208 | void OneInAnimation(bool robot, bool robotColour,bool player, bool playerColour) |
DanGibbons | 6:5e8e2645cd93 | 1209 | { |
DanGibbons | 6:5e8e2645cd93 | 1210 | memset(mainArray, 0, sizeof mainArray); |
DanGibbons | 6:5e8e2645cd93 | 1211 | |
DanGibbons | 6:5e8e2645cd93 | 1212 | if (player == true && robot == true) { |
DanGibbons | 6:5e8e2645cd93 | 1213 | |
DanGibbons | 6:5e8e2645cd93 | 1214 | for (int i = 51; i > 17; i--) { |
DanGibbons | 6:5e8e2645cd93 | 1215 | mainArray[1][i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1216 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1217 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1218 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1219 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1220 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1221 | } |
DanGibbons | 6:5e8e2645cd93 | 1222 | |
DanGibbons | 6:5e8e2645cd93 | 1223 | } |
DanGibbons | 6:5e8e2645cd93 | 1224 | |
DanGibbons | 6:5e8e2645cd93 | 1225 | if (player == true && robot == false) { |
DanGibbons | 6:5e8e2645cd93 | 1226 | |
DanGibbons | 6:5e8e2645cd93 | 1227 | for (int i = 51; i > 17; i--) { |
DanGibbons | 6:5e8e2645cd93 | 1228 | mainArray[1][i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1229 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1230 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1231 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1232 | } |
DanGibbons | 6:5e8e2645cd93 | 1233 | |
DanGibbons | 6:5e8e2645cd93 | 1234 | } |
DanGibbons | 6:5e8e2645cd93 | 1235 | |
DanGibbons | 6:5e8e2645cd93 | 1236 | if (player == false && robot == true) { |
DanGibbons | 6:5e8e2645cd93 | 1237 | |
DanGibbons | 6:5e8e2645cd93 | 1238 | for (int i = 51; i > 17; i--) { // B and F |
DanGibbons | 6:5e8e2645cd93 | 1239 | mainArray[1][i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1240 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1241 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1242 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1243 | } |
DanGibbons | 6:5e8e2645cd93 | 1244 | |
DanGibbons | 6:5e8e2645cd93 | 1245 | } |
DanGibbons | 6:5e8e2645cd93 | 1246 | |
DanGibbons | 6:5e8e2645cd93 | 1247 | } |
DanGibbons | 6:5e8e2645cd93 | 1248 | |
DanGibbons | 6:5e8e2645cd93 | 1249 | void OneOutAnimation(bool robot, bool robotColour,bool player, bool playerColour) |
DanGibbons | 6:5e8e2645cd93 | 1250 | { |
DanGibbons | 6:5e8e2645cd93 | 1251 | if (player == true && robot == true) { |
DanGibbons | 6:5e8e2645cd93 | 1252 | |
DanGibbons | 6:5e8e2645cd93 | 1253 | for (int i = 18; i < 52; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1254 | mainArray[1][i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1255 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1256 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1257 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1258 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 5:2d439ccefc7d | 1259 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1260 | } |
DanGibbons | 6:5e8e2645cd93 | 1261 | |
DanGibbons | 6:5e8e2645cd93 | 1262 | } |
DanGibbons | 6:5e8e2645cd93 | 1263 | |
DanGibbons | 6:5e8e2645cd93 | 1264 | if (player == true && robot == false) { |
DanGibbons | 6:5e8e2645cd93 | 1265 | |
DanGibbons | 6:5e8e2645cd93 | 1266 | for (int i = 18; i < 52; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1267 | mainArray[1][i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1268 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1269 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1270 | playerScoreLED.write(playerScorePx.getBuf());; |
DanGibbons | 6:5e8e2645cd93 | 1271 | } |
DanGibbons | 6:5e8e2645cd93 | 1272 | |
DanGibbons | 6:5e8e2645cd93 | 1273 | } |
DanGibbons | 6:5e8e2645cd93 | 1274 | |
DanGibbons | 6:5e8e2645cd93 | 1275 | if (player == false && robot == true) { |
DanGibbons | 6:5e8e2645cd93 | 1276 | |
DanGibbons | 6:5e8e2645cd93 | 1277 | for (int i = 18; i < 52; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1278 | mainArray[1][i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1279 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1280 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1281 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1282 | } |
DanGibbons | 6:5e8e2645cd93 | 1283 | |
DanGibbons | 6:5e8e2645cd93 | 1284 | } |
DanGibbons | 6:5e8e2645cd93 | 1285 | |
DanGibbons | 6:5e8e2645cd93 | 1286 | } |
DanGibbons | 6:5e8e2645cd93 | 1287 | |
DanGibbons | 6:5e8e2645cd93 | 1288 | void TwoInAnimation(bool robot, bool robotColour,bool player, bool playerColour) |
DanGibbons | 6:5e8e2645cd93 | 1289 | { |
DanGibbons | 6:5e8e2645cd93 | 1290 | memset(mainArray, 0, sizeof mainArray); |
DanGibbons | 5:2d439ccefc7d | 1291 | |
DanGibbons | 6:5e8e2645cd93 | 1292 | if (player == true && robot == true) { |
DanGibbons | 6:5e8e2645cd93 | 1293 | |
DanGibbons | 6:5e8e2645cd93 | 1294 | for (int i = 0; i < 35; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1295 | mainArray[2][i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1296 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1297 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1298 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1299 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1300 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1301 | } |
DanGibbons | 6:5e8e2645cd93 | 1302 | for (int i = 121; i > 103; i--) { |
DanGibbons | 6:5e8e2645cd93 | 1303 | mainArray[2][i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1304 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1305 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1306 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1307 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1308 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1309 | } |
DanGibbons | 6:5e8e2645cd93 | 1310 | for (int i = 86; i > 51; i--) { |
DanGibbons | 6:5e8e2645cd93 | 1311 | mainArray[2][i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1312 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1313 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1314 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1315 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1316 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1317 | } |
DanGibbons | 6:5e8e2645cd93 | 1318 | |
DanGibbons | 6:5e8e2645cd93 | 1319 | } |
DanGibbons | 6:5e8e2645cd93 | 1320 | |
DanGibbons | 6:5e8e2645cd93 | 1321 | if (player == true && robot == false) { |
DanGibbons | 6:5e8e2645cd93 | 1322 | |
DanGibbons | 6:5e8e2645cd93 | 1323 | for (int i = 0; i < 35; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1324 | mainArray[2][i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1325 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1326 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1327 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1328 | } |
DanGibbons | 6:5e8e2645cd93 | 1329 | for (int i = 121; i > 103; i--) { |
DanGibbons | 6:5e8e2645cd93 | 1330 | mainArray[2][i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1331 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1332 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1333 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1334 | } |
DanGibbons | 6:5e8e2645cd93 | 1335 | for (int i = 86; i > 51; i--) { |
DanGibbons | 6:5e8e2645cd93 | 1336 | mainArray[2][i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1337 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1338 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1339 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1340 | } |
DanGibbons | 6:5e8e2645cd93 | 1341 | |
DanGibbons | 6:5e8e2645cd93 | 1342 | } |
DanGibbons | 6:5e8e2645cd93 | 1343 | |
DanGibbons | 6:5e8e2645cd93 | 1344 | if (player == false && robot == true) { |
DanGibbons | 6:5e8e2645cd93 | 1345 | |
DanGibbons | 6:5e8e2645cd93 | 1346 | for (int i = 0; i < 35; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1347 | mainArray[2][i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1348 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1349 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1350 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1351 | } |
DanGibbons | 6:5e8e2645cd93 | 1352 | for (int i = 121; i > 103; i--) { |
DanGibbons | 6:5e8e2645cd93 | 1353 | mainArray[2][i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1354 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1355 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1356 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1357 | } |
DanGibbons | 6:5e8e2645cd93 | 1358 | for (int i = 86; i > 51; i--) { |
DanGibbons | 6:5e8e2645cd93 | 1359 | mainArray[2][i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1360 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1361 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1362 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1363 | } |
DanGibbons | 6:5e8e2645cd93 | 1364 | |
DanGibbons | 6:5e8e2645cd93 | 1365 | } |
DanGibbons | 5:2d439ccefc7d | 1366 | |
DanGibbons | 6:5e8e2645cd93 | 1367 | } |
DanGibbons | 6:5e8e2645cd93 | 1368 | |
DanGibbons | 6:5e8e2645cd93 | 1369 | void TwoOutAnimation(bool robot, bool robotColour,bool player, bool playerColour) |
DanGibbons | 6:5e8e2645cd93 | 1370 | { |
DanGibbons | 6:5e8e2645cd93 | 1371 | if (player == true && robot == true) { |
DanGibbons | 6:5e8e2645cd93 | 1372 | |
DanGibbons | 6:5e8e2645cd93 | 1373 | for (int i = 0; i < 35; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1374 | mainArray[2][i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1375 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1376 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1377 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1378 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1379 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1380 | } |
DanGibbons | 6:5e8e2645cd93 | 1381 | for (int i = 121; i > 103; i--) { |
DanGibbons | 6:5e8e2645cd93 | 1382 | mainArray[2][i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1383 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1384 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1385 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1386 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1387 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1388 | } |
DanGibbons | 6:5e8e2645cd93 | 1389 | for (int i = 86; i > 51; i--) { |
DanGibbons | 6:5e8e2645cd93 | 1390 | mainArray[2][i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1391 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1392 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1393 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1394 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1395 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1396 | } |
DanGibbons | 6:5e8e2645cd93 | 1397 | |
DanGibbons | 6:5e8e2645cd93 | 1398 | } |
DanGibbons | 6:5e8e2645cd93 | 1399 | |
DanGibbons | 6:5e8e2645cd93 | 1400 | if (player == true && robot == false) { |
DanGibbons | 6:5e8e2645cd93 | 1401 | |
DanGibbons | 6:5e8e2645cd93 | 1402 | for (int i = 0; i < 35; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1403 | mainArray[2][i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1404 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1405 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1406 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1407 | } |
DanGibbons | 6:5e8e2645cd93 | 1408 | for (int i = 121; i > 103; i--) { |
DanGibbons | 6:5e8e2645cd93 | 1409 | mainArray[2][i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1410 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1411 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1412 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1413 | } |
DanGibbons | 6:5e8e2645cd93 | 1414 | for (int i = 86; i > 51; i--) { |
DanGibbons | 6:5e8e2645cd93 | 1415 | mainArray[2][i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1416 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1417 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1418 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1419 | } |
DanGibbons | 6:5e8e2645cd93 | 1420 | |
DanGibbons | 6:5e8e2645cd93 | 1421 | } |
DanGibbons | 6:5e8e2645cd93 | 1422 | |
DanGibbons | 6:5e8e2645cd93 | 1423 | if (player == false && robot == true) { |
DanGibbons | 6:5e8e2645cd93 | 1424 | |
DanGibbons | 6:5e8e2645cd93 | 1425 | for (int i = 0; i < 35; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1426 | mainArray[2][i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1427 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1428 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1429 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1430 | } |
DanGibbons | 6:5e8e2645cd93 | 1431 | for (int i = 121; i > 103; i--) { |
DanGibbons | 6:5e8e2645cd93 | 1432 | mainArray[2][i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1433 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1434 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1435 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1436 | } |
DanGibbons | 6:5e8e2645cd93 | 1437 | for (int i = 86; i > 51; i--) { |
DanGibbons | 6:5e8e2645cd93 | 1438 | mainArray[2][i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1439 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1440 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1441 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1442 | } |
DanGibbons | 6:5e8e2645cd93 | 1443 | |
DanGibbons | 6:5e8e2645cd93 | 1444 | } |
DanGibbons | 6:5e8e2645cd93 | 1445 | |
DanGibbons | 6:5e8e2645cd93 | 1446 | } |
DanGibbons | 6:5e8e2645cd93 | 1447 | |
DanGibbons | 6:5e8e2645cd93 | 1448 | void ThreeInAnimation(bool robot, bool robotColour,bool player, bool playerColour) |
DanGibbons | 6:5e8e2645cd93 | 1449 | { |
DanGibbons | 6:5e8e2645cd93 | 1450 | memset(mainArray, 0, sizeof mainArray); |
DanGibbons | 6:5e8e2645cd93 | 1451 | |
DanGibbons | 6:5e8e2645cd93 | 1452 | if (player == true && robot == true) { |
DanGibbons | 6:5e8e2645cd93 | 1453 | |
DanGibbons | 6:5e8e2645cd93 | 1454 | for (int i = 0; i < 35; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1455 | mainArray[3][i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1456 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1457 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1458 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1459 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1460 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1461 | } |
DanGibbons | 6:5e8e2645cd93 | 1462 | for (int i = 0; i < 17; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1463 | mainArray[3][35+i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1464 | mainArray[3][121-i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1465 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1466 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1467 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1468 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1469 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1470 | } |
DanGibbons | 6:5e8e2645cd93 | 1471 | for (int i = 52; i < 70; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1472 | mainArray[3][i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1473 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1474 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1475 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1476 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1477 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1478 | } |
DanGibbons | 6:5e8e2645cd93 | 1479 | |
DanGibbons | 6:5e8e2645cd93 | 1480 | } |
DanGibbons | 6:5e8e2645cd93 | 1481 | |
DanGibbons | 6:5e8e2645cd93 | 1482 | if (player == true && robot == false) { |
DanGibbons | 6:5e8e2645cd93 | 1483 | |
DanGibbons | 6:5e8e2645cd93 | 1484 | for (int i = 0; i < 35; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1485 | mainArray[3][i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1486 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1487 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1488 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1489 | } |
DanGibbons | 6:5e8e2645cd93 | 1490 | for (int i = 0; i < 17; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1491 | mainArray[3][35+i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1492 | mainArray[3][121-i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1493 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1494 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1495 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1496 | } |
DanGibbons | 6:5e8e2645cd93 | 1497 | for (int i = 52; i < 70; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1498 | mainArray[3][i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1499 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1500 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1501 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1502 | } |
DanGibbons | 6:5e8e2645cd93 | 1503 | |
DanGibbons | 6:5e8e2645cd93 | 1504 | } |
DanGibbons | 6:5e8e2645cd93 | 1505 | |
DanGibbons | 6:5e8e2645cd93 | 1506 | if (player == false && robot == true) { |
DanGibbons | 6:5e8e2645cd93 | 1507 | |
DanGibbons | 6:5e8e2645cd93 | 1508 | for (int i = 0; i < 35; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1509 | mainArray[3][i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1510 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1511 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1512 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1513 | } |
DanGibbons | 6:5e8e2645cd93 | 1514 | for (int i = 0; i < 18; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1515 | mainArray[3][35+i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1516 | mainArray[3][121-i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1517 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1518 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1519 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1520 | } |
DanGibbons | 6:5e8e2645cd93 | 1521 | for (int i = 52; i < 70; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1522 | mainArray[3][i] = 1; |
DanGibbons | 6:5e8e2645cd93 | 1523 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1524 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1525 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1526 | } |
DanGibbons | 6:5e8e2645cd93 | 1527 | |
DanGibbons | 6:5e8e2645cd93 | 1528 | } |
DanGibbons | 6:5e8e2645cd93 | 1529 | |
DanGibbons | 6:5e8e2645cd93 | 1530 | } |
DanGibbons | 6:5e8e2645cd93 | 1531 | |
DanGibbons | 6:5e8e2645cd93 | 1532 | void ThreeOutAnimation(bool robot, bool robotColour,bool player, bool playerColour) |
DanGibbons | 6:5e8e2645cd93 | 1533 | { |
DanGibbons | 6:5e8e2645cd93 | 1534 | if (player == true && robot == true) { |
DanGibbons | 6:5e8e2645cd93 | 1535 | |
DanGibbons | 6:5e8e2645cd93 | 1536 | for (int i = 0; i < 18; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1537 | mainArray[3][i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1538 | mainArray[3][104+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1539 | mainArray[3][69-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1540 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1541 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1542 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1543 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1544 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1545 | } |
DanGibbons | 6:5e8e2645cd93 | 1546 | for (int i = 0; i < 18; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1547 | mainArray[3][18+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1548 | mainArray[3][51-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1549 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1550 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1551 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1552 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1553 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1554 | } |
DanGibbons | 6:5e8e2645cd93 | 1555 | |
DanGibbons | 6:5e8e2645cd93 | 1556 | } |
DanGibbons | 6:5e8e2645cd93 | 1557 | |
DanGibbons | 6:5e8e2645cd93 | 1558 | if (player == true && robot == false) { |
DanGibbons | 6:5e8e2645cd93 | 1559 | |
DanGibbons | 6:5e8e2645cd93 | 1560 | for (int i = 0; i < 18; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1561 | mainArray[3][i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1562 | mainArray[3][104+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1563 | mainArray[3][69-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1564 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1565 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1566 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1567 | } |
DanGibbons | 6:5e8e2645cd93 | 1568 | for (int i = 0; i < 18; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1569 | mainArray[3][18+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1570 | mainArray[3][51-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1571 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1572 | WritePxAnimation(playerScore,false,playerColour); |
DanGibbons | 6:5e8e2645cd93 | 1573 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1574 | } |
DanGibbons | 6:5e8e2645cd93 | 1575 | |
DanGibbons | 6:5e8e2645cd93 | 1576 | } |
DanGibbons | 6:5e8e2645cd93 | 1577 | |
DanGibbons | 6:5e8e2645cd93 | 1578 | if (player == false && robot == true) { |
DanGibbons | 6:5e8e2645cd93 | 1579 | |
DanGibbons | 6:5e8e2645cd93 | 1580 | for (int i = 0; i < 18; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1581 | mainArray[3][i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1582 | mainArray[3][104+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1583 | mainArray[3][69-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1584 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1585 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1586 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1587 | } |
DanGibbons | 6:5e8e2645cd93 | 1588 | for (int i = 0; i < 18; i++) { |
DanGibbons | 6:5e8e2645cd93 | 1589 | mainArray[3][18+i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1590 | mainArray[3][51-i] = 0; |
DanGibbons | 6:5e8e2645cd93 | 1591 | wait_ms(10); |
DanGibbons | 6:5e8e2645cd93 | 1592 | WritePxAnimation(robotScore,true,robotColour); |
DanGibbons | 6:5e8e2645cd93 | 1593 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 6:5e8e2645cd93 | 1594 | } |
DanGibbons | 6:5e8e2645cd93 | 1595 | |
DanGibbons | 6:5e8e2645cd93 | 1596 | } |
DanGibbons | 6:5e8e2645cd93 | 1597 | |
DanGibbons | 6:5e8e2645cd93 | 1598 | } |
DanGibbons | 6:5e8e2645cd93 | 1599 | |
DanGibbons | 6:5e8e2645cd93 | 1600 | void idleButtonISR() |
DanGibbons | 6:5e8e2645cd93 | 1601 | { |
DanGibbons | 9:f3f194982bb3 | 1602 | if (idle_button_pressed == 0) { |
DanGibbons | 9:f3f194982bb3 | 1603 | idle_flag = !idle_flag; |
DanGibbons | 9:f3f194982bb3 | 1604 | idle_button_pressed = 1; |
DanGibbons | 9:f3f194982bb3 | 1605 | idleButton.disable_irq(); |
DanGibbons | 9:f3f194982bb3 | 1606 | } |
DanGibbons | 6:5e8e2645cd93 | 1607 | } |