Arduino Conversion of an EM Pinball Machine
Conversion of an old pinball playfield to an Arduino-driven, fully working pinball machine.
Components and supplies
1
WS2812 LEDs
1
MAX7219 LED display
1
Molex connectors
1
Arduino UNO
1
Arduino Mega 2560
1
IRL540N MOSFET
Project description
Code
Arduino controlled Pinball Machine Code
arduino
Allows the Arduino to control the game play of a home made pinball machine. Controls lights, sensors, voltage to coils, scoring, etc.
1 2#include <Wire.h> 3#include "LedControl.h" 4#include <EEPROMex.h> 5//////////////////LED///////////////////// 6#include <FastLED.h> 7#define NUM_LEDS 38 8#define NUM_LEDS2 14 9#define DATA_PIN 8 10#define DATA_PIN2 9 11#define BRIGHTNESS 255 12CRGB leds[NUM_LEDS]; 13CRGB ledsbig[NUM_LEDS2]; 14 15//////////////////LED///////////////////// 16 17LedControl lc=LedControl(7,5,6,2); 18 19 20//Variables 21int Balls = 1; //Number of Balls 22int MaxBalls = 5; //Number of Maxballs 23int Milli = 50; //Delay 1 24int MilliRoll = 100; //Delay 2 25int Milli_Bumper = 30; //Delay for Bumpers 26int Oncepergame = 0; 27int Skillshot_active = 0; //Activates the Skillshot 28int Skillshot1_active = 0; 29int Skillshot2_active = 0; 30int Skillshot3_active = 0; 31int PlayMusicOnce = 0; 32int randNumber; //Random Number for the Skillshot 33unsigned long previousMillis_Skillshot = 0; 34const long interval_skillshot = 10000; //The Skillshot is active for 10 seconds once the ball is in play 35int Ball_active = 0; 36 37 38int AttractMode = 0; 39int Torpedo1_primer =1; 40int Torpedo2_primer =1; 41int Torpedo3_primer =1; 42 43int Torpedo1_active =0; 44int Torpedo2_active =0; 45int Torpedo3_active =0; 46 47int Vari_Bonus_active =0; 48int Vari_top_bottom = 0; //Target recognition starts at the top (position 5) to the bottom (position 1). Highest positions is cored and locks the rest. 49//Mosfet Variables////////////////////////////////////////////////////////////////////////////////////// 50const long interval = 50; // interval at which to trigger bumper solenoids (milliseconds) 51const long interval_vari_activate = 500; // interval after which to activate the vari target coil (milliseconds) 52const long interval_vari_deactivate = 1200; // interval after which to deactivate the vari target coil (milliseconds) 53unsigned long Solenoid_TimeTemp; 54unsigned long Solenoid_FireTime; 55unsigned long previousMillis = 0; 56unsigned long previousMillis_vari_activate = 0; 57unsigned long previousMillis_vari_deactivate = 0; 58unsigned long currentMillis = 0; 59 60unsigned long previousMillis_cap = 0; 61const long interval_grace_cap = 900; // interval at which the captive Balls can't be triggered again after the first trigger 62 63unsigned long VariTargetBurnTime = 0; //Burn Timers to protect the solenoids from stuck switches 64unsigned long BumperBurnTime = 0; 65unsigned long KickoutBurnTime = 0; 66unsigned long ReleaseBurnTime = 0; 67unsigned long SolenoidOnFireTime = 1800; 68unsigned long VariTargetBurnTimeBase; 69unsigned long BumperBurnTimeBase; 70unsigned long KickoutBurnTimeBase; 71unsigned long ReleaseBurnTimeBase; 72 73 74 75 76int MosfetState = LOW; 77int Kickout_Trigger = 0; 78int Bumper_Trigger = 0; 79int Vari_Trigger = 2; 80int BallRelease_Trigger = 0; 81 82//Variables to avoid ghosting////////////////////////////////////////////////////////////////////////////////////// 83int Rollover_Lane1_int_last = LOW; 84int Rollover_Lane2_int_last = LOW; 85int Rollover_Lane3_int_last = LOW; 86 87int CaptiveBall1_int_last = LOW; 88int CaptiveBall2_int_last = LOW; 89int CaptiveBall3_int_last = LOW; 90 91int Outlanes_Links_Rechts_int_last = LOW; 92int Sidelanes_Left1_int_last = LOW; 93int Sidelanes_Right2_int_last = LOW; 94 95int Target_Low_int_last = LOW; 96int Target_High_int_last = LOW; 97int Target_Vari1_int_last = LOW; 98int Target_Vari2_int_last = LOW; 99int Target_Vari3_int_last = LOW; 100int Target_Vari4_int_last = LOW; 101int Target_Vari5_int_last = LOW; 102int VariTarget_int_last = LOW; 103int Kickout_int_last = LOW; 104int Rollunder_int_last = LOW; 105int BallRelease_int_last = LOW; 106int Bumper_int_last = LOW; 107int Bumper_shockproof = 0; 108int Ballinplay_int_last = LOW; 109int Slingshots_Left_Right_Up_int_last = LOW; 110int Rubberband123_int_last = LOW; 111 112//Attract Mode///////////////////////////////////////////////////////////// 113int AttatchInteruptOnce = 0; 114 115//volatile int AttractMode = 0; 116int Attractcounter1 = 0; 117int Attractcounter2 = 0; 118int Attractcounter3 = 0; 119int Attractcounter4 = 0; 120int Attractdelay1 = 800; 121int Attractdelay2 = 400; 122int Startplay_A = 0; 123int Startplay_ACTIVE = 0; 124 125//Attract Mode///////////////////////////////////////////////////////////// 126 127//Score and Scoredisplay////////////////////////////////////////////////////////////////////////////////////// 128 129int adress = 0; //Adress for saved Highscore 130 long HighScore = EEPROM.readLong(adress); 131long Score = 0; 132long Bonus; //Bonus points 133long Bonus_temp = 0; //Bonus counter 134long Bonus_fix = 0; //Bonus --> Ships sunk 135int DoubleBonus = 0; 136int Ships_sunk = 0; 137int Ships_allive = 10; 138int Max_Bonus_multiplier = (Ships_allive-Ships_sunk); 139int Torpedo_Bonus = 0; //(0-10) 140int Bonus_Counter = 0; 141int Bonus_low_target = 0; 142int Kickout_Bonus = 0; 143int VariTorpedo1 = 0; 144int VariTorpedo2 = 0; 145int VariTorpedo3 = 0; 146 147int num0; 148int num1; 149int num2; 150int num3; 151int num4; 152int num5; 153int num6; 154int num7; 155int Highnum0; 156int Highnum1; 157int Highnum2; 158int Highnum3; 159int Highnum4; 160int Highnum5; 161int Highnum6; 162int Highnum7; 163 164 165int loopnumber =0; 166 167//PINS 50,51,52,53 reserved////////////////////////////////////////////////////////////////////////////////////// 168 169int Rollover_Lane1 = 44; 170int Rollover_Lane2 = 42; 171int Rollover_Lane3 = 40; 172int CaptiveBall1 = 49; 173int CaptiveBall2 = 48; 174int CaptiveBall3 = 46; 175int Grace_Trigger = 0; //Grace Trigger for the Captive Balls 176 177 178int Outlanes_Links_Rechts = 47; 179int Sidelanes_Left1 = 43; 180int Sidelanes_Right2 = 45; 181int Target_Low = 26; 182int Target_High = 28; 183int Target_Vari1 = 31; 184int Target_Vari2 = 29; 185int Target_Vari3 = 27; 186int Target_Vari4 = 25; 187int Target_Vari5 = 30; 188int Spinner = 32; 189int Rollunder = 34; 190int Ballinplay = 36; 191int Slingshots_Left_Right_Up = 33; 192int Rubberband123 = 38; 193int Kickout = 37; 194int Bumper = 35; 195int VariTarget = 24; 196int BallRelease = 39; 197 198 199//Pins activate Solenoids when High!////////////////////////////////////////////////////////////////////////////////////// 200const int solenoidPin_Kickout = A15; 201const int solenoidPin_Bumper = A14; 202const int solenoidPin_VariTarget = A13; 203const int solenoidPin_BallRelease = A12; 204 205void setup() 206{ 207randomSeed(analogRead(0)); 208/////////////LEDS/////////////////// 209 FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); 210 FastLED.addLeds<NEOPIXEL, DATA_PIN2>(ledsbig, NUM_LEDS2); 211 FastLED.setBrightness(BRIGHTNESS); 212 213/////General Illumination 214ledsbig[0] = CHSV(70, 165, 255);// 215ledsbig[1] = CHSV(70, 0, 255);// 216ledsbig[2] = CHSV(70, 0, 255);// 217ledsbig[3] = CHSV(70, 205, 255);// 218ledsbig[4] = CHSV(70, 205, 255);// 219ledsbig[5] = CHSV(70, 205, 0);// 220ledsbig[6] = CHSV(70, 205, 255);// 221ledsbig[7] = CHSV(70, 205, 255);// 222ledsbig[8] = CHSV(70, 205, 255);// 223ledsbig[9] = CHSV(70, 205, 255);// 224ledsbig[10] = CHSV(70, 205, 0);// 225ledsbig[11] = CHSV(70, 205, 255);// 226ledsbig[12] = CHSV(70, 205, 255);// 227ledsbig[13] = CHSV(70, 205, 255);// 228leds[37] = CHSV(150, 0, 255); //Bumper 229 FastLED.show(); 230/////General Illuminsation 231 232 233/////////////LEDS/////////////////// 234 235// Inputs 236pinMode(Rollover_Lane1,INPUT_PULLUP); //Rollover Lanes 237pinMode(Rollover_Lane2,INPUT_PULLUP); //Rollover Lanes 238pinMode(Rollover_Lane3,INPUT_PULLUP); //Rollover Lanes 239pinMode(CaptiveBall1,INPUT_PULLUP); //Captive Balls 240pinMode(CaptiveBall2,INPUT_PULLUP); //Captive Balls 241pinMode(CaptiveBall3,INPUT_PULLUP); //Captive Balls 242pinMode(Outlanes_Links_Rechts,INPUT_PULLUP); //Outlanes 243pinMode(Sidelanes_Left1,INPUT_PULLUP); //Sidelanes 244pinMode(Sidelanes_Right2,INPUT_PULLUP); //Sidelanes 245 246pinMode(Target_Low,INPUT_PULLUP); //Targets 247pinMode(Target_High,INPUT_PULLUP); //Targets 248pinMode(Target_Vari1,INPUT_PULLUP); //Vari_Target 249pinMode(Target_Vari2,INPUT_PULLUP); //Vari_Target 250pinMode(Target_Vari3,INPUT_PULLUP); //Vari_Target 251pinMode(Target_Vari4,INPUT_PULLUP); //Vari_Target 252pinMode(Target_Vari5,INPUT_PULLUP); //Vari_Target 253 254pinMode(Slingshots_Left_Right_Up,INPUT_PULLUP); //Spinner 255pinMode(Rubberband123,INPUT_PULLUP); //Spinner 256 257pinMode(Spinner,INPUT_PULLUP); //Spinner 258pinMode(Rollunder,INPUT_PULLUP); //Rollunder 259 260pinMode(Ballinplay,INPUT_PULLUP); //Ballinplay 261pinMode(VariTarget,INPUT_PULLUP); //VariTarget Control if hit 262pinMode(BallRelease,INPUT_PULLUP); //BallRelease Switch 263pinMode(Bumper,INPUT_PULLUP); //Bumper 264pinMode(Kickout,INPUT_PULLUP); //Bumper 265 266pinMode(3, INPUT_PULLUP); //Interrupt 267//Outputs used to activate Solenoids////////////////////////////////////////////////////////////////////////////////////// 268pinMode(solenoidPin_Kickout, OUTPUT); 269pinMode(solenoidPin_Bumper, OUTPUT); 270pinMode(solenoidPin_VariTarget, OUTPUT); 271pinMode(solenoidPin_BallRelease, OUTPUT); 272 273//deactivate all Solenoids just in case 274digitalWrite(solenoidPin_Kickout, LOW); 275digitalWrite(solenoidPin_Bumper, LOW); 276digitalWrite(solenoidPin_VariTarget, LOW); 277digitalWrite(solenoidPin_BallRelease, LOW); 278 279Serial.begin(9600); 280// Initialize the MAX7219 281//Serial.write("14CORE TEST CODE FOR LED MAX7219 LED TUBE\ 282"); 283lc.shutdown(0,false); // To Enable the Display 284lc.setIntensity(0,1); // To set the brightness level (0 is min, 15 is max) 285lc.clearDisplay(0); // To Clear the display register 286lc.shutdown(1,false); // To Enable the Display 287lc.setIntensity(1,1); // To set the brightness level (0 is min, 15 is max) 288lc.clearDisplay(1); // To Clear the display register 289//Serial.write("Solenoid Test "); 290//Serial.write(A13); 291//Serial.write("\ 292"); 293 294} //END SETUP 295 296 297/////////////////////////////////////////////MAIN///////////////////////////////////////////////////////////// 298void loop() 299{ 300 301 302//EIFR = bit (INTF2); 303 304 305 306if (AttractMode == 0) { 307 308 309ATTRACT(); 310 311 312 } //END ATTRACT 313 314if (AttractMode == 1) { 315//detachInterrupt(1); 316//detachInterrupt (digitalPinToInterrupt (3)); 317//AttatchInteruptOnce = 0; //Prevent the interrupt during the game 318 319 320if (Startplay_ACTIVE == 0){ 321 322 for(int i = 0; i < NUM_LEDS; i++) { //Turn off all the lights from the Attract mode 323 leds[i] = CHSV(1, 255, 0); FastLED.show(); 324 }; 325 326 Wire.begin();Wire.beginTransmission(9); // transmit to device #9 327 Wire.write(9); // sends x 328 Wire.endTransmission(); // stop transmitting 329 330 331Serial.print("Startplay_ACTIVE\ 332"); 333 Startplay_ACTIVE = 1; 334 ResetGame(); 335 Kickout_ball(); 336} 337 338//Serial.print("MosfetChecks\ 339"); 340unsigned long currentMillis = millis(); //Starting Time 341detectCollision(); //Collision and Switch detection 342control_lights(); //Lights 343check_conditions(); //Checks for Bonuses 344 345/////////////////////////////////////////////////////////////////////Timed Soneloid Triggers running in Main Loop/////////////////////////////////////////////////////////////////////////////////////////// 346 347///////////////////////////////////////////////////////////////////////////////MOSFET !/////////////////////////////////////////////////////////////////////////////////////////////// 348 349int difference = currentMillis - previousMillis; 350int difference_vari_activate = currentMillis - previousMillis_vari_activate; 351int difference_vari_deactivate = currentMillis - previousMillis_vari_deactivate; 352 353 354 if ((difference >= interval)and (Bumper_Trigger == 1)) { 355 previousMillis = currentMillis; 356 Bumper_Trigger = 0; 357 digitalWrite(solenoidPin_Bumper, LOW); //Bumper Solenoid deactivated 358 Serial.print("Bumper de-activated \ 359"); 360 delay (10); 361 362 } 363 364if ((difference >= interval)and (Kickout_Trigger == 1)) { 365 previousMillis = currentMillis; 366 Kickout_Trigger = 0; 367 digitalWrite(solenoidPin_Kickout, LOW); //Kickout Solenoid deactivated 368 } 369 370 if ((difference_vari_activate >= interval_vari_activate)and (Vari_Trigger == 0)) { 371 previousMillis_vari_activate = currentMillis; 372 373 digitalWrite(solenoidPin_VariTarget, HIGH); //Vari Solenoid activated 374 Vari_Trigger = 1; 375 Serial.write("vari Activated\ 376"); 377 378 } 379 380 381 if ((difference_vari_deactivate >= interval_vari_deactivate)and (Vari_Trigger == 1)) { 382 previousMillis_vari_deactivate = currentMillis; 383 Vari_Trigger = 2; 384 digitalWrite(solenoidPin_VariTarget, LOW); //Vari Solenoid deactivated 385 Serial.write("vari automatic release-deactivated\ 386"); 387 388 Target_Vari5_int_last = LOW; //Reset at this position to prevent counting the hits more than once. Only after coil reset a new 389 Target_Vari4_int_last = LOW; //Varit Hit will be registered. 390 Target_Vari3_int_last = LOW; 391 Target_Vari2_int_last = LOW; 392 Target_Vari1_int_last = LOW; 393 } 394 395 396////////////////////////////////////////////////////////////////MOSFET End !//////////////////////////////////////////////////////// 397 398/////////////Timed Events_______Grace and Skill///////////////////////////// 399int difference_grace = currentMillis - previousMillis_cap; 400 401if ((difference_grace >= interval_grace_cap)and (Grace_Trigger == 1)) { 402 previousMillis_cap = currentMillis; 403 Grace_Trigger = 0; 404 405 } 406 407int difference_skill = currentMillis - previousMillis_Skillshot; 408 409if ((difference_skill >= interval_skillshot) and (Skillshot_active == 1) and (Ball_active == 1)) { 410 Skillshot_active = 0; 411 Ball_active = 0; 412 Skillshot1_active = 0; 413 Skillshot2_active = 0; 414 Skillshot3_active = 0; 415 416 } 417 418 419/////////////Timed Events_______Grace and Skill///////////////////////////// 420 421 422 423////////////////////////////////////////////////////////////////Solenoid Burn protection//////////////////////////////////////////////////////// 424if ((digitalRead(solenoidPin_VariTarget) == LOW) ){ 425 VariTargetBurnTime = 0; 426 VariTargetBurnTimeBase = millis(); 427} 428else if ((digitalRead(solenoidPin_VariTarget) == HIGH) ){ 429 VariTargetBurnTime = VariTargetBurnTime + (millis() - VariTargetBurnTimeBase); 430 VariTargetBurnTimeBase = millis(); 431} 432if ((digitalRead(solenoidPin_Bumper) == LOW) ){ 433 BumperBurnTime = 0; 434 BumperBurnTimeBase = millis(); 435} 436else if ((digitalRead(solenoidPin_Bumper) == HIGH) ){ 437 BumperBurnTime = BumperBurnTime + (millis() - BumperBurnTimeBase); 438 BumperBurnTimeBase = millis(); 439} 440if ((digitalRead(solenoidPin_Kickout) == LOW) ){ 441 KickoutBurnTime = 0; 442 KickoutBurnTimeBase = millis(); 443} 444else if ((digitalRead(solenoidPin_Kickout) == HIGH) ){ 445 KickoutBurnTime = KickoutBurnTime + (millis() - KickoutBurnTimeBase); 446 KickoutBurnTimeBase = millis(); 447} 448if ((digitalRead(solenoidPin_BallRelease) == LOW) ){ 449 ReleaseBurnTime = 0; 450 ReleaseBurnTimeBase = millis(); 451} 452else if ((digitalRead(solenoidPin_BallRelease) == HIGH) ){ 453 ReleaseBurnTime = ReleaseBurnTime + (millis() - ReleaseBurnTimeBase); 454 ReleaseBurnTimeBase = millis(); 455} 456 457//Serial.print("BumperBurnTime is ");Serial.print(BumperBurnTime);Serial.print("\ 458"); 459 460if ((VariTargetBurnTime > SolenoidOnFireTime) || (BumperBurnTime > SolenoidOnFireTime) || (KickoutBurnTime > SolenoidOnFireTime) || (ReleaseBurnTime > SolenoidOnFireTime)){ 461 digitalWrite(solenoidPin_VariTarget, LOW); //Vari Solenoid deactivated 462 digitalWrite(solenoidPin_Bumper, LOW); //Vari Solenoid deactivated 463 digitalWrite(solenoidPin_Kickout, LOW); //Vari Solenoid deactivated 464 digitalWrite(solenoidPin_BallRelease, LOW); //Vari Solenoid deactivated 465 466 while(1){ 467 //Endless Loop. Prevents the re-activation of a solenoid due to a stuck switch. All solenoids have to be de-activated to be on the safe side. 468 Serial.print("Burnprotection ");Serial.print(VariTargetBurnTime);Serial.print(BumperBurnTime);Serial.print(KickoutBurnTime);Serial.print(ReleaseBurnTime);Serial.print("\ 469"); 470 471 } 472} 473 474 475 476////////////////////////////////////////////////////////////////Solenoid Burn protection END//////////////////////////////////////////////////////// 477} 478} 479//////////////////Main END//////////voids////////////////////////////////////////////////////////////////////////////////////// 480 481/////////Routine for setting Lights////////////////////////////// 482void control_lights(){ 483 ////////////////Activated Lights//////////////// 484if (Torpedo1_active == 1){ 485 leds[17] = CHSV(50, 0, 255); 486 } 487if (Torpedo2_active == 1){ 488 leds[16] = CHSV(50, 0, 255); 489 } 490if (Torpedo3_active == 1){ 491 leds[15] = CHSV(50, 0, 255); 492 } 493if (Torpedo1_active == 0){ 494 leds[17] = CHSV(50, 0, 0); 495 } 496if (Torpedo2_active == 0){ 497 leds[16] = CHSV(50, 0, 0); 498 } 499if (Torpedo3_active == 0){ 500 leds[15] = CHSV(50, 0, 0); 501 } 502if (Torpedo1_primer == 1){ 503 leds[0] = CHSV(155, 255, 255); 504 leds[18] = CHSV(150, 255, 255); 505 506 if ( (Skillshot1_active == 1) and (Skillshot_active == 1)) { //Turn red when Skillshot is active 507 leds[0] = CHSV(255, 255, 255); 508 } 509 510 511 } 512if (Torpedo1_primer == 0){ 513 leds[0] = CHSV(155, 255, 0); 514 leds[18] = CHSV(150, 255, 0); 515 516 } 517if (Torpedo2_primer == 1){ 518 leds[1] = CHSV(155, 255, 255); 519 leds[23] = CHSV(150, 255, 255); //lane2 520 521 if ( (Skillshot2_active == 1) and (Skillshot_active == 1)) { //Turn red when Skillshot is active 522 leds[1] = CHSV(255, 255, 255); 523 } 524 525 } 526if (Torpedo2_primer == 0){ 527 leds[1] = CHSV(155, 255, 0); 528 leds[23] = CHSV(150, 255, 0); //lane2 529 } 530if (Torpedo3_primer == 1){ 531 leds[2] = CHSV(155, 255, 255); 532 if ( (Skillshot3_active == 1) and (Skillshot_active == 1)) { //Turn red when Skillshot is active 533 leds[2] = CHSV(255, 255, 255); 534 } 535 } 536if (Torpedo3_primer == 0){ 537 leds[2] = CHSV(155, 255, 0); 538 } 539if (Vari_Bonus_active == 1){ 540 leds[21] = CHSV(50, 0, 255); //vari 541 ledsbig[5] = CHSV(70, 205, 255);// VariBonus?`?? 542 } 543if (Vari_Bonus_active == 0){ 544 leds[21] = CHSV(50, 0, 0); //vari 545 ledsbig[5] = CHSV(70, 205, 0);// VariBonus?`?? 546 } 547if (Bonus_low_target == 1){ 548 leds[22] = CHSV(50, 1, 255); //targetlow 549 } 550if (Bonus_low_target == 0){ 551 leds[22] = CHSV(50, 1, 0); //targetlow 552 } 553 554for (int t=24; t<36;t++){ //Turns off all ship lights. They are subsequently re-lit according to the Bonus and Ship Sunk scores 555 leds[t] = CHSV(50, 1, 0); // 556} 557if (Bonus_temp > 0){ 558 if (Bonus_temp == 1){ 559 leds[33] = CHSV(50, 1, 255); //10k 560 } 561 if (Bonus_temp == 2){ 562 leds[31] = CHSV(50, 1, 255); //20k 563 } 564 if (Bonus_temp == 3){ 565 leds[34] = CHSV(50, 1, 255); //30k 566 } 567 if (Bonus_temp == 4){ 568 leds[30] = CHSV(50, 1, 255); //40k 569 } 570 if (Bonus_temp == 5){ 571 leds[35] = CHSV(50, 1, 255); //50k 572 } 573 if (Bonus_temp == 6){ 574 leds[29] = CHSV(50, 1, 255); //60k 575 } 576 if (Bonus_temp == 7){ 577 leds[27] = CHSV(50, 1, 255); //70k 578 } 579 if (Bonus_temp == 8){ 580 leds[28] = CHSV(50, 1, 255); //80k 581 } 582 if (Bonus_temp == 9){ 583 leds[26] = CHSV(50, 1, 255); //90k 584 } 585if (Bonus_temp == 10){ 586 leds[25] = CHSV(50, 1, 255); //100k 587 } 588} 589 590if (Ships_sunk > 0){ 591 if (Ships_sunk == 1){ 592 leds[25] = CHSV(50, 1, 255); //100k 593 } 594 if (Ships_sunk == 2){ 595 leds[25] = CHSV(50, 1, 255); //100k 596 leds[26] = CHSV(50, 1, 255); //90k 597 } 598 if (Ships_sunk == 3){ 599 leds[25] = CHSV(50, 1, 255); //100k 600 leds[26] = CHSV(50, 1, 255); //90k 601 leds[28] = CHSV(50, 1, 255); //80k 602 } 603 if (Ships_sunk == 4){ 604 leds[25] = CHSV(50, 1, 255); //100k 605 leds[26] = CHSV(50, 1, 255); //90k 606 leds[28] = CHSV(50, 1, 255); //80k 607 leds[27] = CHSV(50, 1, 255); //70k 608 } 609 if (Ships_sunk == 5){ 610 leds[25] = CHSV(50, 1, 255); //100k 611 leds[26] = CHSV(50, 1, 255); //90k 612 leds[28] = CHSV(50, 1, 255); //80k 613 leds[27] = CHSV(50, 1, 255); //70k 614 leds[29] = CHSV(50, 1, 255); //60k 615 } 616 if (Ships_sunk == 6){ 617 leds[25] = CHSV(50, 1, 255); //100k 618 leds[26] = CHSV(50, 1, 255); //90k 619 leds[28] = CHSV(50, 1, 255); //80k 620 leds[27] = CHSV(50, 1, 255); //70k 621 leds[29] = CHSV(50, 1, 255); //60k 622 leds[35] = CHSV(50, 1, 255); //50k 623 } 624 if (Ships_sunk == 7){ 625 leds[25] = CHSV(50, 1, 255); //100k 626 leds[26] = CHSV(50, 1, 255); //90k 627 leds[28] = CHSV(50, 1, 255); //80k 628 leds[27] = CHSV(50, 1, 255); //70k 629 leds[29] = CHSV(50, 1, 255); //60k 630 leds[35] = CHSV(50, 1, 255); //50k 631 leds[30] = CHSV(50, 1, 255); //40k 632 } 633 if (Ships_sunk == 8){ 634 leds[25] = CHSV(50, 1, 255); //100k 635 leds[26] = CHSV(50, 1, 255); //90k 636 leds[28] = CHSV(50, 1, 255); //80k 637 leds[27] = CHSV(50, 1, 255); //70k 638 leds[29] = CHSV(50, 1, 255); //60k 639 leds[35] = CHSV(50, 1, 255); //50k 640 leds[30] = CHSV(50, 1, 255); //40k 641 leds[34] = CHSV(50, 1, 255); //30k 642 } 643 if (Ships_sunk == 9){ 644 leds[25] = CHSV(50, 1, 255); //100k 645 leds[26] = CHSV(50, 1, 255); //90k 646 leds[28] = CHSV(50, 1, 255); //80k 647 leds[27] = CHSV(50, 1, 255); //70k 648 leds[29] = CHSV(50, 1, 255); //60k 649 leds[35] = CHSV(50, 1, 255); //50k 650 leds[30] = CHSV(50, 1, 255); //40k 651 leds[34] = CHSV(50, 1, 255); //30k 652 leds[31] = CHSV(50, 1, 255); //20k 653 } 654if (Ships_sunk == 10){ 655 leds[25] = CHSV(50, 1, 255); //100k 656 leds[26] = CHSV(50, 1, 255); //90k 657 leds[28] = CHSV(50, 1, 255); //80k 658 leds[27] = CHSV(50, 1, 255); //70k 659 leds[29] = CHSV(50, 1, 255); //60k 660 leds[35] = CHSV(50, 1, 255); //50k 661 leds[30] = CHSV(50, 1, 255); //40k 662 leds[34] = CHSV(50, 1, 255); //30k 663 leds[31] = CHSV(50, 1, 255); //20k 664 leds[33] = CHSV(50, 1, 255); //10k 665 } 666} 667for (int t=3; t<14;t++){ //Turns off all torpedo lights. They are subsequently re-lit according to the Torpedo scores 668 leds[t] = CHSV(50, 1, 0); // 669} 670if (Torpedo_Bonus > 0){ 671 int Torpedolight = Torpedo_Bonus + 3; 672 leds[Torpedolight] = CHSV(25, 1, 255); 673} 674if (DoubleBonus == 1){ 675leds[32] = CHSV(230, 255, 255); //DoubleBonus 676} 677 678if (Kickout_Bonus == 1){ 679 ledsbig[10] = CHSV(70, 205, 255);// ExtraBall? 680} 681 682////////////////Activated Lights//////////////// 683 684 685 FastLED.show(); 686} 687 688 689//Main Routine for detecting Conditions////////////////////////////////////////////////////////////////////////////////////// 690void check_conditions(){ 691 692 693if ((VariTorpedo1 == 1)&&(VariTorpedo2 == 1)&&(VariTorpedo3 == 1)&&(Vari_Bonus_active == 0)){ //Activation of VariBonus 694 695 allTorpedosactive(); 696} 697 698if ((VariTorpedo1 == 1)&&(VariTorpedo2 == 1)&&(VariTorpedo3 == 1)&&(Kickout_Bonus == 0) && (DoubleBonus == 1)&& (Oncepergame == 0)){ 699 Kickout_Bonus = 1; //Allows for Extra Ball 700 Oncepergame = 1; //Only one extra Ball per game 701 Wire.begin();Wire.beginTransmission(9); // transmit to device #9 702 Wire.write(15); // sends x 703 Wire.endTransmission(); // stop transmitting 704} 705 706 707} 708//Main Routine for detecting Conditions////////////////////////////////////////////////////////////////////////////////////// 709 710//Main Routine for detecting Events and Scoring//////////////////////////////////////////////////////////////////////// 711 712void detectCollision(){ 713//Serial.print("Collision Check\ 714"); 715//Definition of Sensor Reads 716int Rollover_Lane1_int = digitalRead(Rollover_Lane1); //Variable for Rollover Lanes 717int Rollover_Lane2_int = digitalRead(Rollover_Lane2); //Variable for Rollover Lanes 718int Rollover_Lane3_int = digitalRead(Rollover_Lane3); //Variable for Rollover Lanes 719 720int CaptiveBall1_int = digitalRead(CaptiveBall1); //Variable for CaptiveBalls 721int CaptiveBall2_int = digitalRead(CaptiveBall2); //Variable for CaptiveBalls 722int CaptiveBall3_int = digitalRead(CaptiveBall3); //Variable for CaptiveBalls 723 724int Outlanes_Links_Rechts_int = digitalRead(Outlanes_Links_Rechts); //Variable for Outlanes Links Rechts 725int Sidelanes_Left1_int = digitalRead(Sidelanes_Left1); //Variable for Sidelanes Left 726int Sidelanes_Right2_int = digitalRead(Sidelanes_Right2); //Variable for Sidelanes rigth 727 728int Target_Low_int = digitalRead(Target_Low); //Variable for Target_Low 729int Target_High_int = digitalRead(Target_High); //Variable for Target_High 730int Target_Vari1_int = digitalRead(Target_Vari1); //Variable for Target_Vari1 731int Target_Vari2_int = digitalRead(Target_Vari2); //Variable for Target_Vari1 732int Target_Vari3_int = digitalRead(Target_Vari3); //Variable for Target_Vari1 733int Target_Vari4_int = digitalRead(Target_Vari4); //Variable for Target_Vari1 734int Target_Vari5_int = digitalRead(Target_Vari5); //Variable for Target_Vari1 735 736int Spinner_int = digitalRead(Spinner); //Variable for Spinner 737int Rollunder_int = digitalRead(Rollunder); //Variable for Rollunder 738 739int Ballinplay_int = digitalRead(Ballinplay); //Variable for Ballinplay Switch 740int Slingshots_Left_Right_Up_int = digitalRead(Slingshots_Left_Right_Up); //Variable for Slingshots 741int Rubberband123_int = digitalRead(Rubberband123); //Variable for Rubberband123 742int Kickout_int = digitalRead(Kickout); //Variable for Kickout Switch 743int Bumper_int = digitalRead(Bumper); //Variable for Bumper Switch 744int VariTarget_int = digitalRead(VariTarget); //Variable for VariTarget Switch 745int BallRelease_int = digitalRead(BallRelease); //Variable for BallRelease Switch 746 747int Startbutton = digitalRead(3); //Variable for Startbutton 748 749//End of Definition of Sensor Reads End////////////////////////////////////////////////////////////////////////////////////// 750 751//Definition of Events upon activating a Sensor////////////////////////////////////////////////////////////////////////////////////// 752 753//Switches 1-3////////////////////////////////////////////////////////////////////////////////////// 754 755if ((Ballinplay_int == LOW) && (Ballinplay_int_last == LOW) && (Skillshot_active == 1)){ //Ball in Play and Skillshot is active 756 Ballinplay_int_last = HIGH; 757 Skillshot_Timer(); 758 Ball_active = 1; 759} 760else if ((Ballinplay_int == HIGH) && (Ballinplay_int_last == HIGH) ){ //Ball in Play released 761 Ballinplay_int_last = LOW; 762delay (150); 763} 764 765if ((Rollover_Lane1_int == LOW) && (Rollover_Lane1_int_last == LOW) ){ //Rollover_Lane1 triggered 766 767Rollover_Lane1_event(); //Events triggered 768Rollover_Lane1_int_last = HIGH; 769Serial.print("Rollover1\ 770"); 771delay (MilliRoll); 772} 773else if ((Rollover_Lane1_int == HIGH) && (Rollover_Lane1_int_last == HIGH) ){ //Rollover_Lane1 released 774 Rollover_Lane1_int_last = LOW; 775delay (MilliRoll); 776} 777 778if ((Rollover_Lane2_int == LOW) && (Rollover_Lane2_int_last == LOW) ){ //Rollover_Lane2 triggered 779 780Rollover_Lane2_event(); //Events triggered 781Rollover_Lane2_int_last = HIGH; 782Serial.print("Rollover2\ 783"); 784delay (MilliRoll); 785} 786else if ((Rollover_Lane2_int == HIGH) && (Rollover_Lane2_int_last == HIGH) ){ //Rollover_Lane2 released 787 Rollover_Lane2_int_last = LOW; 788delay (MilliRoll); 789} 790if ((Rollover_Lane3_int == LOW) && (Rollover_Lane3_int_last == LOW) ){ //Rollover_Lane3 triggered 791 792Rollover_Lane3_event(); //Events triggered 793Rollover_Lane3_int_last = HIGH; 794Serial.print("Rollover3\ 795"); 796delay (MilliRoll); 797} 798else if ((Rollover_Lane3_int == HIGH) && (Rollover_Lane3_int_last == HIGH) ){ //Rollover_Lane3 released 799 Rollover_Lane3_int_last = LOW; 800delay (MilliRoll); 801} 802 803//End of Switches 1-3 ////////////////////////////////////////////////////////////////////////////////////// 804 805//CaptiveBalls 1-3////////////////////////////////////////////////////////////////////////////////////// 806if ((CaptiveBall1_int == LOW) && (CaptiveBall1_int_last == LOW) && (Grace_Trigger == 0) ){ //CaptiveBall1_int triggered Grace_Trigger prevents double Activation by captive Balls 807Grace_Trigger = 1 ; 808CaptiveBall1_int_last = HIGH; 809 Wire.begin();Wire.beginTransmission(9); // transmit to device #9 810 Wire.write(10); // sends x 811 Wire.endTransmission(); // stop transmitting 812 813CaptiveBall1_event(); //Events triggered 814Serial.print("Captive1\ 815"); 816delay (MilliRoll); 817} 818else if ((CaptiveBall1_int == HIGH) && (CaptiveBall1_int_last == HIGH) ){ //CaptiveBall1_int released 819 CaptiveBall1_int_last = LOW; 820 Serial.print("Captive1 released\ 821"); 822delay (MilliRoll); 823} 824 825if ((CaptiveBall2_int == LOW) && (CaptiveBall2_int_last == LOW) && (Grace_Trigger == 0) ){ //CaptiveBall2_int triggered 826Grace_Trigger = 1 ; 827 Wire.begin();Wire.beginTransmission(9); // transmit to device #9 828 Wire.write(10); // sends x 829 Wire.endTransmission(); // stop transmitting 830 831CaptiveBall2_event(); //Events triggered 832CaptiveBall2_int_last = HIGH; 833Serial.print("Captive2\ 834"); 835delay (MilliRoll); 836} 837else if ((CaptiveBall2_int == HIGH) && (CaptiveBall2_int_last == HIGH) ){ //CaptiveBall2_int released 838 CaptiveBall2_int_last = LOW; 839 Serial.print("Captive2 released\ 840"); 841delay (MilliRoll); 842} 843 844if ((CaptiveBall3_int == LOW) && (CaptiveBall3_int_last == LOW) && (Grace_Trigger == 0) ){ //CaptiveBall3_int triggered 845Grace_Trigger = 1 ; 846 Wire.begin();Wire.beginTransmission(9); // transmit to device #9 847 Wire.write(10); // sends x 848 Wire.endTransmission(); // stop transmitting 849CaptiveBall3_event(); //Events triggered 850CaptiveBall3_int_last = HIGH; 851Serial.print("Captive3\ 852"); 853delay (MilliRoll); 854} 855else if ((CaptiveBall3_int == HIGH) && (CaptiveBall3_int_last == HIGH) ){ //CaptiveBall3_int released 856 CaptiveBall3_int_last = LOW; 857 Serial.print("Captive3 released\ 858"); 859delay (MilliRoll); 860} 861 862//End of CaptiveBalls 1-3 ////////////////////////////////////////////////////////////////////////////////////// 863 864//Vari Bonus///////////////////////////////////////////// 865 866 867//Vari Bonus///////////////////////////////////////////// 868 869//Slingshot ////////////////////////////////////////////////////////////////////////////////////// 870 871if ((Slingshots_Left_Right_Up_int == LOW) && (Slingshots_Left_Right_Up_int_last == LOW) ){ //Slingshots_Left_Right_Up_int triggered 872Slingshots_Left_Right_Up_int_last = HIGH; 873Slingshot_event(); //Events triggered 874Serial.print("Slingshot\ 875"); 876Serial.print(Slingshots_Left_Right_Up_int ); 877Serial.print(Slingshots_Left_Right_Up_int_last); 878Wire.begin();Wire.beginTransmission(9); // transmit to device #9 879Wire.write(2); // sends x 880Wire.endTransmission(); // stop transmitting 881 882} 883else if ((Slingshots_Left_Right_Up_int == HIGH) && (Slingshots_Left_Right_Up_int_last == HIGH) ){ //Slingshots_Left_Right_Up_int released 884 Slingshots_Left_Right_Up_int_last = LOW; 885 delay (20); //possibly too long for Bumper 886} 887 888//End of Slingshot ////////////////////////////////////////////////////////////////////////////////////// 889 890//Spinner//////////////////////////////////////////////////////////////////////// 891if ((digitalRead(Spinner) == LOW) ){ 892 Wire.begin();Wire.beginTransmission(9); // transmit to device #9 893 Wire.write(3); // sends x 894 Wire.endTransmission(); // stop transmitting 895Spinnerf(); 896Serial.print("Spinner1\ 897"); 898} 899//End of Spinner//////////////////////////////////////////////////////////////////////// 900 901//Rollunder//////////////////////////////////////////////////////////////////////// 902if ((Rollunder_int == LOW) && (Rollunder_int_last == LOW) ){ //Rollunder is triggered 903Rollunder_int_last = HIGH; 904 Wire.begin();Wire.beginTransmission(9); // transmit to device #9 905 Wire.write(5); // sends x 906 Wire.endTransmission(); // stop transmitting 907Rollunderf(); 908Serial.print("Rollunder\ 909"); 910delay (MilliRoll); 911} 912else if ((Rollunder_int == HIGH) && (Rollunder_int_last == HIGH) ){ //Rollunder released 913 Rollunder_int_last = LOW; 914 Serial.print("Rollunder released\ 915"); 916 delay (MilliRoll); 917 918} 919//End of Rollunder//////////////////////////////////////////////////////////////////////// 920 921//Rubberbands ////////////////////////////////////////////////////////////////////////////////////// 922 923if ((Rubberband123_int == LOW) && (Rubberband123_int_last == LOW) ){ //Rubberband123 triggered 924 Wire.begin();Wire.beginTransmission(9); // transmit to device #9 925 Wire.write(14); // sends x 926 Wire.endTransmission(); // stop transmitting 927Rubberband123_event(); //Events triggered 928Rubberband123_int_last = HIGH; 929Serial.print("Rubber\ 930"); 931delay (MilliRoll); 932} 933else if ((Rubberband123_int == HIGH) && (Rubberband123_int_last == HIGH) ){ //Rubberband123 released 934 Rubberband123_int_last = LOW; 935 936delay (MilliRoll); 937} 938//End of Rubberbands ////////////////////////////////////////////////////////////////////////////////////// 939 940//Sidelanes 1 and 2 ////////////////////////////////////////////////////////////////////////////////////// 941 942if ((Sidelanes_Left1_int == LOW) && (Sidelanes_Left1_int_last == LOW) ){ //Sidelanes_Left1_int triggered 943Wire.begin();Wire.beginTransmission(9); // transmit to device #9 944 Wire.write(11); // sends x 945 Wire.endTransmission(); // stop transmitting 946Sidelane1_event(); //Events triggered 947Sidelanes_Left1_int_last = HIGH; 948Serial.print("Side1\ 949"); 950} 951else if ((Sidelanes_Left1_int == HIGH) && (Sidelanes_Left1_int_last == HIGH) ){ //Sidelanes_Left1_int released 952 Sidelanes_Left1_int_last = LOW; 953 954delay (MilliRoll); 955} 956 957////////// 958if ((Sidelanes_Right2_int == LOW) && (Sidelanes_Right2_int_last == LOW) ){ //Sidelanes_Right2_int triggered 959Wire.begin();Wire.beginTransmission(9); // transmit to device #9 960 Wire.write(11); // sends x 961 Wire.endTransmission(); // stop transmitting 962Sidelane2_event(); //Events triggered 963Sidelanes_Right2_int_last = HIGH; 964Serial.print("Side2\ 965"); 966} 967else if ((Sidelanes_Right2_int == HIGH) && (Sidelanes_Right2_int_last == HIGH) ){ //Sidelanes_Right2_int released 968 Sidelanes_Right2_int_last = LOW; 969 970delay (MilliRoll); 971} 972 973//End of Sidelanes ////////////////////////////////////////////////////////////////////////////////////// 974 975//Outlanes 1 and 2 ////////////////////////////////////////////////////////////////////////////////////// 976 977if ((Outlanes_Links_Rechts_int == LOW) && (Outlanes_Links_Rechts_int == LOW) ){ //Outlanes_Links_Rechts_intt triggered 978 Wire.begin();Wire.beginTransmission(9); // transmit to device #9 979 Wire.write(11); // sends x 980 Wire.endTransmission(); // stop transmitting 981Outlanes_Links_Rechts_int_last = HIGH; 982Outlane_event(); //Events triggered 983Serial.print("Outlanes\ 984"); 985} 986else if ((Outlanes_Links_Rechts_int == HIGH) && (Outlanes_Links_Rechts_int_last == HIGH) ){ //Outlanes_Links_Rechts_int released 987 Outlanes_Links_Rechts_int_last = LOW; 988 989delay (MilliRoll); 990} 991 992// Target Routine//////////////////////////////////////////////////////////////////////////////////// 993 994 995if ((Target_Low_int == LOW) && (Target_Low_int_last == LOW) ){ //Low Target hit 996Wire.begin();Wire.beginTransmission(9); // transmit to device #9 997 Wire.write(4); // sends x 998 Wire.endTransmission(); // stop transmitting 999Target_low_event(); 1000Target_Low_int_last = HIGH; 1001 delay (MilliRoll); 1002 Serial.print("Target_low\ 1003"); 1004} 1005 1006else if ((Target_Low_int == HIGH) && (Target_Low_int_last == HIGH) ){ //Target released 1007 Target_Low_int_last = LOW; 1008 delay (MilliRoll); 1009} 1010 1011if ((Target_High_int == LOW) && (Target_High_int_last == LOW) ){ //Low Target hit 1012Wire.begin();Wire.beginTransmission(9); // transmit to device #9 1013 Wire.write(4); // sends x 1014 Wire.endTransmission(); // stop transmitting 1015Target_High_event(); 1016Target_High_int_last = HIGH; 1017 delay (MilliRoll); 1018 Serial.print("Target_High\ 1019"); 1020} 1021 1022else if ((Target_High_int == HIGH) && (Target_High_int_last == HIGH) ){ //Target released 1023 Target_High_int_last = LOW; 1024 delay (MilliRoll); 1025} 1026////////////Vari Target The vari Target has 5 positions and a "check" switch.There has to be a tiny delay between triggering the 1027//check switch and the evaluation of the actual position. Testing with 50ms. 1028//The first postition doesn't have a different switch, if no other switch is triggered it is considered position 1. 1029 1030if ((VariTarget_int == LOW) && (VariTarget_int_last == LOW) ){ //Vari Target hit 1031VariTarget_int_last = HIGH; 1032delay (200); //Small delay in front of the Evaluation 1033Target_vari_event(); //Evaluation Event for Vari Target 1034 1035 1036} 1037else if ((VariTarget_int == HIGH) && (VariTarget_int_last == HIGH) ){ //Vari Target released 1038 VariTarget_int_last = LOW; 1039 delay (MilliRoll); 1040} 1041 1042////////////Vari Target 1043 1044// End of Target Routine //////////////////////////////////////////////////////////////////////////////////// 1045 1046//Solenoids 1047 1048if ((Bumper_int == LOW) && (Bumper_int_last == LOW)){ //Bumper has been triggered 1049Bumper_int_last = HIGH; 1050Wire.begin();Wire.beginTransmission(9); // transmit to device #9 1051 Wire.write(1); // sends x 1052 Wire.endTransmission(); // stop transmitting 1053Serial.print("Bumper Event triggered \ 1054"); 1055Bumper_Event(); 1056 1057} 1058else if ((Bumper_int == HIGH) && (Bumper_int_last == HIGH) ){ //bumper released 1059 1060 Serial.print("Bumper_int_last reseted \ 1061"); 1062 delay (10); 1063 1064 Bumper_int_last = LOW; 1065} 1066 1067 1068 1069 1070if ((Kickout_int == LOW) && (Kickout_int_last == LOW) ){ //Kickout has been triggered 1071Kickout_int_last = HIGH; 1072Wire.begin();Wire.beginTransmission(9); // transmit to device #9 1073 Wire.write(5); // sends x 1074 Wire.endTransmission(); // stop transmitting 1075delay (1000); //Ball rests in Kickout position, time to let it settle. 1076 1077 1078 1079Kickout_Event(); 1080Serial.print("Kickout\ 1081"); 1082} 1083else if ((Kickout_int == HIGH) && (Kickout_int_last == HIGH) ){ //Kickout released 1084 Kickout_int_last = LOW; 1085 delay (MilliRoll); 1086} 1087 1088if ((digitalRead(BallRelease) == LOW) && (BallRelease_int_last == LOW)){ 1089BallRelease_int_last = HIGH; 1090Releasef(); 1091Serial.print("Release\ 1092"); 1093} 1094else if ((digitalRead(BallRelease) == HIGH) && (BallRelease_int_last == HIGH) ){ //BallRelease released 1095 BallRelease_int_last = LOW; 1096 delay (MilliRoll); 1097} 1098 1099} 1100 1101//END of Main Routine for detecting Events and Scoring////////////////////////////////////////////////////////////////////////////////////// 1102 1103//void interruptstart(){ // ISR! 1104// 1105// AttractMode = 1; 1106// Serial.print("Interrupt Triggered\ 1107"); 1108// detachInterrupt (digitalPinToInterrupt (3)); 1109// AttatchInteruptOnce = 0; //Prevent the interrupt during the game 1110// } 1111 1112 1113 1114 1115void Bumper_Event(){ 1116 1117Score = Score +100; //Bumper awards 100 points and advances the Torpedo counter 1118 1119 1120previousMillis = millis(); 1121digitalWrite(solenoidPin_Bumper, HIGH); //Bumper Solenoid activated ! 1122 1123Serial.print("Bumper activated \ 1124"); 1125Serial.print('solenoidPin_Bumper'); 1126Scoring(); //Show Score 1127Torpedos_count(); 1128leds[37] = CHSV(random8(),255,255); //Bumper 1129 FastLED.show(); 1130delay(30); 1131Bumper_Trigger = 1 ; 1132 } 1133 1134void Kickout_Event(){ 1135Score = Score +1000; //Kickout awards 100 pints and advances the Torpedo counter 1136Torpedos_count(); 1137Scoring(); //Show Score 1138 1139 1140 1141 if (Kickout_Bonus == 1) { //if Kickout Bonus is active awards an active Ball 1142 MaxBalls +=1; 1143 Kickout_Bonus = 0; 1144 Wire.begin();Wire.beginTransmission(9); // transmit to device #9 1145 Wire.write(15); // sends x 1146 Wire.endTransmission(); // stop transmitting 1147 } 1148 1149 1150previousMillis = millis(); 1151digitalWrite(solenoidPin_Kickout, HIGH); //Kickout Solenoid activated ! 1152Kickout_Trigger = 1 ; 1153Serial.print("KICKOUT activated \ 1154"); 1155delay(Milli_Bumper); 1156 1157} 1158 1159 1160void Target_vari_event(){ //Evaluates which position has been hit in on the Vari Target///////////////////////////////////////////////////////////// 1161 1162int Target_Vari1_int = digitalRead(Target_Vari1); //Variable for Target_Vari2 1163int Target_Vari2_int = digitalRead(Target_Vari2); //Variable for Target_Vari3 1164int Target_Vari3_int = digitalRead(Target_Vari3); //Variable for Target_Vari4 1165int Target_Vari4_int = digitalRead(Target_Vari4); //Variable for Target_Vari5 1166int Target_Vari5_int = digitalRead(Target_Vari5); //Variable for Target_Vari X //Not Used ! Position 5 on the target is too far back to score. 1167Vari_top_bottom = 0; 1168delay(50); 1169 1170Serial.print("Vari activated. Beginning Evaluation "); 1171Serial.print("Vari_top_bottom is"); Serial.print(Vari_top_bottom);Serial.print(" The Readout for 12345 is: "); Serial.print(Target_Vari1_int); Serial.print(Target_Vari2_int); Serial.print(Target_Vari3_int); Serial.print(Target_Vari4_int); Serial.print(Target_Vari5_int); 1172 1173if ((Target_Vari4_int == LOW) && (Target_Vari4_int_last == LOW) && (Vari_top_bottom == 0) ){ //Vari Target position 5 hit 1174 Target_Vari4_int_last == HIGH; 1175 if (Vari_Bonus_active == 0) { //if Vari Bonus is active awards additional Bonuses 1176 Score = Score +5000; 1177 Scoring(); 1178 } 1179 else if (Vari_Bonus_active == 1){ 1180 Score = Score +50000; 1181 for (int u=0; u<5;u++){ 1182 Bonus_count(); 1183 } 1184 1185 Torpedo1_active = 0; //Deactivating the torpedos after VariBonus has been claimed 1186 Torpedo2_active = 0; 1187 Torpedo3_active = 0; 1188 VariTorpedo1 = 0; 1189 VariTorpedo2 = 0; 1190 VariTorpedo3 = 0; 1191 Vari_Bonus_active = 0; 1192 Torpedo1_primer = 1; //and activating the primers again 1193 Torpedo2_primer = 1; 1194 Torpedo3_primer = 1; 1195 } 1196Vari_top_bottom = 1; //locks the rest of the detection 1197Serial.print("Vari 5 activated\ 1198"); 1199} 1200 1201 1202if ((Target_Vari3_int == LOW) && (Target_Vari3_int_last == LOW) && (Vari_top_bottom == 0) ){ //Vari Target position 4 hit 1203 Target_Vari3_int_last == HIGH; 1204 if (Vari_Bonus_active == 0) { //if Vari Bonus is active awards additional Bonuses 1205 Score = Score +4000; 1206 Scoring(); 1207 } 1208 else if (Vari_Bonus_active == 1){ 1209 1210 for (int u=0; u<4;u++){ 1211 Bonus_count(); 1212 } 1213 1214 Torpedo1_active = 0; //Deactivating the torpedos after VariBonus has been claimed 1215 Torpedo2_active = 0; 1216 Torpedo3_active = 0; 1217 VariTorpedo1 = 0; 1218 VariTorpedo2 = 0; 1219 VariTorpedo3 = 0; 1220 Vari_Bonus_active = 0; 1221 Torpedo1_primer = 1; //and activating the primers again 1222 Torpedo2_primer = 1; 1223 Torpedo3_primer = 1; 1224 } 1225Vari_top_bottom = 1; //locks the rest of the detection 1226Serial.print("Vari 4 activated\ 1227"); 1228} 1229 1230 1231if ((Target_Vari2_int == LOW) && (Target_Vari2_int_last == LOW) && (Vari_top_bottom == 0) ){ //Vari Target position 3 hit 1232 Target_Vari2_int_last == HIGH; 1233 if (Vari_Bonus_active == 0) { //if Vari Bonus is active awards additional Bonuses 1234 Score = Score +3000; 1235 Scoring(); 1236 } 1237 else if (Vari_Bonus_active == 1){ 1238 1239 for (int u=0; u<3;u++){ 1240 Bonus_count(); 1241 } 1242 1243 Torpedo1_active = 0; //Deactivating the torpedos after VariBonus has been claimed 1244 Torpedo2_active = 0; 1245 Torpedo3_active = 0; 1246 VariTorpedo1 = 0; 1247 VariTorpedo2 = 0; 1248 VariTorpedo3 = 0; 1249 Vari_Bonus_active = 0; 1250 Torpedo1_primer = 1; //and activating the primers again 1251 Torpedo2_primer = 1; 1252 Torpedo3_primer = 1; 1253 } 1254Vari_top_bottom = 1; //locks the rest of the detection 1255Serial.print("Vari 3 activated\ 1256"); 1257} 1258 1259 1260if ((Target_Vari1_int == LOW) && (Target_Vari1_int_last == LOW) && (Vari_top_bottom == 0) ){ //Vari Target position 2 hit 1261 Target_Vari1_int_last == HIGH; 1262 if (Vari_Bonus_active == 0) { //if Vari Bonus is active awards additional Bonuses 1263 Score = Score +2000; 1264 Scoring(); 1265 } 1266 else if (Vari_Bonus_active == 1){ 1267 1268 for (int u=0; u<2;u++){ 1269 Bonus_count(); 1270 } 1271 1272 Torpedo1_active = 0; //Deactivating the torpedos after VariBonus has been claimed 1273 Torpedo2_active = 0; 1274 Torpedo3_active = 0; 1275 VariTorpedo1 = 0; 1276 VariTorpedo2 = 0; 1277 VariTorpedo3 = 0; 1278 Vari_Bonus_active = 0; 1279 Torpedo1_primer = 1; //and activating the primers again 1280 Torpedo2_primer = 1; 1281 Torpedo3_primer = 1; 1282 } 1283Vari_top_bottom = 1; //locks the rest of the detection 1284Serial.print("Vari 2 activated\ 1285"); 1286} 1287 1288else if (Vari_top_bottom == 0) { //if nothing else is hit = Position 1 1289 1290 if (Vari_Bonus_active == 0) { //if Vari Bonus is active awards additional Bonuses 1291 Score = Score +1000; 1292 Scoring(); 1293 } 1294 else if (Vari_Bonus_active == 1){ 1295 1296 for (int u=0; u<1;u++){ 1297 Bonus_count(); 1298 } 1299 1300 Torpedo1_active = 0; //Deactivating the torpedos after VariBonus has been claimed 1301 Torpedo2_active = 0; 1302 Torpedo3_active = 0; 1303 VariTorpedo1 = 0; 1304 VariTorpedo2 = 0; 1305 VariTorpedo3 = 0; 1306 Vari_Bonus_active = 0; 1307 Torpedo1_primer = 1; //and activating the primers again 1308 Torpedo2_primer = 1; 1309 Torpedo3_primer = 1; 1310 } 1311Vari_top_bottom = 1; //locks the rest of the detection 1312Serial.print("Vari 1 activated\ 1313"); 1314} 1315 1316 1317 1318previousMillis_vari_activate = millis(); 1319previousMillis_vari_deactivate = millis(); 1320Vari_Trigger = 0; 1321//Serial.print("Vari activated\ 1322"); 1323//delay (400); //test Delay is too long. VariCoil has to be activated by TimedEvent. 1324//digitalWrite(solenoidPin_VariTarget, HIGH); //Vari Target Solenoid activated ! 1325//Vari_Trigger = 1; 1326 1327delay(Milli_Bumper); 1328}// End of Evaluation which position has been hit in on the Vari Target///////////////////////////////////////////////////////////// 1329 1330 1331 1332 1333//End of Solenoid Events 1334 1335//Detailed Events////////////////////////////////////////////////////////////////////////////////////// 1336 1337 1338void Spinnerf(){ 1339Score = Score +100; 1340Scoring(); //Show Score 1341delay(50); 1342} 1343 1344void Rollunderf() { 1345Score = Score +5000; 1346Bonus_count(); 1347Scoring(); //Show Score 1348delay(50); 1349} 1350 1351void Rubberband123_event (){ 1352Torpedos_count(); 1353} 1354 1355 1356void Rollover_Lane1_event(){ //The Rollovers each give 1000 points and activate the Torpedos for the captured balls. 1357if (Torpedo1_primer == 1){ 1358 Torpedo1_active =1; 1359 Torpedo1_primer =0; 1360 1361if ((Skillshot1_active == 1) and (Skillshot_active == 1)) { //Check for Skillshot 1362 Score = Score +5000; 1363 Skillshot1_active = 0; 1364 Skillshot_active = 0; 1365 Wire.begin();Wire.beginTransmission(9); // transmit to device #9 1366 Wire.write(13); // sends x 1367 Wire.endTransmission(); // stop transmitting 1368} 1369 1370 1371 1372} 1373 Wire.begin();Wire.beginTransmission(9); // transmit to device #9 1374 Wire.write(11); // sends x 1375 Wire.endTransmission(); // stop transmitting 1376Score = Score +1000; 1377Scoring(); //Show Score 1378delay(Milli); 1379} 1380 1381void Rollover_Lane2_event(){ //The Rollovers each give 1000 points and activate the Torpedos for the captured balls. 1382if (Torpedo2_primer == 1){ 1383 Torpedo2_active =1; 1384 Torpedo2_primer =0; 1385 1386 if ((Skillshot2_active == 1) and (Skillshot_active == 1)) { //Check for Skillshot 1387 Score = Score +5000; 1388 Skillshot2_active = 0; 1389 Skillshot_active = 0; 1390 Wire.begin();Wire.beginTransmission(9); // transmit to device #9 1391 Wire.write(13); // sends x 1392 Wire.endTransmission(); // stop transmitting 1393} 1394} 1395 Wire.begin();Wire.beginTransmission(9); // transmit to device #9 1396 Wire.write(11); // sends x 1397 Wire.endTransmission(); // stop transmitting 1398Score = Score +1000; 1399Scoring(); //Show Score 1400delay(Milli); 1401} 1402void Rollover_Lane3_event(){ //The Rollovers each give 1000 points and activate the Torpedos for the captured balls. 1403if (Torpedo3_primer == 1){ 1404 Torpedo3_active =1; 1405 Torpedo3_primer =0; 1406 1407 if ((Skillshot3_active == 1) and (Skillshot_active == 1)) { //Check for Skillshot 1408 Score = Score +5000; 1409 Skillshot3_active = 0; 1410 Skillshot_active = 0; 1411 Wire.begin();Wire.beginTransmission(9); // transmit to device #9 1412 Wire.write(13); // sends x 1413 Wire.endTransmission(); // stop transmitting 1414} 1415} 1416 Wire.begin();Wire.beginTransmission(9); // transmit to device #9 1417 Wire.write(11); // sends x 1418 Wire.endTransmission(); // stop transmitting 1419Score = Score +1000; 1420Scoring(); //Show Score 1421delay(Milli); 1422} 1423 1424void Skillshot_Timer(){ //Timer for the activation of the skillshot 1425 1426previousMillis_Skillshot = millis(); 1427 1428 1429} 1430 1431 1432 1433 1434 1435void CaptiveBall1_event(){ //The captured balls each give 500 points. If the Torpedos are activated they award 5000 points 1436 // and advance the Bonuscounter. 1437 if (Torpedo1_active == 1){ 1438 Score = Score +5000; 1439 Bonus_count() ; 1440 Scoring(); //Show Score 1441 VariTorpedo1 = 1; 1442} 1443else if (Torpedo1_active == 0){ 1444 Score = Score +500; 1445 Scoring(); //Show Score 1446} 1447previousMillis_cap = millis(); 1448 1449 1450} 1451void CaptiveBall2_event(){ //The captured balls each give 500 points. If the Torpedos are activated they award 5000 points 1452 // and advance the Bonuscounter. 1453 if (Torpedo2_active == 1){ 1454 Score = Score +5000; 1455 Bonus_count() ; 1456 Scoring(); //Show Score 1457 VariTorpedo2 = 1; 1458} 1459else if (Torpedo2_active == 0){ 1460 Score = Score +500; 1461 Scoring(); //Show Score 1462} 1463previousMillis_cap = millis(); 1464} 1465 1466void CaptiveBall3_event(){ //The captured balls each give 500 points. If the Torpedos are activated they award 5000 points 1467 // and advance the Bonuscounter. 1468 if (Torpedo3_active == 1){ 1469 Score = Score +5000; 1470 Bonus_count() ; 1471 Scoring(); //Show Score 1472 VariTorpedo3 = 1; 1473} 1474else if (Torpedo3_active == 0){ 1475 Score = Score +500; 1476 Scoring(); //Show Score 1477} 1478previousMillis_cap = millis(); 1479} 1480 1481void allTorpedosactive(){ //activates the Vari Bonus 1482 Vari_Bonus_active =1; 1483} 1484 1485void Sidelane1_event(){ //The Sidelanes each give 1000 points and activate the Torpedos 1 and 2 for the captured balls. 1486 if (Torpedo1_primer == 1){ 1487 Torpedo1_active =1; 1488 Torpedo1_primer =0; 1489 if ((Skillshot1_active == 1) and (Skillshot_active == 1)) { //Check for Skillshot 1490 Skillshot1_active = 0; 1491 Skillshot_active = 0; 1492} 1493} 1494Score = Score +1000; 1495Scoring(); //Show Score 1496delay(Milli); 1497} 1498 1499void Sidelane2_event(){ //The Sidelanes each give 1000 points and activate the Torpedos 1 and 2 for the captured balls. 1500 if (Torpedo2_primer == 1){ 1501 Torpedo2_active =1; 1502 Torpedo2_primer =0; 1503 if ((Skillshot2_active == 1)and (Skillshot_active == 1)) { //Check for Skillshot 1504 Score = Score +5000; 1505 Skillshot2_active = 0; 1506 Skillshot_active = 0; 1507} 1508} 1509Score = Score +1000; 1510Scoring(); //Show Score 1511delay(Milli); 1512} 1513 1514void Outlane_event() { //Each Outlane awards 10000 points. 1515Score = Score +10000; 1516Scoring(); //Show Score 1517 delay(250); 1518} 1519 1520void Slingshot_event() { //Each Slingshot bounce awards 100 points. 1521Score = Score +100; 1522Torpedos_count(); 1523Scoring(); //Show Score 1524 delay(Milli); 1525} 1526 1527void Target_High_event(){ //The high target awards 10000 points and avtivates the Bonus for the lower Target 1528Torpedos_count(); 1529Bonus_low_target=1; 1530Score = Score +10000; 1531Scoring(); //Show Score 1532delay(Milli); 1533} 1534 1535void Target_low_event(){ //The low target awards 10000 points or 50000 points if the Bonus for the lower Target is active 1536if (Bonus_low_target == 0) { 1537 Score = Score +10000; 1538} 1539else if (Bonus_low_target == 1) { 1540 Bonus_low_target =0; 1541 Score = Score +50000; 1542 Torpedo1_active = 0; //Deactivating the torpedos after Bonus has been claimed 1543 Torpedo2_active = 0; 1544 Torpedo3_active = 0; 1545 VariTorpedo1 = 0; 1546 VariTorpedo2 = 0; 1547 VariTorpedo3 = 0; 1548 // Vari_Bonus_active = 0; Too harsh? 1549 Torpedo1_primer = 1; //and activating the primers again 1550 Torpedo2_primer = 1; 1551 Torpedo3_primer = 1; 1552} 1553 1554 1555Scoring(); //Show Score 1556delay(Milli); 1557} 1558 1559void Torpedos_count(){ //Increases the Torpedo Bonus "Clock" by 1 and calls "Bonus_count" upon reaching 10 Torpedos. 1560Torpedo_Bonus +=1; 1561if (Torpedo_Bonus == 11) { 1562 Torpedo_Bonus =0; 1563 Bonus_count(); 1564} 1565} 1566 1567void Bonus_count() { //Increases the Bonus Counter by 1 and calculates Sunk Ships 1568Max_Bonus_multiplier = (Ships_allive-Ships_sunk); 1569 Wire.begin();Wire.beginTransmission(9); // transmit to device #9 1570 Wire.write(8); // sends x 1571 Wire.endTransmission(); // stop transmitting 1572if (Max_Bonus_multiplier > -11){ //Do this until all Ships are sunk 1573if (Bonus_temp < (Ships_allive-1)){ 1574 Bonus_temp +=1; //Count up the Bonus Counter 1575} 1576else if (Bonus_temp == (Ships_allive-1)){ 1577 Bonus_fix +=1; 1578 Ships_allive -=1; //Set the Bonus Counter to Zero and increase the number of Sunk ships. 1579 Ships_sunk +=1; //Use this later to calculate Bonus Score, each sunken ship adds (11000 - 1000x N) Points 1580 Bonus_temp = 0; //to the normal Bonus Score of (Bonus_temp x 10000). 1581} 1582} 1583if (Max_Bonus_multiplier < -10){ //all ships sunk, super Bonus awarded. 1584 1585if (DoubleBonus == 0){ 1586 DoubleBonus = 1; 1587} 1588 1589} 1590 1591} 1592 1593void Bonus_add() { //Calculates and adds the Bonuspoints to the Score 1594 1595if (Ships_sunk >=1) { 1596 for (int i = 0; i <= Ships_sunk; i++) { 1597 Bonus = Bonus + (110000 - 10000*i); 1598 } 1599} 1600Bonus = Bonus + (Bonus_temp*10000); 1601 1602if (DoubleBonus == 1){ 1603 Bonus = Bonus*2; 1604} 1605Score = Score + Bonus; 1606Bonus = 0; 1607Ships_sunk = 0; 1608Ships_allive= 10; 1609 } 1610 1611 1612 1613void ResetGame() { 1614Score = 0; 1615MaxBalls = 5; 1616Bonus = 0; 1617Kickout_Bonus =0; 1618DoubleBonus = 0; 1619Torpedo_Bonus =0; 1620Torpedo1_primer = 1; 1621Torpedo2_primer = 1; 1622Torpedo3_primer = 1; 1623Ball_active = 0; 1624Torpedo1_active = 0; 1625Torpedo2_active = 0; 1626Torpedo3_active = 0; 1627Vari_Bonus_active = 0; 1628Bonus_low_target = 0; 1629int Rollover_Lane1_int_last = LOW; 1630int Rollover_Lane2_int_last = LOW; 1631int Rollover_Lane3_int_last = LOW; 1632 1633int CaptiveBall1_int_last = LOW; 1634int CaptiveBall2_int_last = LOW; 1635int CaptiveBall3_int_last = LOW; 1636 1637int Outlanes_Links_Rechts_int_last = LOW; 1638int Sidelanes_Left1_int_last = LOW; 1639int Sidelanes_Right2_int_last = LOW; 1640 1641int Target_Low_int_last = LOW; 1642int Target_High_int_last = LOW; 1643int Target_Vari1_int_last = LOW; 1644int Target_Vari2_int_last = LOW; 1645int Target_Vari3_int_last = LOW; 1646int Target_Vari4_int_last = LOW; 1647int Target_Vari5_int_last = LOW; 1648int VariTarget_int_last = LOW; 1649int Kickout_int_last = LOW; 1650 1651int Ballinplay_int_last = LOW; 1652int Slingshots_Left_Right_Up_int_last = LOW; 1653int Rubberband123_int_last = LOW; 1654control_lights(); 1655 1656for (int t=24; t<34;t++){ //Turn off all the "sunk" lights 1657 leds[t] = CHSV(50, 1, 0); // 1658} 1659for (int t=3; t<12;t++){ //Turns off all torpedo lights. They are subsequently re-lit according to the Torpedo scores 1660 leds[t] = CHSV(50, 1, 0); // 1661} 1662 1663 1664Scoring(); 1665delay (100); 1666 1667} 1668 1669 1670 1671 1672 1673 1674void Scoring(){ 1675 ScoreCalc(); 1676 ScoreDisplay(); //Show Score 1677 Serial.print("Score: "); 1678 Serial.print(Score); 1679 Serial.print("\ 1680"); 1681} 1682 1683void ScoreCalc() 1684{ 1685 1686num0 = (Score / 1) % 10; 1687num1 = (Score / 10) % 10; 1688num2 = (Score / 100) % 10; 1689num3 = (Score / 1000) % 10; 1690num4 = (Score / 10000) % 10; 1691num5 = (Score / 100000) % 10; 1692num6 = (Score / 1000000) % 10; 1693num7 = (Score / 10000000) % 10; 1694} 1695 1696void ScoreDisplay() 1697{ 1698 1699lc.clearDisplay(0); // To Clear the display register 1700 1701if (num7 != -1){ 1702lc.setDigit(0,7,num7, false); // To Place a 0 in the column 8 1703} 1704if (num6 != -1){ 1705lc.setDigit(0,6,num6, false); // To Place a 0 in the column 7 1706} 1707if (num5 != -1){ 1708lc.setDigit(0,5,num5, false); // To Place a 0 in the column 6 1709} 1710if (num4 != -1){ 1711lc.setDigit(0,4,num4, false); // To Place a 0 in the column 5 1712} 1713if (num3 != -1){ 1714lc.setDigit(0,3,num3, false); // To Place a 0 in the column 4 1715} 1716if (num2 != -1){ 1717lc.setDigit(0,2,num2, false); // To Place a 0 in the column 3 1718} 1719if (num1 != -1){ 1720lc.setDigit(0,1,num1, false); // To Place a 0 in the column 2 1721} 1722 1723if (num0 != -1){ 1724lc.setDigit(0,0,num0, false); // To Place a 0 in the column 1 1725} 1726 1727} 1728 1729void HighScoring(){ 1730 HighScore = EEPROM.readLong(adress); 1731 HighScoreCalc(); 1732 HighScoreDisplay(); //Show Score 1733 Serial.print("HighScore: "); 1734 Serial.print(HighScore); 1735 Serial.print("\ 1736"); 1737} 1738 1739void HighScoreCalc() 1740{ 1741 1742Highnum0 = (HighScore / 1) % 10; 1743Highnum1 = (HighScore / 10) % 10; 1744Highnum2 = (HighScore / 100) % 10; 1745Highnum3 = (HighScore / 1000) % 10; 1746Highnum4 = (HighScore / 10000) % 10; 1747Highnum5 = (HighScore / 100000) % 10; 1748Highnum6 = (HighScore / 1000000) % 10; 1749Highnum7 = (HighScore / 10000000) % 10; 1750} 1751 1752void HighScoreDisplay() 1753{ 1754 1755lc.clearDisplay(1); // To Clear the display register 1756 1757if (num7 != -1){ 1758lc.setDigit(1,7,Highnum7, false); // To Place a 0 in the column 8 1759} 1760if (num6 != -1){ 1761lc.setDigit(1,6,Highnum6, false); // To Place a 0 in the column 7 1762} 1763if (num5 != -1){ 1764lc.setDigit(1,5,Highnum5, false); // To Place a 0 in the column 6 1765} 1766if (num4 != -1){ 1767lc.setDigit(1,4,Highnum4, false); // To Place a 0 in the column 5 1768} 1769if (num3 != -1){ 1770lc.setDigit(1,3,Highnum3, false); // To Place a 0 in the column 4 1771} 1772if (num2 != -1){ 1773lc.setDigit(1,2,Highnum2, false); // To Place a 0 in the column 3 1774} 1775if (num1 != -1){ 1776lc.setDigit(1,1,Highnum1, false); // To Place a 0 in the column 2 1777} 1778 1779if (num0 != -1){ 1780lc.setDigit(1,0,Highnum0, false); // To Place a 0 in the column 1 1781} 1782 1783} 1784 1785 1786 1787 1788void Kickout_ball() { //Kicks out the ball into the shooter lane. Activates and deactivates the solenoid 1789Ball_active = 0; 1790Skillshot_active = 1; //Skillshot activated 1791Skillshot1_active = 0; 1792Skillshot2_active = 0; 1793Skillshot3_active = 0; 1794 1795int randNumber = random(1,4); 1796 1797if (randNumber == 1){ 1798 Skillshot1_active = 1; //Skillshot activated 1799} 1800if (randNumber == 2){ 1801 Skillshot2_active = 1; //Skillshot activated 1802} 1803if (randNumber == 3){ 1804 Skillshot3_active = 1; //Skillshot activated 1805} 1806 1807digitalWrite(solenoidPin_BallRelease, HIGH); 1808delay (100); //TEST 1809digitalWrite(solenoidPin_BallRelease,LOW); 1810delay (400); 1811} 1812 1813void Releasef() 1814{ 1815 if (Balls <MaxBalls){ 1816 Balls +=1; 1817 Serial.print("Ball Lost"); 1818 Ball_Lost(); 1819 } 1820 1821else if (Balls >=MaxBalls){ 1822 Serial.print("Game Over"); 1823 Game_Over(); 1824 } 1825} 1826 1827void Ball_Lost() { 1828 1829Ball_active = 0; 1830Skillshot_active = 0; 1831Skillshot1_active = 0; 1832Skillshot2_active = 0; 1833Skillshot3_active = 0; 1834 1835Bonus_add(); 1836Scoring(); 1837 1838previousMillis = millis(); 1839delay(1000); 1840Kickout_ball(); 1841 1842Bonus = 0; 1843Kickout_Bonus =0; 1844DoubleBonus = 0; 1845Torpedo_Bonus =0; 1846Bonus_temp = 0; 1847Ships_sunk = 0; 1848Torpedo1_primer = 1; 1849Torpedo2_primer = 1; 1850Torpedo3_primer = 1; 1851 1852Torpedo1_active = 0; 1853Torpedo2_active = 0; 1854Torpedo3_active = 0; 1855Vari_Bonus_active =0; 1856Vari_Bonus_active = 0; 1857Bonus_low_target = 0; 1858 1859control_lights(); 1860delay (100); 1861} 1862 1863void Game_Over(){ 1864 Wire.begin();Wire.beginTransmission(9); // transmit to device #9 1865 Wire.write(7); // sends x 1866 Wire.endTransmission(); // stop transmitting 1867Bonus_add(); 1868Scoring(); 1869MaxBalls = 5; 1870Balls = 1; 1871Oncepergame = 0; 1872Ball_active = 0; 1873Skillshot_active = 0; 1874Skillshot1_active = 0; 1875Skillshot2_active = 0; 1876Skillshot3_active = 0; 1877 if (Score > HighScore){ 1878 HighScore = Score; 1879 EEPROM.writeLong(adress, HighScore); 1880 } 1881HighScoring(); 1882delay (1000); 1883Bonus = 0; 1884Kickout_Bonus =0; 1885DoubleBonus = 0; 1886Torpedo_Bonus =0; 1887Torpedo1_primer = 1; 1888Torpedo2_primer = 1; 1889Torpedo3_primer = 1; 1890Bonus_temp = 0; 1891Ships_sunk = 0; 1892Torpedo1_active = 0; 1893Torpedo2_active = 0; 1894Torpedo3_active = 0; 1895Vari_Bonus_active =0; 1896Bonus_low_target = 0; 1897Startplay_ACTIVE = 0; 1898AttractMode = 0; 1899Score = 0; 1900PlayMusicOnce = 0; 1901delay (1000); 1902ATTRACT(); 1903 1904} 1905 1906void ATTRACT (){ 1907 1908// if (AttatchInteruptOnce == 0) { 1909// AttatchInteruptOnce = 1; 1910// EIFR = 2; 1911// EIFR = bit (INTF1); 1912// delay(200); 1913// EIFR = bit (INTF1); 1914// attachInterrupt(digitalPinToInterrupt (3), interruptstart, FALLING); //PIN 3 1915//Serial.print("Interrupt attatched\ 1916"); 1917// } 1918if (PlayMusicOnce == 0) { 1919 PlayMusicOnce = 1; 1920 1921 Wire.begin();Wire.beginTransmission(9); // transmit to device #9 1922 Wire.write(12); // sends x 1923 Wire.endTransmission(); // stop transmitting 1924 1925} 1926 while (AttractMode == 0) { 1927 HighScoring(); 1928 1929 Serial.print("Attract Mode"); 1930 static uint8_t hue = 0; 1931 for(int i = 0; i < NUM_LEDS; i++) { 1932 if (AttractMode == 1) {break;}; 1933 // Set the i'th led to red 1934 leds[i] = CHSV(hue++, 255, 255); 1935 // Show the leds 1936 FastLED.show(); 1937 // now that we've shown the leds, reset the i'th led to black 1938 // leds[i] = CRGB::Black; 1939 fadeall(); 1940 // Wait a little bit before we loop around and do it again 1941 if ((digitalRead(3) == LOW) ){ 1942 AttractMode = 1; 1943 } 1944 delay(30); 1945 if (AttractMode == 1) {break;}; 1946 } 1947 for(int i = (NUM_LEDS)-1; i >= 0; i--) { 1948 if (AttractMode == 1) {break;}; 1949 // Set the i'th led to red 1950 leds[i] = CHSV(hue++, 255, 255); 1951 // Show the leds 1952 FastLED.show(); 1953 // now that we've shown the leds, reset the i'th led to black 1954 // leds[i] = CRGB::Black; 1955 fadeall(); 1956 // Wait a little bit before we loop around and do it again 1957 if ((digitalRead(3) == LOW) ){ 1958 AttractMode = 1; 1959 } 1960 delay(30); 1961 if (AttractMode == 1) {break;}; 1962 } 1963 if ((digitalRead(3) == LOW) ){ 1964 AttractMode = 1; 1965 } 1966 1967 //delay(Attractdelay1); 1968 if (AttractMode == 1) {break;}; 1969 } 1970} 1971 1972void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } } 1973 1974
Comments
Only logged in users can leave comments