Components and supplies
Rotary Potentiometer, 10 kohm
Capacitor 22 µF
Alphanumeric LCD, 16 x 2
Resistor 10k ohm
Resistor 220 ohm
Capacitor 1000 µF
Arduino Nano R3
Slide Switch
9V battery (generic)
Pushbutton switch 12mm
Tools and machines
Soldering iron (generic)
Project description
Code
Multi_Player_Score_Tracker.ino
arduino
1#include <LiquidCrystal.h> 2#include <MsTimer2.h> 3#include <EEPROM.h> 4 5#define MAX_PLAYERS 50 // maximum allowed, depends on EEPROM size & memory available 6#define MIN_PLAYERS 1 // minimum players needed 7#define debounce 50 // switch debounce time, in milli seconds 8#define HOLDTIME 2000 // for switch long click , in milli seconds 9#define INT_SIZE 2 10#define MAX_SCORE_STEP 10 // maximum number allowed for scoreStep variable 11 12int players; 13int scoreStep = 1 ; // default value for score increase/decrease by this number 14int currentPlayer; 15int playerButtonState; 16int upButtonState; 17int dnButtonState; 18int mode = 0 ; // operation modes: 0 = view score, 1 = update score , 2 = configure 19int POINTS[MAX_PLAYERS+1] ; // runtime score stored in an array 20unsigned long configWait; 21boolean configStarted = LOW; 22int configMode = 1; // configuration modes: 1 = no of players, 2 = reset score , 3 = score STEP 23boolean resetScore = LOW; 24LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // initialize LCD 25 26 27// ++++++++++ BEGIN: Class sButton ++++++++++ 28// orginal button click logic is from http://jmsarduino.blogspot.com 29// I did convert it into a Class so that I can create multiple objects 30class sButton { 31 const byte pin; 32 int state; 33 int prevState; 34 int overallState; // 0 = not clicked , 1 = short click , 2 = long click (hold) 35 boolean ignoreUp; 36 boolean hold; 37 unsigned long buttonUpMs; 38 unsigned long buttonDownMs; 39 40 41 public: 42 sButton(byte attachTo) : 43 pin(attachTo) 44 { 45 } 46 47 void setup() { 48 pinMode(pin, INPUT_PULLUP); 49 state = LOW; 50 hold = false; 51 prevState = LOW; 52 ignoreUp = false; 53 } 54 55 int stateCheck() { 56 overallState = 0; 57 state = digitalRead(pin); 58 // Test for button pressed and store the down time 59 if (state == LOW && prevState == HIGH && (millis() - buttonUpMs ) > long(debounce)) 60 { 61 buttonDownMs = millis(); 62 } 63 // Test for button release and store the up time 64 if (state == HIGH && prevState == LOW && (millis() - buttonDownMs) > long(debounce)) 65 { 66 if (ignoreUp == false) { 67 overallState = 1; 68 } 69 else ignoreUp = false; 70 buttonUpMs = millis(); 71 } 72 73 // Test for button held down for longer than the hold time 74 if (state == LOW && (millis() - buttonDownMs) > long(HOLDTIME)) 75 { 76 ignoreUp = true; 77 hold = true; 78 buttonDownMs = millis(); 79 overallState = 2; 80 } 81 82 prevState = state; 83 return overallState; 84 } 85}; 86// ------------END: Class sButton -------------- 87 88 89 90// +++++++++++++ Main : Starts here ++++++++++++++++ 91 92sButton playerButton(4); // initilaize didital pin 4 for Player sellection 93sButton upButton(5); // initialize digitla pin 5 for score increment operation 94sButton dnButton(6); // initialize digital pin 6 for score decrement operaiton 95 96void setup() { 97 playerButton.setup(); 98 upButton.setup(); 99 dnButton.setup(); 100 initScores(); 101 MsTimer2::set(10, powerLossDetector); // 10ms timer to check powerloss 102 MsTimer2::start(); 103 lcd.begin(16, 2); 104 currentPlayer=0; 105 showWelcome(); 106} 107 108void loop() { 109 playerButtonState = playerButton.stateCheck(); 110 upButtonState = upButton.stateCheck(); 111 dnButtonState = dnButton.stateCheck(); 112 113 // +++ BEGIN: Block for handling configuration +++++++++ 114 // In confure mode number of players can be set & can reset every player's score to 0 115 // 116 // config mode begins by holding upbutton for HOLDTIME 117 if (upButtonState == 2 || mode == 2 ) { 118 if (mode != 2 ) { 119 configWait = millis(); // config mode begins, up button in hold, waititng for dn button 120 } 121 mode = 2; 122 if (dnButtonState == 2) { // dn button also held for HOLDTIME 123 configStarted = HIGH; // now we enter into configuraiton mode 124 lcd.clear(); 125 } 126 127 // to return back to view mode if the dn button wasnt long-clicked within HOLDTIME window 128 if (millis() - configWait > HOLDTIME && configStarted == LOW) mode = 0; 129 130 if (configStarted == HIGH) { // now we are in configuraiton mode 131 switch(configMode){ 132 case 1: doPlayerCountConfig(); break; 133 case 2: doResetScore(); break; 134 case 3: doScoreStep(); break; 135 default: break; 136 } 137 138 if ( playerButtonState == 1) { // changing config mode 139 switch (configMode) { 140 case 1: configMode = 2 ; playerButtonState = 0 ; lcd.clear(); break; 141 case 2: configMode = 3 ; playerButtonState = 0 ; lcd.clear(); break; 142 case 3: configMode = 1 ; playerButtonState = 0 ; lcd.clear(); break; 143 default: break; 144 } 145 } 146 147 if ( playerButtonState == 2) { // exit from configuration mode 148 mode = 0; 149 configMode = 1 ; 150 showWelcome(); 151 } 152 } 153 154 // returning to the begining op loop as we are in configuraiton mode 155 return ; 156 } 157 configStarted = LOW; 158 // ---- END: Block for handling configuration (number of players) --------- 159 160 161 162 // +++ BEGIN: Block for updating score of each player +++++++++ 163 if ( playerButtonState == 1) { // jump to update score mode if update button pressed 164 lcd.clear(); 165 if (currentPlayer == 0) currentPlayer++; 166 if (mode == 1 ) currentPlayer++; // move to next player 167 mode = 1; 168 if (currentPlayer > players ) currentPlayer = 1 ; 169 } 170 171 if (mode == 1 ) { // to stay in update score mode, show score on display 172 doUpdateScore(); 173 } 174 // ---- END: Block for updating score of each player ------- 175 176 177 178 // +++ BEGIN: Block for displaying score of each player +++++++++ 179 if (mode == 0 && (upButtonState == 1 || dnButtonState == 1)) { // to view score 180 lcd.clear(); 181 showPlayerScore(); 182 } 183 // --- END : Block for displaying score of each player -------- 184 185 186 // +++ BEGIN: Block for exiting from any mode to welcome screen +++++++++ 187 if ( playerButtonState == 2) { // to exit from current mode to home screen 188 mode = 0 ; 189 currentPlayer = 0 ; 190 showWelcome(); 191 } 192 // ---- END: Block for exiting from any mode to welcome screen -------- 193 194} 195 196// ------------- Main : Ends here --------------- 197 198 199// function for showing welcome screen 200void showWelcome() { 201 if (resetScore == HIGH ) { 202 for (int p = 1 ; p <= players ; p++ ) { 203 POINTS[p]=0; 204 } 205 206 resetScore = LOW; 207 } 208 209 lcd.clear(); 210 lcd.print ("*Score Tracker*"); 211 lcd.setCursor(0, 1); 212 lcd.print ("No of players "); 213 lcd.print (players); 214 lcd.noBlink(); 215} 216 217 218// function for showing individual player's score 219void showPlayerScore () { 220 if (upButtonState == 1 ) currentPlayer++ ; 221 if (dnButtonState == 1) currentPlayer--; 222 if (currentPlayer > players) currentPlayer = 1; 223 if (currentPlayer < 1) currentPlayer = players; 224 lcd.setCursor(0, 0); 225 lcd.print ("View score:"); 226 lcd.setCursor(0, 1); 227 lcd.print ("Player "); 228 lcd.print (currentPlayer); 229 lcd.print (" = "); 230 lcd.print (POINTS[currentPlayer]); 231 lcd.print (" "); 232} 233 234// function for updating individual player's score 235void doUpdateScore () { 236 lcd.setCursor(0, 0); 237 lcd.print ("Update score:"); 238 lcd.setCursor(0, 1); 239 lcd.print ("Player "); 240 lcd.print (currentPlayer); 241 lcd.print (" = "); 242 lcd.print (POINTS[currentPlayer]); 243 lcd.print (" "); 244 245 if (mode == 1 && upButtonState == 1) { // increment score if up button pressed 246 POINTS[currentPlayer] += scoreStep; 247 } 248 if (mode == 1 && dnButtonState == 1) { // decrement point if down button pressed 249 if (POINTS[currentPlayer] != 0 ) 250 POINTS[currentPlayer] -= scoreStep; 251 } 252} 253 254// function for reset all player's score 255void doResetScore() { 256 lcd.setCursor(0, 0); 257 lcd.print("Configure: Reset"); 258 lcd.setCursor(0, 1); 259 lcd.print("score ? "); 260 if (resetScore == LOW ) { 261 lcd.print("NO "); 262 } else { 263 lcd.print("YES"); 264 } 265 266 if (upButtonState == 1) { // increment score if up button pressed 267 resetScore = HIGH; 268 } 269 if (dnButtonState == 1) { // decrement point if down button pressed 270 resetScore = LOW; 271 } 272} 273 274// function for configuring number of players 275void doPlayerCountConfig () { 276 lcd.setCursor(0, 0); 277 lcd.print ("Configure: No of "); 278 lcd.setCursor(0, 1); 279 lcd.print("Players = "); 280 lcd.print(players); 281 lcd.print(" "); 282 if (upButtonState == 1) { // increment number of players 283 players++; 284 if (players > MAX_PLAYERS) { 285 players = MAX_PLAYERS; // limiting players to MAX_PLAYERS 286 } 287 } 288 if (dnButtonState == 1) { // decement number of players 289 players--; 290 if (players < MIN_PLAYERS) { 291 players = MIN_PLAYERS; 292 } 293 294 } 295} 296 297 298// function for configuring sccore increase/decrease step 299void doScoreStep () { 300 lcd.setCursor(0, 0); 301 lcd.print ("Configure: Score "); 302 lcd.setCursor(0, 1); 303 lcd.print("Step = "); 304 lcd.print(scoreStep); 305 lcd.print(" "); 306 if (upButtonState == 1) { // increment number of players 307 scoreStep++; 308 if (scoreStep > MAX_SCORE_STEP ) { 309 scoreStep = MAX_SCORE_STEP; 310 } 311 } 312 if (dnButtonState == 1) { // decement number of players 313 scoreStep--; 314 if (scoreStep < 1 ) { 315 scoreStep = 1; // minimum step value is 1 316 } 317 318 } 319} 320 321 322// function called by timer to detect power loss and save into EEPROM 323// coutrsey to Darieee's youtube video on power losss detection 324void powerLossDetector () { 325 int eeAddress = 0; 326 int eeValue = 0; 327 digitalWrite(LED_BUILTIN, LOW); 328 if (analogRead(A3) < 920) { 329 pinMode(A3, OUTPUT); 330 digitalWrite (A3, HIGH); 331 return; 332 } 333 334 pinMode(A3, INPUT); 335 if (analogRead(A3) > 1000) { // this happens only when power fails 336 eeAddress = 0; 337 EEPROM.put( eeAddress, players); 338 eeAddress+=INT_SIZE; 339 EEPROM.put( eeAddress, scoreStep); 340 eeAddress+=INT_SIZE; 341 for(int i=1; i<=players; i++) { 342 EEPROM.put( eeAddress, POINTS[i]); // save score into EEPROM 343 eeAddress+=INT_SIZE; 344 } 345 MsTimer2::stop(); 346 digitalWrite(LED_BUILTIN, HIGH); 347 } 348} 349 350// function to read from EEPROM and initailize score 351void initScores() { 352 int eeAddress = 512; // address 512 for tracking EEPROM usage 353 int eeValue = 0; 354 EEPROM.get( eeAddress, eeValue); 355 if (eeValue != 89 ) { // looks like a fresh EEPROM 356 EEPROM.put( eeAddress, 89); 357 players = MIN_PLAYERS; 358 eeAddress = 0; 359 EEPROM.put( eeAddress, players); 360 eeAddress+=INT_SIZE; 361 EEPROM.put( eeAddress, scoreStep); 362 for(int i=1; i<=players; i++) { 363 eeAddress+=INT_SIZE; 364 EEPROM.put( eeAddress, POINTS[i]); 365 } 366 return; 367 } 368 eeAddress = 0; 369 EEPROM.get( eeAddress, players); 370 eeAddress+=INT_SIZE; 371 EEPROM.get( eeAddress, scoreStep); 372 373 for(int i=1; i<=players; i++) { 374 eeAddress+=INT_SIZE; 375 EEPROM.get( eeAddress, eeValue); 376 POINTS[i]=eeValue; 377 } 378} 379
Multi_Player_Score_Tracker.ino
arduino
1#include <LiquidCrystal.h> 2#include <MsTimer2.h> 3#include <EEPROM.h> 4 5#define 6 MAX_PLAYERS 50 // maximum allowed, depends on EEPROM size & memory available 7#define 8 MIN_PLAYERS 1 // minimum players needed 9#define debounce 50 // switch 10 debounce time, in milli seconds 11#define HOLDTIME 2000 // for switch long 12 click , in milli seconds 13#define INT_SIZE 2 14#define MAX_SCORE_STEP 10 // maximum 15 number allowed for scoreStep variable 16 17int players; 18int scoreStep = 1 ; 19 // default value for score increase/decrease by this number 20int currentPlayer; 21int 22 playerButtonState; 23int upButtonState; 24int dnButtonState; 25int mode = 0 ; 26 // operation modes: 0 = view score, 1 = update score , 2 = configure 27int POINTS[MAX_PLAYERS+1] 28 ; // runtime score stored in an array 29unsigned long configWait; 30boolean 31 configStarted = LOW; 32int configMode = 1; // configuration modes: 1 = no of players, 33 2 = reset score , 3 = score STEP 34boolean resetScore = LOW; 35LiquidCrystal lcd(7, 36 8, 9, 10, 11, 12); // initialize LCD 37 38 39// ++++++++++ BEGIN: Class sButton 40 ++++++++++ 41// orginal button click logic is from http://jmsarduino.blogspot.com 42// 43 I did convert it into a Class so that I can create multiple objects 44class sButton 45 { 46 const byte pin; 47 int state; 48 int prevState; 49 int overallState; 50 // 0 = not clicked , 1 = short click , 2 = long click (hold) 51 boolean ignoreUp; 52 53 boolean hold; 54 unsigned long buttonUpMs; 55 unsigned long buttonDownMs; 56 57 58 59 public: 60 sButton(byte attachTo) : 61 pin(attachTo) 62 63 { 64 } 65 66 void setup() { 67 pinMode(pin, INPUT_PULLUP); 68 69 state = LOW; 70 hold = false; 71 prevState = LOW; 72 ignoreUp 73 = false; 74 } 75 76 int stateCheck() { 77 overallState = 0; 78 state 79 = digitalRead(pin); 80 // Test for button pressed and store the down time 81 82 if (state == LOW && prevState == HIGH && (millis() - buttonUpMs ) > long(debounce)) 83 84 { 85 buttonDownMs = millis(); 86 } 87 // Test for button 88 release and store the up time 89 if (state == HIGH && prevState == LOW && 90 (millis() - buttonDownMs) > long(debounce)) 91 { 92 if (ignoreUp == 93 false) { 94 overallState = 1; 95 } 96 else ignoreUp 97 = false; 98 buttonUpMs = millis(); 99 } 100 101 // Test 102 for button held down for longer than the hold time 103 if (state == LOW && (millis() 104 - buttonDownMs) > long(HOLDTIME)) 105 { 106 ignoreUp = true; 107 hold 108 = true; 109 buttonDownMs = millis(); 110 overallState = 2; 111 } 112 113 114 prevState = state; 115 return overallState; 116 } 117}; 118// 119 ------------END: Class sButton -------------- 120 121 122 123// +++++++++++++ Main 124 : Starts here ++++++++++++++++ 125 126sButton playerButton(4); // initilaize 127 didital pin 4 for Player sellection 128sButton upButton(5); // initialize 129 digitla pin 5 for score increment operation 130sButton dnButton(6); // 131 initialize digital pin 6 for score decrement operaiton 132 133void setup() { 134 135 playerButton.setup(); 136 upButton.setup(); 137 dnButton.setup(); 138 initScores(); 139 140 MsTimer2::set(10, powerLossDetector); // 10ms timer to check powerloss 141 MsTimer2::start(); 142 143 lcd.begin(16, 2); 144 currentPlayer=0; 145 showWelcome(); 146} 147 148void loop() 149 { 150 playerButtonState = playerButton.stateCheck(); 151 upButtonState = upButton.stateCheck(); 152 153 dnButtonState = dnButton.stateCheck(); 154 155 // +++ BEGIN: Block for handling 156 configuration +++++++++ 157 // In confure mode number of players can be set & 158 can reset every player's score to 0 159 // 160 // config mode begins by holding 161 upbutton for HOLDTIME 162 if (upButtonState == 2 || mode == 2 ) { 163 if (mode 164 != 2 ) { 165 configWait = millis(); // config mode begins, up button 166 in hold, waititng for dn button 167 } 168 mode = 2; 169 if (dnButtonState 170 == 2) { // dn button also held for HOLDTIME 171 configStarted = 172 HIGH; // now we enter into configuraiton mode 173 lcd.clear(); 174 175 } 176 177 // to return back to view mode if the dn button wasnt long-clicked 178 within HOLDTIME window 179 if (millis() - configWait > HOLDTIME && configStarted 180 == LOW) mode = 0; 181 182 if (configStarted == HIGH) { // now we 183 are in configuraiton mode 184 switch(configMode){ 185 case 1: doPlayerCountConfig(); 186 break; 187 case 2: doResetScore(); break; 188 case 3: doScoreStep(); 189 break; 190 default: break; 191 } 192 193 if ( playerButtonState 194 == 1) { // changing config mode 195 switch (configMode) { 196 case 197 1: configMode = 2 ; playerButtonState = 0 ; lcd.clear(); break; 198 case 199 2: configMode = 3 ; playerButtonState = 0 ; lcd.clear(); break; 200 case 201 3: configMode = 1 ; playerButtonState = 0 ; lcd.clear(); break; 202 default: 203 break; 204 } 205 } 206 207 if ( playerButtonState == 2) { // 208 exit from configuration mode 209 mode = 0; 210 configMode = 1 211 ; 212 showWelcome(); 213 } 214 } 215 216 // returning to the 217 begining op loop as we are in configuraiton mode 218 return ; 219 } 220 221 configStarted = LOW; 222 // ---- END: Block for handling configuration (number 223 of players) --------- 224 225 226 227 // +++ BEGIN: Block for updating score 228 of each player +++++++++ 229 if ( playerButtonState == 1) { // jump to update 230 score mode if update button pressed 231 lcd.clear(); 232 if (currentPlayer 233 == 0) currentPlayer++; 234 if (mode == 1 ) currentPlayer++; // move to next 235 player 236 mode = 1; 237 if (currentPlayer > players ) currentPlayer = 1 ; 238 239 } 240 241 if (mode == 1 ) { // to stay in update score mode, show 242 score on display 243 doUpdateScore(); 244 } 245 // ---- END: Block for updating 246 score of each player ------- 247 248 249 250 // +++ BEGIN: Block for displaying 251 score of each player +++++++++ 252 if (mode == 0 && (upButtonState == 1 || dnButtonState 253 == 1)) { // to view score 254 lcd.clear(); 255 showPlayerScore(); 256 } 257 258 // --- END : Block for displaying score of each player -------- 259 260 261 // 262 +++ BEGIN: Block for exiting from any mode to welcome screen +++++++++ 263 264 if ( playerButtonState == 2) { // to exit from current mode to home screen 265 266 mode = 0 ; 267 currentPlayer = 0 ; 268 showWelcome(); 269 270 } 271 // ---- END: Block for exiting from any mode to welcome screen -------- 272 273 274} 275 276// ------------- Main : Ends here --------------- 277 278 279// 280 function for showing welcome screen 281void showWelcome() { 282 if (resetScore 283 == HIGH ) { 284 for (int p = 1 ; p <= players ; p++ ) { 285 POINTS[p]=0; 286 287 } 288 289 resetScore = LOW; 290 } 291 292 lcd.clear(); 293 lcd.print 294 ("*Score Tracker*"); 295 lcd.setCursor(0, 1); 296 lcd.print ("No of players 297 "); 298 lcd.print (players); 299 lcd.noBlink(); 300} 301 302 303// function for 304 showing individual player's score 305void showPlayerScore () { 306 if (upButtonState 307 == 1 ) currentPlayer++ ; 308 if (dnButtonState == 1) currentPlayer--; 309 if 310 (currentPlayer > players) currentPlayer = 1; 311 if (currentPlayer < 1) currentPlayer 312 = players; 313 lcd.setCursor(0, 0); 314 lcd.print ("View score:"); 315 lcd.setCursor(0, 316 1); 317 lcd.print ("Player "); 318 lcd.print (currentPlayer); 319 lcd.print 320 (" = "); 321 lcd.print (POINTS[currentPlayer]); 322 lcd.print (" "); 323} 324 325// 326 function for updating individual player's score 327void doUpdateScore () { 328 lcd.setCursor(0, 329 0); 330 lcd.print ("Update score:"); 331 lcd.setCursor(0, 1); 332 lcd.print 333 ("Player "); 334 lcd.print (currentPlayer); 335 lcd.print (" = "); 336 337 lcd.print (POINTS[currentPlayer]); 338 lcd.print (" "); 339 340 if 341 (mode == 1 && upButtonState == 1) { // increment score if up button pressed 342 343 POINTS[currentPlayer] += scoreStep; 344 } 345 if (mode == 1 && dnButtonState 346 == 1) { // decrement point if down button pressed 347 if (POINTS[currentPlayer] 348 != 0 ) 349 POINTS[currentPlayer] -= scoreStep; 350 } 351} 352 353// function 354 for reset all player's score 355void doResetScore() { 356 lcd.setCursor(0, 0); 357 358 lcd.print("Configure: Reset"); 359 lcd.setCursor(0, 1); 360 lcd.print("score 361 ? "); 362 if (resetScore == LOW ) { 363 lcd.print("NO "); 364 } else { 365 366 lcd.print("YES"); 367 } 368 369 if (upButtonState == 1) { // increment 370 score if up button pressed 371 resetScore = HIGH; 372 } 373 if (dnButtonState 374 == 1) { // decrement point if down button pressed 375 resetScore = LOW; 376 377 } 378} 379 380// function for configuring number of players 381void doPlayerCountConfig 382 () { 383 lcd.setCursor(0, 0); 384 lcd.print ("Configure: No of "); 385 386 lcd.setCursor(0, 1); 387 lcd.print("Players = "); 388 lcd.print(players); 389 390 lcd.print(" "); 391 if (upButtonState == 1) { // increment number 392 of players 393 players++; 394 if (players > MAX_PLAYERS) { 395 396 players = MAX_PLAYERS; // limiting players to MAX_PLAYERS 397 398 } 399 } 400 if (dnButtonState == 1) { // decement number 401 of players 402 players--; 403 if (players < MIN_PLAYERS) { 404 players 405 = MIN_PLAYERS; 406 } 407 408 } 409} 410 411 412// function 413 for configuring sccore increase/decrease step 414void doScoreStep () { 415 lcd.setCursor(0, 416 0); 417 lcd.print ("Configure: Score "); 418 lcd.setCursor(0, 1); 419 420 lcd.print("Step = "); 421 lcd.print(scoreStep); 422 lcd.print(" 423 "); 424 if (upButtonState == 1) { // increment number of players 425 426 scoreStep++; 427 if (scoreStep > MAX_SCORE_STEP ) { 428 scoreStep 429 = MAX_SCORE_STEP; 430 } 431 } 432 if (dnButtonState == 1) { // 433 decement number of players 434 scoreStep--; 435 if (scoreStep < 1 436 ) { 437 scoreStep = 1; // minimum step value is 1 438 } 439 440 441 } 442} 443 444 445// function called by timer to detect power 446 loss and save into EEPROM 447// coutrsey to Darieee's youtube video on power losss 448 detection 449void powerLossDetector () { 450 int eeAddress = 0; 451 int eeValue 452 = 0; 453 digitalWrite(LED_BUILTIN, LOW); 454 if (analogRead(A3) < 920) { 455 pinMode(A3, 456 OUTPUT); 457 digitalWrite (A3, HIGH); 458 return; 459 } 460 461 pinMode(A3, 462 INPUT); 463 if (analogRead(A3) > 1000) { // this happens only when power fails 464 465 eeAddress = 0; 466 EEPROM.put( eeAddress, players); 467 eeAddress+=INT_SIZE; 468 469 EEPROM.put( eeAddress, scoreStep); 470 eeAddress+=INT_SIZE; 471 for(int 472 i=1; i<=players; i++) { 473 EEPROM.put( eeAddress, POINTS[i]); // save score 474 into EEPROM 475 eeAddress+=INT_SIZE; 476 } 477 MsTimer2::stop(); 478 479 digitalWrite(LED_BUILTIN, HIGH); 480 } 481} 482 483// function to read from 484 EEPROM and initailize score 485void initScores() { 486 int eeAddress = 512; // 487 address 512 for tracking EEPROM usage 488 int eeValue = 0; 489 EEPROM.get( eeAddress, 490 eeValue); 491 if (eeValue != 89 ) { // looks like a fresh EEPROM 492 EEPROM.put( 493 eeAddress, 89); 494 players = MIN_PLAYERS; 495 eeAddress = 0; 496 EEPROM.put( 497 eeAddress, players); 498 eeAddress+=INT_SIZE; 499 EEPROM.put( eeAddress, scoreStep); 500 501 for(int i=1; i<=players; i++) { 502 eeAddress+=INT_SIZE; 503 EEPROM.put( 504 eeAddress, POINTS[i]); 505 } 506 return; 507 } 508 eeAddress = 0; 509 EEPROM.get( 510 eeAddress, players); 511 eeAddress+=INT_SIZE; 512 EEPROM.get( eeAddress, scoreStep); 513 514 515 for(int i=1; i<=players; i++) { 516 eeAddress+=INT_SIZE; 517 EEPROM.get( 518 eeAddress, eeValue); 519 POINTS[i]=eeValue; 520 } 521} 522
Downloadable files
MPST Schematic diagram
MPST Schematic diagram
MPST Schematic diagram
MPST Schematic diagram
Documentation
Prototype unit inside view
Prototype unit inside view
Prototype unit outside view
Prototype unit outside view
Prototype unit outside view
Prototype unit outside view
Prototype unit inside view
Prototype unit inside view
Component wiring diagram
Component wiring diagram
Comments
Only logged in users can leave comments
Anonymous user
5 years ago
Hi, I'm doing this for a school project and have built your design on an Arduino Uno; however, I'm having a bit of trouble with the coding. Whenever I copy the code into the Arduno application, I get the following message: 'compilation terminated. Error compiling.' I am not 100% sure whats wrong with the coding for it to be having these issues and I'm not very experienced in this. Has anyone got any clue as to how to fix this error? Thanks so much.