
updated 7seg controls for new 7 seg boards
Dependencies: PixelArray WS2812 mbed
Fork of frdm_pong_table_controller by
main.cpp@5:2d439ccefc7d, 2017-07-06 (annotated)
- Committer:
- DanGibbons
- Date:
- Thu Jul 06 16:16:36 2017 +0000
- Revision:
- 5:2d439ccefc7d
- Parent:
- 4:2e80bd814f57
- Child:
- 6:5e8e2645cd93
Random Colour added; Drain animation added; Drawing animation added for numbers
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(); |
benswindell | 0:f2b739e846ae | 6 | |
DanGibbons | 4:2e80bd814f57 | 7 | while(1) { |
DanGibbons | 4:2e80bd814f57 | 8 | |
DanGibbons | 4:2e80bd814f57 | 9 | double rbbValue = robotBreakBeam; // Read Robot Break beam |
DanGibbons | 4:2e80bd814f57 | 10 | double pbbValue = playerBreakBeam; // Read Player Break beam |
benswindell | 0:f2b739e846ae | 11 | |
DanGibbons | 4:2e80bd814f57 | 12 | // IF PLAYER HAS SCORED A GOAL |
DanGibbons | 4:2e80bd814f57 | 13 | if (((prevRbbValue - rbbValue)>0.03)|| (PB1==0)) { |
DanGibbons | 4:2e80bd814f57 | 14 | pc.printf("Player has scored a goal \n\r"); |
DanGibbons | 4:2e80bd814f57 | 15 | HandleGoal(false); |
DanGibbons | 4:2e80bd814f57 | 16 | } |
benswindell | 0:f2b739e846ae | 17 | |
DanGibbons | 4:2e80bd814f57 | 18 | // IF ROBOT HAS SCORED A GOAL |
DanGibbons | 4:2e80bd814f57 | 19 | if (((prevPbbValue - pbbValue) > 0.03)|| (PB2==0)) { |
DanGibbons | 4:2e80bd814f57 | 20 | pc.printf("Robot has scored a goal \n\r"); |
DanGibbons | 4:2e80bd814f57 | 21 | HandleGoal(true); |
DanGibbons | 4:2e80bd814f57 | 22 | } |
benswindell | 0:f2b739e846ae | 23 | |
DanGibbons | 4:2e80bd814f57 | 24 | prevRbbValue = rbbValue; |
DanGibbons | 4:2e80bd814f57 | 25 | prevPbbValue = pbbValue; |
benswindell | 0:f2b739e846ae | 26 | |
DanGibbons | 4:2e80bd814f57 | 27 | pc.printf("PlayerGoal: %f, RobotGoal: %f \r\n",pbbValue,rbbValue); |
DanGibbons | 4:2e80bd814f57 | 28 | pc.printf("Player: %i v %i : Robot \r\n",playerScore,robotScore); |
DanGibbons | 4:2e80bd814f57 | 29 | wait(0.02); |
benswindell | 0:f2b739e846ae | 30 | |
DanGibbons | 4:2e80bd814f57 | 31 | } |
DanGibbons | 4:2e80bd814f57 | 32 | } |
samuelmoss | 2:ff409472bc08 | 33 | |
DanGibbons | 4:2e80bd814f57 | 34 | void Setup() |
benswindell | 0:f2b739e846ae | 35 | { |
benswindell | 0:f2b739e846ae | 36 | // Turn on green LED |
benswindell | 0:f2b739e846ae | 37 | led_green = 0; |
benswindell | 0:f2b739e846ae | 38 | |
benswindell | 1:24bc4d8ed2ae | 39 | // Set brightness of the 4 LED strips |
samuelmoss | 2:ff409472bc08 | 40 | robotScoreLED.setII(0xB0); |
benswindell | 1:24bc4d8ed2ae | 41 | robotScoreLED.useII(WS2812::GLOBAL); |
samuelmoss | 2:ff409472bc08 | 42 | playerScoreLED.setII(0xB0); |
benswindell | 1:24bc4d8ed2ae | 43 | playerScoreLED.useII(WS2812::GLOBAL); |
DanGibbons | 4:2e80bd814f57 | 44 | |
benswindell | 0:f2b739e846ae | 45 | // Set scores to 0 |
benswindell | 0:f2b739e846ae | 46 | robotScore = 0; |
benswindell | 0:f2b739e846ae | 47 | playerScore = 0; |
benswindell | 0:f2b739e846ae | 48 | numFlashes = 0; |
DanGibbons | 5:2d439ccefc7d | 49 | |
DanGibbons | 5:2d439ccefc7d | 50 | FigureOf8Animation(true,true,2); // run animation 2 times for both robot and player scores |
DanGibbons | 5:2d439ccefc7d | 51 | DrainAnimation(true,true,robotScore,true,true,playerScore); // run animation for both scores with random colour pattern |
DanGibbons | 5:2d439ccefc7d | 52 | |
DanGibbons | 5:2d439ccefc7d | 53 | SetNumberPatterns(); |
DanGibbons | 5:2d439ccefc7d | 54 | |
benswindell | 0:f2b739e846ae | 55 | WriteScores(); |
samuelmoss | 2:ff409472bc08 | 56 | |
benswindell | 0:f2b739e846ae | 57 | // Turn off green LED |
benswindell | 0:f2b739e846ae | 58 | led_green = 1; |
benswindell | 0:f2b739e846ae | 59 | } |
benswindell | 0:f2b739e846ae | 60 | |
DanGibbons | 5:2d439ccefc7d | 61 | // set segment number patterns |
DanGibbons | 4:2e80bd814f57 | 62 | void SetNumberPatterns() |
benswindell | 0:f2b739e846ae | 63 | { |
DanGibbons | 4:2e80bd814f57 | 64 | for (int num = 0; num < 11; num++) { |
benswindell | 0:f2b739e846ae | 65 | |
DanGibbons | 4:2e80bd814f57 | 66 | switch (num) { |
DanGibbons | 4:2e80bd814f57 | 67 | case 0 : |
DanGibbons | 4:2e80bd814f57 | 68 | // 0 |
DanGibbons | 4:2e80bd814f57 | 69 | seg1A = 1; |
DanGibbons | 4:2e80bd814f57 | 70 | seg1B = 1; |
DanGibbons | 4:2e80bd814f57 | 71 | seg1C = 1; |
DanGibbons | 4:2e80bd814f57 | 72 | seg1D = 1; |
DanGibbons | 4:2e80bd814f57 | 73 | seg1E = 1; |
DanGibbons | 4:2e80bd814f57 | 74 | seg1F = 1; |
DanGibbons | 4:2e80bd814f57 | 75 | seg1G = 0; |
benswindell | 0:f2b739e846ae | 76 | |
DanGibbons | 4:2e80bd814f57 | 77 | SetLEDArray(0); |
DanGibbons | 4:2e80bd814f57 | 78 | break; |
benswindell | 0:f2b739e846ae | 79 | |
DanGibbons | 4:2e80bd814f57 | 80 | case 1 : |
DanGibbons | 4:2e80bd814f57 | 81 | // 1 |
DanGibbons | 4:2e80bd814f57 | 82 | seg1A = 0; |
DanGibbons | 4:2e80bd814f57 | 83 | seg1B = 1; |
DanGibbons | 4:2e80bd814f57 | 84 | seg1C = 1; |
DanGibbons | 4:2e80bd814f57 | 85 | seg1D = 0; |
DanGibbons | 4:2e80bd814f57 | 86 | seg1E = 0; |
DanGibbons | 4:2e80bd814f57 | 87 | seg1F = 0; |
DanGibbons | 4:2e80bd814f57 | 88 | seg1G = 0; |
benswindell | 0:f2b739e846ae | 89 | |
DanGibbons | 4:2e80bd814f57 | 90 | SetLEDArray(1); |
DanGibbons | 4:2e80bd814f57 | 91 | break; |
benswindell | 0:f2b739e846ae | 92 | |
DanGibbons | 4:2e80bd814f57 | 93 | case 2 : |
DanGibbons | 4:2e80bd814f57 | 94 | // 2 |
DanGibbons | 4:2e80bd814f57 | 95 | seg1A = 1; |
DanGibbons | 4:2e80bd814f57 | 96 | seg1B = 1; |
DanGibbons | 4:2e80bd814f57 | 97 | seg1C = 0; |
DanGibbons | 4:2e80bd814f57 | 98 | seg1D = 1; |
DanGibbons | 4:2e80bd814f57 | 99 | seg1E = 1; |
DanGibbons | 4:2e80bd814f57 | 100 | seg1F = 0; |
DanGibbons | 4:2e80bd814f57 | 101 | seg1G = 1; |
benswindell | 0:f2b739e846ae | 102 | |
DanGibbons | 4:2e80bd814f57 | 103 | SetLEDArray(2); |
DanGibbons | 4:2e80bd814f57 | 104 | break; |
benswindell | 0:f2b739e846ae | 105 | |
DanGibbons | 4:2e80bd814f57 | 106 | case 3 : |
DanGibbons | 4:2e80bd814f57 | 107 | // 3 |
DanGibbons | 4:2e80bd814f57 | 108 | seg1A = 1; |
DanGibbons | 4:2e80bd814f57 | 109 | seg1B = 1; |
DanGibbons | 4:2e80bd814f57 | 110 | seg1C = 1; |
DanGibbons | 4:2e80bd814f57 | 111 | seg1D = 1; |
DanGibbons | 4:2e80bd814f57 | 112 | seg1E = 0; |
DanGibbons | 4:2e80bd814f57 | 113 | seg1F = 0; |
DanGibbons | 4:2e80bd814f57 | 114 | seg1G = 1; |
benswindell | 0:f2b739e846ae | 115 | |
DanGibbons | 4:2e80bd814f57 | 116 | SetLEDArray(3); |
DanGibbons | 4:2e80bd814f57 | 117 | break; |
benswindell | 0:f2b739e846ae | 118 | |
DanGibbons | 4:2e80bd814f57 | 119 | case 4: |
DanGibbons | 4:2e80bd814f57 | 120 | // 4 |
DanGibbons | 4:2e80bd814f57 | 121 | seg1A = 0; |
DanGibbons | 4:2e80bd814f57 | 122 | seg1B = 1; |
DanGibbons | 4:2e80bd814f57 | 123 | seg1C = 1; |
DanGibbons | 4:2e80bd814f57 | 124 | seg1D = 0; |
DanGibbons | 4:2e80bd814f57 | 125 | seg1E = 0; |
DanGibbons | 4:2e80bd814f57 | 126 | seg1F = 1; |
DanGibbons | 4:2e80bd814f57 | 127 | seg1G = 1; |
benswindell | 0:f2b739e846ae | 128 | |
DanGibbons | 4:2e80bd814f57 | 129 | SetLEDArray(4); |
DanGibbons | 4:2e80bd814f57 | 130 | break; |
benswindell | 0:f2b739e846ae | 131 | |
DanGibbons | 4:2e80bd814f57 | 132 | case 5: |
DanGibbons | 4:2e80bd814f57 | 133 | // 5 |
DanGibbons | 4:2e80bd814f57 | 134 | seg1A = 1; |
DanGibbons | 4:2e80bd814f57 | 135 | seg1B = 0; |
DanGibbons | 4:2e80bd814f57 | 136 | seg1C = 1; |
DanGibbons | 4:2e80bd814f57 | 137 | seg1D = 1; |
DanGibbons | 4:2e80bd814f57 | 138 | seg1E = 0; |
DanGibbons | 4:2e80bd814f57 | 139 | seg1F = 1; |
DanGibbons | 4:2e80bd814f57 | 140 | seg1G = 1; |
benswindell | 0:f2b739e846ae | 141 | |
DanGibbons | 4:2e80bd814f57 | 142 | SetLEDArray(5); |
DanGibbons | 4:2e80bd814f57 | 143 | break; |
benswindell | 0:f2b739e846ae | 144 | |
DanGibbons | 4:2e80bd814f57 | 145 | case 6: |
DanGibbons | 4:2e80bd814f57 | 146 | // 6 |
DanGibbons | 4:2e80bd814f57 | 147 | seg1A = 1; |
DanGibbons | 4:2e80bd814f57 | 148 | seg1B = 0; |
DanGibbons | 4:2e80bd814f57 | 149 | seg1C = 1; |
DanGibbons | 4:2e80bd814f57 | 150 | seg1D = 1; |
DanGibbons | 4:2e80bd814f57 | 151 | seg1E = 1; |
DanGibbons | 4:2e80bd814f57 | 152 | seg1F = 1; |
DanGibbons | 4:2e80bd814f57 | 153 | seg1G = 1; |
benswindell | 0:f2b739e846ae | 154 | |
DanGibbons | 4:2e80bd814f57 | 155 | SetLEDArray(6); |
DanGibbons | 4:2e80bd814f57 | 156 | break; |
benswindell | 0:f2b739e846ae | 157 | |
DanGibbons | 4:2e80bd814f57 | 158 | case 7: |
DanGibbons | 4:2e80bd814f57 | 159 | // 7 |
DanGibbons | 4:2e80bd814f57 | 160 | seg1A = 1; |
DanGibbons | 4:2e80bd814f57 | 161 | seg1B = 1; |
DanGibbons | 4:2e80bd814f57 | 162 | seg1C = 1; |
DanGibbons | 4:2e80bd814f57 | 163 | seg1D = 0; |
DanGibbons | 4:2e80bd814f57 | 164 | seg1E = 0; |
DanGibbons | 4:2e80bd814f57 | 165 | seg1F = 0; |
DanGibbons | 4:2e80bd814f57 | 166 | seg1G = 0; |
benswindell | 0:f2b739e846ae | 167 | |
DanGibbons | 4:2e80bd814f57 | 168 | SetLEDArray(7); |
DanGibbons | 4:2e80bd814f57 | 169 | break; |
benswindell | 0:f2b739e846ae | 170 | |
DanGibbons | 4:2e80bd814f57 | 171 | case 8: |
DanGibbons | 4:2e80bd814f57 | 172 | // 8 |
DanGibbons | 4:2e80bd814f57 | 173 | seg1A = 1; |
DanGibbons | 4:2e80bd814f57 | 174 | seg1B = 1; |
DanGibbons | 4:2e80bd814f57 | 175 | seg1C = 1; |
DanGibbons | 4:2e80bd814f57 | 176 | seg1D = 1; |
DanGibbons | 4:2e80bd814f57 | 177 | seg1E = 1; |
DanGibbons | 4:2e80bd814f57 | 178 | seg1F = 1; |
DanGibbons | 4:2e80bd814f57 | 179 | seg1G = 1; |
benswindell | 0:f2b739e846ae | 180 | |
DanGibbons | 4:2e80bd814f57 | 181 | SetLEDArray(8); |
DanGibbons | 4:2e80bd814f57 | 182 | break; |
benswindell | 0:f2b739e846ae | 183 | |
DanGibbons | 4:2e80bd814f57 | 184 | case 9: |
DanGibbons | 4:2e80bd814f57 | 185 | // 9 |
DanGibbons | 4:2e80bd814f57 | 186 | seg1A = 1; |
DanGibbons | 4:2e80bd814f57 | 187 | seg1B = 1; |
DanGibbons | 4:2e80bd814f57 | 188 | seg1C = 1; |
DanGibbons | 4:2e80bd814f57 | 189 | seg1D = 0; |
DanGibbons | 4:2e80bd814f57 | 190 | seg1E = 0; |
DanGibbons | 4:2e80bd814f57 | 191 | seg1F = 1; |
DanGibbons | 4:2e80bd814f57 | 192 | seg1G = 1; |
benswindell | 0:f2b739e846ae | 193 | |
DanGibbons | 4:2e80bd814f57 | 194 | SetLEDArray(9); |
DanGibbons | 4:2e80bd814f57 | 195 | break; |
benswindell | 0:f2b739e846ae | 196 | |
DanGibbons | 4:2e80bd814f57 | 197 | case 10: |
DanGibbons | 4:2e80bd814f57 | 198 | // OFF |
DanGibbons | 4:2e80bd814f57 | 199 | seg1A = 0; |
DanGibbons | 4:2e80bd814f57 | 200 | seg1B = 0; |
DanGibbons | 4:2e80bd814f57 | 201 | seg1C = 0; |
DanGibbons | 4:2e80bd814f57 | 202 | seg1D = 0; |
DanGibbons | 4:2e80bd814f57 | 203 | seg1E = 0; |
DanGibbons | 4:2e80bd814f57 | 204 | seg1F = 0; |
DanGibbons | 4:2e80bd814f57 | 205 | seg1G = 0; |
benswindell | 0:f2b739e846ae | 206 | |
DanGibbons | 4:2e80bd814f57 | 207 | SetLEDArray(10); |
DanGibbons | 4:2e80bd814f57 | 208 | break; |
benswindell | 0:f2b739e846ae | 209 | |
DanGibbons | 4:2e80bd814f57 | 210 | default : |
benswindell | 0:f2b739e846ae | 211 | |
DanGibbons | 4:2e80bd814f57 | 212 | break; |
DanGibbons | 4:2e80bd814f57 | 213 | |
DanGibbons | 4:2e80bd814f57 | 214 | } |
benswindell | 0:f2b739e846ae | 215 | |
benswindell | 0:f2b739e846ae | 216 | } |
DanGibbons | 4:2e80bd814f57 | 217 | |
DanGibbons | 4:2e80bd814f57 | 218 | } |
DanGibbons | 4:2e80bd814f57 | 219 | |
DanGibbons | 5:2d439ccefc7d | 220 | // segment pattern for figure of 8 animation |
DanGibbons | 4:2e80bd814f57 | 221 | void SetFigureOf8Pattern() |
DanGibbons | 4:2e80bd814f57 | 222 | { |
DanGibbons | 4:2e80bd814f57 | 223 | for(int seg = 0; seg < 8; seg++) { |
DanGibbons | 4:2e80bd814f57 | 224 | |
DanGibbons | 4:2e80bd814f57 | 225 | switch (seg) { |
DanGibbons | 4:2e80bd814f57 | 226 | case 0 : |
DanGibbons | 4:2e80bd814f57 | 227 | seg1A = 1; |
DanGibbons | 4:2e80bd814f57 | 228 | seg1B = 0; |
DanGibbons | 4:2e80bd814f57 | 229 | seg1C = 0; |
DanGibbons | 4:2e80bd814f57 | 230 | seg1D = 0; |
DanGibbons | 4:2e80bd814f57 | 231 | seg1E = 0; |
DanGibbons | 4:2e80bd814f57 | 232 | seg1F = 0; |
DanGibbons | 4:2e80bd814f57 | 233 | seg1G = 0; |
DanGibbons | 4:2e80bd814f57 | 234 | |
DanGibbons | 4:2e80bd814f57 | 235 | SetLEDArray(0); |
DanGibbons | 4:2e80bd814f57 | 236 | break; |
DanGibbons | 4:2e80bd814f57 | 237 | |
DanGibbons | 4:2e80bd814f57 | 238 | case 1 : |
DanGibbons | 4:2e80bd814f57 | 239 | seg1A = 0; |
DanGibbons | 4:2e80bd814f57 | 240 | seg1B = 1; |
DanGibbons | 4:2e80bd814f57 | 241 | seg1C = 0; |
DanGibbons | 4:2e80bd814f57 | 242 | seg1D = 0; |
DanGibbons | 4:2e80bd814f57 | 243 | seg1E = 0; |
DanGibbons | 4:2e80bd814f57 | 244 | seg1F = 0; |
DanGibbons | 4:2e80bd814f57 | 245 | seg1G = 0; |
DanGibbons | 4:2e80bd814f57 | 246 | |
DanGibbons | 4:2e80bd814f57 | 247 | SetLEDArray(1); |
DanGibbons | 4:2e80bd814f57 | 248 | break; |
DanGibbons | 4:2e80bd814f57 | 249 | |
DanGibbons | 4:2e80bd814f57 | 250 | case 2 : |
DanGibbons | 4:2e80bd814f57 | 251 | seg1A = 0; |
DanGibbons | 4:2e80bd814f57 | 252 | seg1B = 0; |
DanGibbons | 4:2e80bd814f57 | 253 | seg1C = 0; |
DanGibbons | 4:2e80bd814f57 | 254 | seg1D = 0; |
DanGibbons | 4:2e80bd814f57 | 255 | seg1E = 0; |
DanGibbons | 4:2e80bd814f57 | 256 | seg1F = 0; |
DanGibbons | 4:2e80bd814f57 | 257 | seg1G = 1; |
DanGibbons | 4:2e80bd814f57 | 258 | |
DanGibbons | 4:2e80bd814f57 | 259 | SetLEDArray(2); |
DanGibbons | 4:2e80bd814f57 | 260 | break; |
DanGibbons | 4:2e80bd814f57 | 261 | |
DanGibbons | 4:2e80bd814f57 | 262 | case 3 : |
DanGibbons | 4:2e80bd814f57 | 263 | seg1A = 0; |
DanGibbons | 4:2e80bd814f57 | 264 | seg1B = 0; |
DanGibbons | 4:2e80bd814f57 | 265 | seg1C = 0; |
DanGibbons | 4:2e80bd814f57 | 266 | seg1D = 0; |
DanGibbons | 4:2e80bd814f57 | 267 | seg1E = 1; |
DanGibbons | 4:2e80bd814f57 | 268 | seg1F = 0; |
DanGibbons | 4:2e80bd814f57 | 269 | seg1G = 0; |
DanGibbons | 4:2e80bd814f57 | 270 | |
DanGibbons | 4:2e80bd814f57 | 271 | SetLEDArray(3); |
DanGibbons | 4:2e80bd814f57 | 272 | break; |
DanGibbons | 4:2e80bd814f57 | 273 | |
DanGibbons | 4:2e80bd814f57 | 274 | case 4: |
DanGibbons | 4:2e80bd814f57 | 275 | seg1A = 0; |
DanGibbons | 4:2e80bd814f57 | 276 | seg1B = 0; |
DanGibbons | 4:2e80bd814f57 | 277 | seg1C = 0; |
DanGibbons | 4:2e80bd814f57 | 278 | seg1D = 1; |
DanGibbons | 4:2e80bd814f57 | 279 | seg1E = 0; |
DanGibbons | 4:2e80bd814f57 | 280 | seg1F = 0; |
DanGibbons | 4:2e80bd814f57 | 281 | seg1G = 0; |
DanGibbons | 4:2e80bd814f57 | 282 | |
DanGibbons | 4:2e80bd814f57 | 283 | SetLEDArray(4); |
DanGibbons | 4:2e80bd814f57 | 284 | break; |
DanGibbons | 4:2e80bd814f57 | 285 | |
DanGibbons | 4:2e80bd814f57 | 286 | case 5: |
DanGibbons | 4:2e80bd814f57 | 287 | seg1A = 0; |
DanGibbons | 4:2e80bd814f57 | 288 | seg1B = 0; |
DanGibbons | 4:2e80bd814f57 | 289 | seg1C = 1; |
DanGibbons | 4:2e80bd814f57 | 290 | seg1D = 0; |
DanGibbons | 4:2e80bd814f57 | 291 | seg1E = 0; |
DanGibbons | 4:2e80bd814f57 | 292 | seg1F = 0; |
DanGibbons | 4:2e80bd814f57 | 293 | seg1G = 0; |
DanGibbons | 4:2e80bd814f57 | 294 | |
DanGibbons | 4:2e80bd814f57 | 295 | SetLEDArray(5); |
DanGibbons | 4:2e80bd814f57 | 296 | break; |
DanGibbons | 4:2e80bd814f57 | 297 | |
DanGibbons | 4:2e80bd814f57 | 298 | case 6: |
DanGibbons | 4:2e80bd814f57 | 299 | seg1A = 0; |
DanGibbons | 4:2e80bd814f57 | 300 | seg1B = 0; |
DanGibbons | 4:2e80bd814f57 | 301 | seg1C = 0; |
DanGibbons | 4:2e80bd814f57 | 302 | seg1D = 0; |
DanGibbons | 4:2e80bd814f57 | 303 | seg1E = 0; |
DanGibbons | 4:2e80bd814f57 | 304 | seg1F = 0; |
DanGibbons | 4:2e80bd814f57 | 305 | seg1G = 1; |
DanGibbons | 4:2e80bd814f57 | 306 | |
DanGibbons | 4:2e80bd814f57 | 307 | SetLEDArray(6); |
DanGibbons | 4:2e80bd814f57 | 308 | break; |
DanGibbons | 4:2e80bd814f57 | 309 | |
DanGibbons | 4:2e80bd814f57 | 310 | case 7: |
DanGibbons | 4:2e80bd814f57 | 311 | seg1A = 0; |
DanGibbons | 4:2e80bd814f57 | 312 | seg1B = 0; |
DanGibbons | 4:2e80bd814f57 | 313 | seg1C = 0; |
DanGibbons | 4:2e80bd814f57 | 314 | seg1D = 0; |
DanGibbons | 4:2e80bd814f57 | 315 | seg1E = 0; |
DanGibbons | 4:2e80bd814f57 | 316 | seg1F = 1; |
DanGibbons | 4:2e80bd814f57 | 317 | seg1G = 0; |
DanGibbons | 4:2e80bd814f57 | 318 | |
DanGibbons | 4:2e80bd814f57 | 319 | SetLEDArray(7); |
DanGibbons | 4:2e80bd814f57 | 320 | break; |
DanGibbons | 4:2e80bd814f57 | 321 | |
DanGibbons | 4:2e80bd814f57 | 322 | default : |
DanGibbons | 4:2e80bd814f57 | 323 | |
DanGibbons | 4:2e80bd814f57 | 324 | break; |
DanGibbons | 4:2e80bd814f57 | 325 | |
DanGibbons | 4:2e80bd814f57 | 326 | } |
DanGibbons | 4:2e80bd814f57 | 327 | |
DanGibbons | 4:2e80bd814f57 | 328 | } |
DanGibbons | 4:2e80bd814f57 | 329 | |
benswindell | 0:f2b739e846ae | 330 | } |
benswindell | 0:f2b739e846ae | 331 | |
DanGibbons | 5:2d439ccefc7d | 332 | // Segment Pattern for circle animation |
DanGibbons | 5:2d439ccefc7d | 333 | void SetCirclePattern() |
DanGibbons | 5:2d439ccefc7d | 334 | { |
DanGibbons | 5:2d439ccefc7d | 335 | for(int seg = 0; seg < 6; seg++) { |
DanGibbons | 5:2d439ccefc7d | 336 | |
DanGibbons | 5:2d439ccefc7d | 337 | switch (seg) { |
DanGibbons | 5:2d439ccefc7d | 338 | case 0 : |
DanGibbons | 5:2d439ccefc7d | 339 | seg1A = 1; |
DanGibbons | 5:2d439ccefc7d | 340 | seg1B = 0; |
DanGibbons | 5:2d439ccefc7d | 341 | seg1C = 0; |
DanGibbons | 5:2d439ccefc7d | 342 | seg1D = 0; |
DanGibbons | 5:2d439ccefc7d | 343 | seg1E = 0; |
DanGibbons | 5:2d439ccefc7d | 344 | seg1F = 0; |
DanGibbons | 5:2d439ccefc7d | 345 | seg1G = 0; |
DanGibbons | 5:2d439ccefc7d | 346 | |
DanGibbons | 5:2d439ccefc7d | 347 | SetLEDArray(0); |
DanGibbons | 5:2d439ccefc7d | 348 | break; |
DanGibbons | 5:2d439ccefc7d | 349 | |
DanGibbons | 5:2d439ccefc7d | 350 | case 1 : |
DanGibbons | 5:2d439ccefc7d | 351 | seg1A = 0; |
DanGibbons | 5:2d439ccefc7d | 352 | seg1B = 1; |
DanGibbons | 5:2d439ccefc7d | 353 | seg1C = 0; |
DanGibbons | 5:2d439ccefc7d | 354 | seg1D = 0; |
DanGibbons | 5:2d439ccefc7d | 355 | seg1E = 0; |
DanGibbons | 5:2d439ccefc7d | 356 | seg1F = 0; |
DanGibbons | 5:2d439ccefc7d | 357 | seg1G = 0; |
DanGibbons | 5:2d439ccefc7d | 358 | |
DanGibbons | 5:2d439ccefc7d | 359 | SetLEDArray(1); |
DanGibbons | 5:2d439ccefc7d | 360 | break; |
DanGibbons | 5:2d439ccefc7d | 361 | |
DanGibbons | 5:2d439ccefc7d | 362 | case 2 : |
DanGibbons | 5:2d439ccefc7d | 363 | seg1A = 0; |
DanGibbons | 5:2d439ccefc7d | 364 | seg1B = 0; |
DanGibbons | 5:2d439ccefc7d | 365 | seg1C = 1; |
DanGibbons | 5:2d439ccefc7d | 366 | seg1D = 0; |
DanGibbons | 5:2d439ccefc7d | 367 | seg1E = 0; |
DanGibbons | 5:2d439ccefc7d | 368 | seg1F = 0; |
DanGibbons | 5:2d439ccefc7d | 369 | seg1G = 0; |
DanGibbons | 5:2d439ccefc7d | 370 | |
DanGibbons | 5:2d439ccefc7d | 371 | SetLEDArray(2); |
DanGibbons | 5:2d439ccefc7d | 372 | break; |
DanGibbons | 5:2d439ccefc7d | 373 | |
DanGibbons | 5:2d439ccefc7d | 374 | case 3 : |
DanGibbons | 5:2d439ccefc7d | 375 | seg1A = 0; |
DanGibbons | 5:2d439ccefc7d | 376 | seg1B = 0; |
DanGibbons | 5:2d439ccefc7d | 377 | seg1C = 0; |
DanGibbons | 5:2d439ccefc7d | 378 | seg1D = 1; |
DanGibbons | 5:2d439ccefc7d | 379 | seg1E = 0; |
DanGibbons | 5:2d439ccefc7d | 380 | seg1F = 0; |
DanGibbons | 5:2d439ccefc7d | 381 | seg1G = 0; |
DanGibbons | 5:2d439ccefc7d | 382 | |
DanGibbons | 5:2d439ccefc7d | 383 | SetLEDArray(3); |
DanGibbons | 5:2d439ccefc7d | 384 | break; |
DanGibbons | 5:2d439ccefc7d | 385 | |
DanGibbons | 5:2d439ccefc7d | 386 | case 4: |
DanGibbons | 5:2d439ccefc7d | 387 | seg1A = 0; |
DanGibbons | 5:2d439ccefc7d | 388 | seg1B = 0; |
DanGibbons | 5:2d439ccefc7d | 389 | seg1C = 0; |
DanGibbons | 5:2d439ccefc7d | 390 | seg1D = 0; |
DanGibbons | 5:2d439ccefc7d | 391 | seg1E = 1; |
DanGibbons | 5:2d439ccefc7d | 392 | seg1F = 0; |
DanGibbons | 5:2d439ccefc7d | 393 | seg1G = 0; |
DanGibbons | 5:2d439ccefc7d | 394 | |
DanGibbons | 5:2d439ccefc7d | 395 | SetLEDArray(4); |
DanGibbons | 5:2d439ccefc7d | 396 | break; |
DanGibbons | 5:2d439ccefc7d | 397 | |
DanGibbons | 5:2d439ccefc7d | 398 | case 5: |
DanGibbons | 5:2d439ccefc7d | 399 | seg1A = 0; |
DanGibbons | 5:2d439ccefc7d | 400 | seg1B = 0; |
DanGibbons | 5:2d439ccefc7d | 401 | seg1C = 0; |
DanGibbons | 5:2d439ccefc7d | 402 | seg1D = 0; |
DanGibbons | 5:2d439ccefc7d | 403 | seg1E = 0; |
DanGibbons | 5:2d439ccefc7d | 404 | seg1F = 1; |
DanGibbons | 5:2d439ccefc7d | 405 | seg1G = 0; |
DanGibbons | 5:2d439ccefc7d | 406 | |
DanGibbons | 5:2d439ccefc7d | 407 | SetLEDArray(5); |
DanGibbons | 5:2d439ccefc7d | 408 | break; |
DanGibbons | 5:2d439ccefc7d | 409 | |
DanGibbons | 5:2d439ccefc7d | 410 | default : |
DanGibbons | 5:2d439ccefc7d | 411 | |
DanGibbons | 5:2d439ccefc7d | 412 | break; |
DanGibbons | 5:2d439ccefc7d | 413 | |
DanGibbons | 5:2d439ccefc7d | 414 | } |
DanGibbons | 5:2d439ccefc7d | 415 | |
DanGibbons | 5:2d439ccefc7d | 416 | } |
DanGibbons | 5:2d439ccefc7d | 417 | |
DanGibbons | 5:2d439ccefc7d | 418 | } |
DanGibbons | 5:2d439ccefc7d | 419 | |
benswindell | 0:f2b739e846ae | 420 | // Write segment config to main array |
benswindell | 0:f2b739e846ae | 421 | void SetLEDArray(int x) |
benswindell | 0:f2b739e846ae | 422 | { |
benswindell | 0:f2b739e846ae | 423 | for (int i = 0; i < WS2812_BUF; i++) { |
samuelmoss | 2:ff409472bc08 | 424 | if (i < 18) { |
DanGibbons | 5:2d439ccefc7d | 425 | mainArray[x][i] = seg1A; |
benswindell | 0:f2b739e846ae | 426 | } |
benswindell | 0:f2b739e846ae | 427 | |
samuelmoss | 2:ff409472bc08 | 428 | if ( i >= 18 && i < 35) { |
benswindell | 0:f2b739e846ae | 429 | mainArray[x][i] = seg1B; |
benswindell | 0:f2b739e846ae | 430 | } |
benswindell | 0:f2b739e846ae | 431 | |
samuelmoss | 2:ff409472bc08 | 432 | if (i >= 35 && i < 52) { |
benswindell | 0:f2b739e846ae | 433 | mainArray[x][i] = seg1C; |
benswindell | 0:f2b739e846ae | 434 | } |
benswindell | 0:f2b739e846ae | 435 | |
samuelmoss | 2:ff409472bc08 | 436 | if (i >= 52 && i < 70) { |
benswindell | 0:f2b739e846ae | 437 | mainArray[x][i]= seg1D; |
benswindell | 0:f2b739e846ae | 438 | } |
benswindell | 0:f2b739e846ae | 439 | |
samuelmoss | 2:ff409472bc08 | 440 | if ( i >= 70 && i < 87) { |
benswindell | 0:f2b739e846ae | 441 | mainArray[x][i] = seg1E; |
benswindell | 0:f2b739e846ae | 442 | } |
benswindell | 0:f2b739e846ae | 443 | |
samuelmoss | 2:ff409472bc08 | 444 | if (i >= 87 && i < 104) { |
benswindell | 0:f2b739e846ae | 445 | mainArray[x][i] = seg1F; |
benswindell | 0:f2b739e846ae | 446 | } |
benswindell | 0:f2b739e846ae | 447 | |
samuelmoss | 2:ff409472bc08 | 448 | if ( i >= 104 && i < 122) { |
benswindell | 0:f2b739e846ae | 449 | mainArray[x][i] = seg1G; |
benswindell | 0:f2b739e846ae | 450 | } |
DanGibbons | 4:2e80bd814f57 | 451 | } |
benswindell | 0:f2b739e846ae | 452 | } |
benswindell | 0:f2b739e846ae | 453 | |
benswindell | 1:24bc4d8ed2ae | 454 | // Update both Score LEDs with the current score |
benswindell | 0:f2b739e846ae | 455 | void WriteScores() |
benswindell | 0:f2b739e846ae | 456 | { |
benswindell | 1:24bc4d8ed2ae | 457 | WritePxScores(playerScore,false); |
benswindell | 1:24bc4d8ed2ae | 458 | playerScoreLED.write(playerScorePx.getBuf()); |
benswindell | 0:f2b739e846ae | 459 | wait(0.01); |
benswindell | 1:24bc4d8ed2ae | 460 | WritePxScores(robotScore,true); |
benswindell | 1:24bc4d8ed2ae | 461 | robotScoreLED.write(robotScorePx.getBuf()); |
benswindell | 0:f2b739e846ae | 462 | } |
benswindell | 0:f2b739e846ae | 463 | |
DanGibbons | 5:2d439ccefc7d | 464 | // Write pixel array for Numbers (drawing animation |
benswindell | 1:24bc4d8ed2ae | 465 | void WritePxScores(int line_num,bool isRobot) |
benswindell | 0:f2b739e846ae | 466 | { |
benswindell | 1:24bc4d8ed2ae | 467 | if(isRobot == true) { |
benswindell | 1:24bc4d8ed2ae | 468 | |
benswindell | 1:24bc4d8ed2ae | 469 | for (int i = 0; i < WS2812_BUF; i++) { |
benswindell | 1:24bc4d8ed2ae | 470 | if (mainArray[line_num][i] == 0) { |
benswindell | 1:24bc4d8ed2ae | 471 | robotScorePx.Set(i,OFF); |
benswindell | 1:24bc4d8ed2ae | 472 | } |
benswindell | 1:24bc4d8ed2ae | 473 | |
benswindell | 1:24bc4d8ed2ae | 474 | if (mainArray[line_num][i] == 1) { |
samuelmoss | 2:ff409472bc08 | 475 | robotScorePx.Set(i,BLUE); |
DanGibbons | 5:2d439ccefc7d | 476 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 477 | } |
DanGibbons | 5:2d439ccefc7d | 478 | } |
DanGibbons | 5:2d439ccefc7d | 479 | } else { |
DanGibbons | 5:2d439ccefc7d | 480 | for (int i = 0; i < WS2812_BUF; i++) { |
DanGibbons | 5:2d439ccefc7d | 481 | if (mainArray[line_num][i] == 0) { |
DanGibbons | 5:2d439ccefc7d | 482 | playerScorePx.Set(i,OFF); |
DanGibbons | 5:2d439ccefc7d | 483 | } |
DanGibbons | 5:2d439ccefc7d | 484 | |
DanGibbons | 5:2d439ccefc7d | 485 | if (mainArray[line_num][i] == 1) { |
DanGibbons | 5:2d439ccefc7d | 486 | playerScorePx.Set(i,BLUE); |
DanGibbons | 5:2d439ccefc7d | 487 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 488 | } |
DanGibbons | 5:2d439ccefc7d | 489 | } |
DanGibbons | 5:2d439ccefc7d | 490 | } |
DanGibbons | 5:2d439ccefc7d | 491 | |
DanGibbons | 5:2d439ccefc7d | 492 | } |
DanGibbons | 5:2d439ccefc7d | 493 | |
DanGibbons | 5:2d439ccefc7d | 494 | // Write Pixel array with random colour pattern |
DanGibbons | 5:2d439ccefc7d | 495 | void WritePxScoresRandomColours(int line_num,bool isRobot) |
DanGibbons | 5:2d439ccefc7d | 496 | { |
DanGibbons | 5:2d439ccefc7d | 497 | if(isRobot == true) { |
DanGibbons | 5:2d439ccefc7d | 498 | |
DanGibbons | 5:2d439ccefc7d | 499 | for (int i = 0; i < WS2812_BUF; i++) { |
DanGibbons | 5:2d439ccefc7d | 500 | if (mainArray[line_num][i] == 0) { |
DanGibbons | 5:2d439ccefc7d | 501 | robotScorePx.Set(i,OFF); |
DanGibbons | 5:2d439ccefc7d | 502 | } |
DanGibbons | 5:2d439ccefc7d | 503 | |
DanGibbons | 5:2d439ccefc7d | 504 | if (mainArray[line_num][i] == 1) { |
DanGibbons | 5:2d439ccefc7d | 505 | robotScorePx.Set(i,rand_colors[rand() % 10]); |
DanGibbons | 5:2d439ccefc7d | 506 | } |
DanGibbons | 5:2d439ccefc7d | 507 | } |
DanGibbons | 5:2d439ccefc7d | 508 | } else { |
DanGibbons | 5:2d439ccefc7d | 509 | for (int i = 0; i < WS2812_BUF; i++) { |
DanGibbons | 5:2d439ccefc7d | 510 | if (mainArray[line_num][i] == 0) { |
DanGibbons | 5:2d439ccefc7d | 511 | playerScorePx.Set(i,OFF); |
DanGibbons | 5:2d439ccefc7d | 512 | } |
DanGibbons | 5:2d439ccefc7d | 513 | |
DanGibbons | 5:2d439ccefc7d | 514 | if (mainArray[line_num][i] == 1) { |
DanGibbons | 5:2d439ccefc7d | 515 | playerScorePx.Set(i,rand_colors[rand() % 10]); |
DanGibbons | 5:2d439ccefc7d | 516 | } |
DanGibbons | 5:2d439ccefc7d | 517 | } |
DanGibbons | 5:2d439ccefc7d | 518 | } |
DanGibbons | 5:2d439ccefc7d | 519 | |
DanGibbons | 5:2d439ccefc7d | 520 | } |
DanGibbons | 5:2d439ccefc7d | 521 | |
DanGibbons | 5:2d439ccefc7d | 522 | // Write Pixel array with standard colour |
DanGibbons | 5:2d439ccefc7d | 523 | void WritePxAnimation(int line_num,bool isRobot) |
DanGibbons | 5:2d439ccefc7d | 524 | { |
DanGibbons | 5:2d439ccefc7d | 525 | if(isRobot == true) { |
DanGibbons | 5:2d439ccefc7d | 526 | |
DanGibbons | 5:2d439ccefc7d | 527 | for (int i = 0; i < WS2812_BUF; i++) { |
DanGibbons | 5:2d439ccefc7d | 528 | if (mainArray[line_num][i] == 0) { |
DanGibbons | 5:2d439ccefc7d | 529 | robotScorePx.Set(i,OFF); |
DanGibbons | 5:2d439ccefc7d | 530 | } |
DanGibbons | 5:2d439ccefc7d | 531 | |
DanGibbons | 5:2d439ccefc7d | 532 | if (mainArray[line_num][i] == 1) { |
DanGibbons | 5:2d439ccefc7d | 533 | robotScorePx.Set(i,BLUE); |
benswindell | 1:24bc4d8ed2ae | 534 | } |
benswindell | 0:f2b739e846ae | 535 | } |
benswindell | 1:24bc4d8ed2ae | 536 | } else { |
benswindell | 1:24bc4d8ed2ae | 537 | for (int i = 0; i < WS2812_BUF; i++) { |
benswindell | 1:24bc4d8ed2ae | 538 | if (mainArray[line_num][i] == 0) { |
benswindell | 1:24bc4d8ed2ae | 539 | playerScorePx.Set(i,OFF); |
benswindell | 1:24bc4d8ed2ae | 540 | } |
benswindell | 0:f2b739e846ae | 541 | |
benswindell | 1:24bc4d8ed2ae | 542 | if (mainArray[line_num][i] == 1) { |
samuelmoss | 2:ff409472bc08 | 543 | playerScorePx.Set(i,BLUE); |
benswindell | 1:24bc4d8ed2ae | 544 | } |
benswindell | 1:24bc4d8ed2ae | 545 | } |
benswindell | 1:24bc4d8ed2ae | 546 | } |
benswindell | 1:24bc4d8ed2ae | 547 | |
benswindell | 1:24bc4d8ed2ae | 548 | } |
benswindell | 1:24bc4d8ed2ae | 549 | |
DanGibbons | 5:2d439ccefc7d | 550 | // Handle behaviour for when a goal scored event |
benswindell | 0:f2b739e846ae | 551 | void HandleGoal(bool hasRobotScored) |
benswindell | 0:f2b739e846ae | 552 | { |
DanGibbons | 4:2e80bd814f57 | 553 | GoalAnimation(hasRobotScored); |
benswindell | 1:24bc4d8ed2ae | 554 | |
samuelmoss | 2:ff409472bc08 | 555 | wait(1); |
benswindell | 1:24bc4d8ed2ae | 556 | |
benswindell | 1:24bc4d8ed2ae | 557 | // If either player reaches the score limit, then call HandleWin(). If not, then turn goal LEDs off |
benswindell | 1:24bc4d8ed2ae | 558 | if(robotScore == scoreLimit || playerScore == scoreLimit) { |
benswindell | 1:24bc4d8ed2ae | 559 | HandleWin(); |
samuelmoss | 2:ff409472bc08 | 560 | } |
benswindell | 1:24bc4d8ed2ae | 561 | } |
benswindell | 1:24bc4d8ed2ae | 562 | |
benswindell | 1:24bc4d8ed2ae | 563 | // Handle behaviour when either the player or robot has won a game. |
benswindell | 1:24bc4d8ed2ae | 564 | void HandleWin() |
benswindell | 1:24bc4d8ed2ae | 565 | { |
benswindell | 1:24bc4d8ed2ae | 566 | // Initalise variable as true |
benswindell | 1:24bc4d8ed2ae | 567 | bool isRobotWinner = true; |
benswindell | 1:24bc4d8ed2ae | 568 | |
benswindell | 1:24bc4d8ed2ae | 569 | // Decide if the robot is the winner. If not, then change isRobotWinner to false |
benswindell | 1:24bc4d8ed2ae | 570 | if(playerScore == scoreLimit) { |
DanGibbons | 4:2e80bd814f57 | 571 | |
benswindell | 1:24bc4d8ed2ae | 572 | isRobotWinner = false; |
benswindell | 1:24bc4d8ed2ae | 573 | pc.printf("Player won!"); |
DanGibbons | 4:2e80bd814f57 | 574 | WinAnimation(isRobotWinner); |
benswindell | 1:24bc4d8ed2ae | 575 | |
benswindell | 1:24bc4d8ed2ae | 576 | } else { |
DanGibbons | 4:2e80bd814f57 | 577 | |
benswindell | 1:24bc4d8ed2ae | 578 | pc.printf("Robot won!"); |
DanGibbons | 4:2e80bd814f57 | 579 | WinAnimation(isRobotWinner); |
benswindell | 1:24bc4d8ed2ae | 580 | |
benswindell | 1:24bc4d8ed2ae | 581 | } |
benswindell | 1:24bc4d8ed2ae | 582 | |
benswindell | 1:24bc4d8ed2ae | 583 | // Reset scores then write to LEDs |
benswindell | 1:24bc4d8ed2ae | 584 | robotScore = 0; |
benswindell | 1:24bc4d8ed2ae | 585 | playerScore = 0; |
DanGibbons | 5:2d439ccefc7d | 586 | |
DanGibbons | 5:2d439ccefc7d | 587 | FigureOf8Animation(true,true,2); |
DanGibbons | 5:2d439ccefc7d | 588 | DrainAnimation(true,true,0,true,true,0); |
DanGibbons | 5:2d439ccefc7d | 589 | |
benswindell | 1:24bc4d8ed2ae | 590 | WriteScores(); |
benswindell | 0:f2b739e846ae | 591 | } |
benswindell | 0:f2b739e846ae | 592 | |
DanGibbons | 5:2d439ccefc7d | 593 | // animation for when a goal is scored |
DanGibbons | 4:2e80bd814f57 | 594 | void GoalAnimation(bool hasRobotScored) |
benswindell | 0:f2b739e846ae | 595 | { |
DanGibbons | 4:2e80bd814f57 | 596 | if(hasRobotScored == true) { |
DanGibbons | 4:2e80bd814f57 | 597 | robotScore++; |
DanGibbons | 4:2e80bd814f57 | 598 | robotScorePx.SetAll(0); |
DanGibbons | 4:2e80bd814f57 | 599 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 600 | wait_ms(250); |
DanGibbons | 5:2d439ccefc7d | 601 | FigureOf8Animation(true,false,1); |
DanGibbons | 4:2e80bd814f57 | 602 | WriteScores(); |
DanGibbons | 4:2e80bd814f57 | 603 | |
DanGibbons | 4:2e80bd814f57 | 604 | } else { |
DanGibbons | 4:2e80bd814f57 | 605 | playerScore++; |
DanGibbons | 4:2e80bd814f57 | 606 | playerScorePx.SetAll(0); |
DanGibbons | 4:2e80bd814f57 | 607 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 608 | wait_ms(250); |
DanGibbons | 5:2d439ccefc7d | 609 | FigureOf8Animation(false,true,1); |
DanGibbons | 4:2e80bd814f57 | 610 | WriteScores(); |
DanGibbons | 4:2e80bd814f57 | 611 | } |
DanGibbons | 4:2e80bd814f57 | 612 | |
DanGibbons | 4:2e80bd814f57 | 613 | } |
benswindell | 0:f2b739e846ae | 614 | |
DanGibbons | 5:2d439ccefc7d | 615 | // animation when player or robot win the game |
DanGibbons | 4:2e80bd814f57 | 616 | void WinAnimation(bool isRobotWinner) |
DanGibbons | 4:2e80bd814f57 | 617 | { |
DanGibbons | 4:2e80bd814f57 | 618 | if(isRobotWinner == false) { |
DanGibbons | 4:2e80bd814f57 | 619 | |
DanGibbons | 5:2d439ccefc7d | 620 | //robotScoreLED.setII(0x10); |
DanGibbons | 5:2d439ccefc7d | 621 | |
DanGibbons | 5:2d439ccefc7d | 622 | for (int i = 0; i < 80; i++) { // A |
DanGibbons | 5:2d439ccefc7d | 623 | WritePxScoresRandomColours(playerScore,false); |
DanGibbons | 5:2d439ccefc7d | 624 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 625 | wait_ms(50); |
DanGibbons | 5:2d439ccefc7d | 626 | } |
DanGibbons | 5:2d439ccefc7d | 627 | |
DanGibbons | 5:2d439ccefc7d | 628 | DrainAnimation(true,false,robotScore,true,true,playerScore); |
DanGibbons | 5:2d439ccefc7d | 629 | |
DanGibbons | 4:2e80bd814f57 | 630 | } else { |
DanGibbons | 5:2d439ccefc7d | 631 | |
DanGibbons | 5:2d439ccefc7d | 632 | //playerScoreLED.setII(0x10); |
DanGibbons | 4:2e80bd814f57 | 633 | |
DanGibbons | 5:2d439ccefc7d | 634 | for (int i = 0; i < 80; i++) { // A |
DanGibbons | 5:2d439ccefc7d | 635 | WritePxScoresRandomColours(robotScore,true); |
DanGibbons | 5:2d439ccefc7d | 636 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 637 | wait_ms(50); |
DanGibbons | 5:2d439ccefc7d | 638 | } |
DanGibbons | 4:2e80bd814f57 | 639 | |
DanGibbons | 5:2d439ccefc7d | 640 | DrainAnimation(true,true,robotScore,true,false,playerScore); |
benswindell | 0:f2b739e846ae | 641 | } |
DanGibbons | 4:2e80bd814f57 | 642 | |
DanGibbons | 5:2d439ccefc7d | 643 | |
DanGibbons | 5:2d439ccefc7d | 644 | wait(2); |
DanGibbons | 5:2d439ccefc7d | 645 | |
DanGibbons | 5:2d439ccefc7d | 646 | playerScorePx.SetAll(0); |
DanGibbons | 5:2d439ccefc7d | 647 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 648 | robotScorePx.SetAll(0); |
DanGibbons | 5:2d439ccefc7d | 649 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 650 | |
DanGibbons | 5:2d439ccefc7d | 651 | wait(3); |
DanGibbons | 5:2d439ccefc7d | 652 | |
DanGibbons | 4:2e80bd814f57 | 653 | } |
DanGibbons | 4:2e80bd814f57 | 654 | |
DanGibbons | 5:2d439ccefc7d | 655 | // figure of 8 animation |
DanGibbons | 5:2d439ccefc7d | 656 | void FigureOf8Animation(bool robot, bool player, int numberOfRepetitions) |
DanGibbons | 4:2e80bd814f57 | 657 | { |
DanGibbons | 5:2d439ccefc7d | 658 | SetFigureOf8Pattern(); |
DanGibbons | 5:2d439ccefc7d | 659 | |
DanGibbons | 5:2d439ccefc7d | 660 | for (int i = 0; i < numberOfRepetitions; i++) { |
DanGibbons | 5:2d439ccefc7d | 661 | |
DanGibbons | 4:2e80bd814f57 | 662 | for (int j = 0; j < 8; j++) { |
DanGibbons | 5:2d439ccefc7d | 663 | |
DanGibbons | 5:2d439ccefc7d | 664 | if(robot == true && player == true) { |
DanGibbons | 5:2d439ccefc7d | 665 | WritePxAnimation(j,false); |
DanGibbons | 5:2d439ccefc7d | 666 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 667 | WritePxAnimation(j,true); |
DanGibbons | 5:2d439ccefc7d | 668 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 669 | } else if(robot == true && player == false) { |
DanGibbons | 5:2d439ccefc7d | 670 | WritePxAnimation(j,true); |
DanGibbons | 5:2d439ccefc7d | 671 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 672 | } else if(robot == false && player == true) { |
DanGibbons | 5:2d439ccefc7d | 673 | WritePxAnimation(j,false); |
DanGibbons | 5:2d439ccefc7d | 674 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 675 | } |
DanGibbons | 5:2d439ccefc7d | 676 | |
DanGibbons | 5:2d439ccefc7d | 677 | wait_ms(20); |
DanGibbons | 4:2e80bd814f57 | 678 | |
DanGibbons | 5:2d439ccefc7d | 679 | } |
DanGibbons | 5:2d439ccefc7d | 680 | } |
DanGibbons | 5:2d439ccefc7d | 681 | |
DanGibbons | 5:2d439ccefc7d | 682 | SetNumberPatterns(); |
DanGibbons | 5:2d439ccefc7d | 683 | |
DanGibbons | 5:2d439ccefc7d | 684 | } |
DanGibbons | 5:2d439ccefc7d | 685 | |
DanGibbons | 5:2d439ccefc7d | 686 | // circle animation |
DanGibbons | 5:2d439ccefc7d | 687 | void CircleAnimation(bool robot, bool player, int numberOfRepetitions) |
DanGibbons | 5:2d439ccefc7d | 688 | { |
DanGibbons | 5:2d439ccefc7d | 689 | SetCirclePattern(); |
DanGibbons | 5:2d439ccefc7d | 690 | |
DanGibbons | 5:2d439ccefc7d | 691 | for (int i = 0; i < numberOfRepetitions; i++) { |
DanGibbons | 5:2d439ccefc7d | 692 | |
DanGibbons | 5:2d439ccefc7d | 693 | for (int j = 0; j < 6; j++) { |
DanGibbons | 5:2d439ccefc7d | 694 | |
DanGibbons | 5:2d439ccefc7d | 695 | if(robot == true && player == true) { |
DanGibbons | 5:2d439ccefc7d | 696 | WritePxScores(j,false); |
DanGibbons | 5:2d439ccefc7d | 697 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 698 | WritePxScores(j,true); |
DanGibbons | 5:2d439ccefc7d | 699 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 700 | } else if(robot == true && player == false) { |
DanGibbons | 5:2d439ccefc7d | 701 | WritePxScores(j,true); |
DanGibbons | 5:2d439ccefc7d | 702 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 703 | } else if(robot == false && player == true) { |
DanGibbons | 5:2d439ccefc7d | 704 | WritePxScores(j,false); |
DanGibbons | 5:2d439ccefc7d | 705 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 706 | } |
DanGibbons | 5:2d439ccefc7d | 707 | |
DanGibbons | 5:2d439ccefc7d | 708 | wait_ms(10); |
DanGibbons | 4:2e80bd814f57 | 709 | |
DanGibbons | 4:2e80bd814f57 | 710 | } |
DanGibbons | 4:2e80bd814f57 | 711 | } |
DanGibbons | 5:2d439ccefc7d | 712 | |
DanGibbons | 5:2d439ccefc7d | 713 | SetNumberPatterns(); |
DanGibbons | 5:2d439ccefc7d | 714 | |
DanGibbons | 5:2d439ccefc7d | 715 | } |
DanGibbons | 5:2d439ccefc7d | 716 | |
DanGibbons | 5:2d439ccefc7d | 717 | // animation that drains the display from the top segment A to the bottom segment D |
DanGibbons | 5:2d439ccefc7d | 718 | void DrainAnimation(bool robot, bool robotColour, int robotScore, bool player, bool playerColour, int playerScore) |
DanGibbons | 5:2d439ccefc7d | 719 | { |
DanGibbons | 5:2d439ccefc7d | 720 | if (player == true && robot == true) { |
DanGibbons | 5:2d439ccefc7d | 721 | for (int i = 0; i < 10; i++) { // A |
DanGibbons | 5:2d439ccefc7d | 722 | mainArray[robotScore][9+i] = 0; |
DanGibbons | 5:2d439ccefc7d | 723 | mainArray[robotScore][9-i] = 0; |
DanGibbons | 5:2d439ccefc7d | 724 | mainArray[playerScore][9+i] = 0; |
DanGibbons | 5:2d439ccefc7d | 725 | mainArray[playerScore][9-i] = 0; |
DanGibbons | 5:2d439ccefc7d | 726 | wait_ms(30); |
DanGibbons | 5:2d439ccefc7d | 727 | WritePxScoresRandomColours(playerScore,false); |
DanGibbons | 5:2d439ccefc7d | 728 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 729 | WritePxScoresRandomColours(robotScore,true); |
DanGibbons | 5:2d439ccefc7d | 730 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 731 | } |
DanGibbons | 5:2d439ccefc7d | 732 | for (int i = 0; i < 18; i++) { // B and F |
DanGibbons | 5:2d439ccefc7d | 733 | mainArray[robotScore][18+i] = 0; |
DanGibbons | 5:2d439ccefc7d | 734 | mainArray[robotScore][103-i] = 0; |
DanGibbons | 5:2d439ccefc7d | 735 | mainArray[playerScore][18+i] = 0; |
DanGibbons | 5:2d439ccefc7d | 736 | mainArray[playerScore][103-i] = 0; |
DanGibbons | 5:2d439ccefc7d | 737 | wait_ms(30); |
DanGibbons | 5:2d439ccefc7d | 738 | WritePxScoresRandomColours(playerScore,false); |
DanGibbons | 5:2d439ccefc7d | 739 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 740 | WritePxScoresRandomColours(robotScore,true); |
DanGibbons | 5:2d439ccefc7d | 741 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 742 | } |
DanGibbons | 5:2d439ccefc7d | 743 | for (int i = 0; i < 18; i++) { // G |
DanGibbons | 5:2d439ccefc7d | 744 | mainArray[robotScore][104+i] = 0; |
DanGibbons | 5:2d439ccefc7d | 745 | mainArray[playerScore][104+i] = 0; |
DanGibbons | 5:2d439ccefc7d | 746 | } |
DanGibbons | 5:2d439ccefc7d | 747 | |
DanGibbons | 5:2d439ccefc7d | 748 | WritePxScoresRandomColours(playerScore,false); |
DanGibbons | 5:2d439ccefc7d | 749 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 750 | WritePxScoresRandomColours(robotScore,true); |
DanGibbons | 5:2d439ccefc7d | 751 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 752 | |
DanGibbons | 5:2d439ccefc7d | 753 | for (int i = 0; i < 18; i++) { // C and E |
DanGibbons | 5:2d439ccefc7d | 754 | mainArray[robotScore][35+i] = 0; |
DanGibbons | 5:2d439ccefc7d | 755 | mainArray[robotScore][86-i] = 0; |
DanGibbons | 5:2d439ccefc7d | 756 | mainArray[playerScore][35+i] = 0; |
DanGibbons | 5:2d439ccefc7d | 757 | mainArray[playerScore][86-i] = 0; |
DanGibbons | 5:2d439ccefc7d | 758 | wait_ms(30); |
DanGibbons | 5:2d439ccefc7d | 759 | WritePxScoresRandomColours(playerScore,false); |
DanGibbons | 5:2d439ccefc7d | 760 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 761 | WritePxScoresRandomColours(robotScore,true); |
DanGibbons | 5:2d439ccefc7d | 762 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 763 | } |
DanGibbons | 5:2d439ccefc7d | 764 | for (int i = 0; i < 10; i++) { // D |
DanGibbons | 5:2d439ccefc7d | 765 | mainArray[robotScore][52+i] = 0; |
DanGibbons | 5:2d439ccefc7d | 766 | mainArray[robotScore][70-i] = 0; |
DanGibbons | 5:2d439ccefc7d | 767 | mainArray[playerScore][52+i] = 0; |
DanGibbons | 5:2d439ccefc7d | 768 | mainArray[playerScore][70-i] = 0; |
DanGibbons | 5:2d439ccefc7d | 769 | wait_ms(30); |
DanGibbons | 5:2d439ccefc7d | 770 | WritePxScoresRandomColours(playerScore,false); |
DanGibbons | 5:2d439ccefc7d | 771 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 772 | WritePxScoresRandomColours(robotScore,true); |
DanGibbons | 5:2d439ccefc7d | 773 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 774 | } |
DanGibbons | 5:2d439ccefc7d | 775 | } |
DanGibbons | 5:2d439ccefc7d | 776 | |
DanGibbons | 5:2d439ccefc7d | 777 | if (player == true && robot == false) { |
DanGibbons | 5:2d439ccefc7d | 778 | for (int i = 0; i < 10; i++) { // A |
DanGibbons | 5:2d439ccefc7d | 779 | mainArray[playerScore][9+i] = 0; |
DanGibbons | 5:2d439ccefc7d | 780 | mainArray[playerScore][9-i] = 0; |
DanGibbons | 5:2d439ccefc7d | 781 | wait_ms(30); |
DanGibbons | 5:2d439ccefc7d | 782 | WritePxScores(playerScore,false); |
DanGibbons | 5:2d439ccefc7d | 783 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 784 | } |
DanGibbons | 5:2d439ccefc7d | 785 | for (int i = 0; i < 18; i++) { // B and F |
DanGibbons | 5:2d439ccefc7d | 786 | mainArray[playerScore][18+i] = 0; |
DanGibbons | 5:2d439ccefc7d | 787 | mainArray[playerScore][103-i] = 0; |
DanGibbons | 5:2d439ccefc7d | 788 | wait_ms(30); |
DanGibbons | 5:2d439ccefc7d | 789 | WritePxScores(playerScore,false); |
DanGibbons | 5:2d439ccefc7d | 790 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 791 | } |
DanGibbons | 5:2d439ccefc7d | 792 | for (int i = 0; i < 18; i++) { // G |
DanGibbons | 5:2d439ccefc7d | 793 | mainArray[playerScore][104+i] = 0; |
DanGibbons | 5:2d439ccefc7d | 794 | wait_ms(30); |
DanGibbons | 5:2d439ccefc7d | 795 | WritePxScores(playerScore,false); |
DanGibbons | 5:2d439ccefc7d | 796 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 797 | } |
DanGibbons | 5:2d439ccefc7d | 798 | for (int i = 0; i < 18; i++) { // C and E |
DanGibbons | 5:2d439ccefc7d | 799 | mainArray[playerScore][35+i] = 0; |
DanGibbons | 5:2d439ccefc7d | 800 | mainArray[playerScore][86-i] = 0; |
DanGibbons | 5:2d439ccefc7d | 801 | wait_ms(30); |
DanGibbons | 5:2d439ccefc7d | 802 | WritePxScores(playerScore,false); |
DanGibbons | 5:2d439ccefc7d | 803 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 804 | } |
DanGibbons | 5:2d439ccefc7d | 805 | for (int i = 0; i < 10; i++) { // D |
DanGibbons | 5:2d439ccefc7d | 806 | mainArray[playerScore][52+i] = 0; |
DanGibbons | 5:2d439ccefc7d | 807 | mainArray[playerScore][70-i] = 0; |
DanGibbons | 5:2d439ccefc7d | 808 | wait_ms(30); |
DanGibbons | 5:2d439ccefc7d | 809 | WritePxScores(playerScore,false); |
DanGibbons | 5:2d439ccefc7d | 810 | playerScoreLED.write(playerScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 811 | } |
DanGibbons | 5:2d439ccefc7d | 812 | } |
DanGibbons | 5:2d439ccefc7d | 813 | |
DanGibbons | 5:2d439ccefc7d | 814 | if (player == false && robot == true) { |
DanGibbons | 5:2d439ccefc7d | 815 | for (int i = 0; i < 10; i++) { // A |
DanGibbons | 5:2d439ccefc7d | 816 | mainArray[robotScore][9+i] = 0; |
DanGibbons | 5:2d439ccefc7d | 817 | mainArray[robotScore][9-i] = 0; |
DanGibbons | 5:2d439ccefc7d | 818 | wait_ms(30); |
DanGibbons | 5:2d439ccefc7d | 819 | WritePxScores(robotScore,true); |
DanGibbons | 5:2d439ccefc7d | 820 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 821 | } |
DanGibbons | 5:2d439ccefc7d | 822 | for (int i = 0; i < 18; i++) { // B and F |
DanGibbons | 5:2d439ccefc7d | 823 | mainArray[robotScore][18+i] = 0; |
DanGibbons | 5:2d439ccefc7d | 824 | mainArray[robotScore][103-i] = 0; |
DanGibbons | 5:2d439ccefc7d | 825 | wait_ms(30); |
DanGibbons | 5:2d439ccefc7d | 826 | WritePxScores(robotScore,true); |
DanGibbons | 5:2d439ccefc7d | 827 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 828 | } |
DanGibbons | 5:2d439ccefc7d | 829 | for (int i = 0; i < 18; i++) { // G |
DanGibbons | 5:2d439ccefc7d | 830 | mainArray[robotScore][104+i] = 0; |
DanGibbons | 5:2d439ccefc7d | 831 | wait_ms(30); |
DanGibbons | 5:2d439ccefc7d | 832 | WritePxScores(robotScore,true); |
DanGibbons | 5:2d439ccefc7d | 833 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 834 | } |
DanGibbons | 5:2d439ccefc7d | 835 | for (int i = 0; i < 18; i++) { // C and E |
DanGibbons | 5:2d439ccefc7d | 836 | mainArray[robotScore][35+i] = 0; |
DanGibbons | 5:2d439ccefc7d | 837 | mainArray[robotScore][86-i] = 0; |
DanGibbons | 5:2d439ccefc7d | 838 | wait_ms(30); |
DanGibbons | 5:2d439ccefc7d | 839 | WritePxScores(robotScore,true); |
DanGibbons | 5:2d439ccefc7d | 840 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 841 | } |
DanGibbons | 5:2d439ccefc7d | 842 | for (int i = 0; i < 10; i++) { // D |
DanGibbons | 5:2d439ccefc7d | 843 | mainArray[robotScore][52+i] = 0; |
DanGibbons | 5:2d439ccefc7d | 844 | mainArray[robotScore][70-i] = 0; |
DanGibbons | 5:2d439ccefc7d | 845 | wait_ms(30); |
DanGibbons | 5:2d439ccefc7d | 846 | WritePxScores(robotScore,true); |
DanGibbons | 5:2d439ccefc7d | 847 | robotScoreLED.write(robotScorePx.getBuf()); |
DanGibbons | 5:2d439ccefc7d | 848 | } |
DanGibbons | 5:2d439ccefc7d | 849 | } |
DanGibbons | 5:2d439ccefc7d | 850 | |
DanGibbons | 5:2d439ccefc7d | 851 | SetNumberPatterns(); |
DanGibbons | 5:2d439ccefc7d | 852 | |
DanGibbons | 5:2d439ccefc7d | 853 | } |
DanGibbons | 5:2d439ccefc7d | 854 |