Project showcase

Homemade Arduino Pinball Machine © GPL3+

Conversion of an old pinball playfield to an Arduino-driven, fully working pinball machine.

  • 2,050 views
  • 3 comments
  • 14 respects

Components and supplies

About this project

Arduino Controlled Pinball Machine

Since I always wanted a pinball machine I soon realized that fully working pinball machines in good condition are rather expensive and require quite a bit of maintenance and knowledge, especially the old electromechanical (EM) machines. Searching for a way to build a pinball machine myself, I stumbled upon various homemade pinball projects utilizing Arduinos as the “brain” behind the pinball mechanic. I found Bob Blomquists project page and videos especially helpful in starting my own project. My first idea was to build everything myself, however I soon realized that buying pinball parts is also quite expensive. I found an old pinball playfield with most parts still intact on EBAY and decided to use this as a foundation to build my own machine. If you’re rather interested in building your own machine from the ground up, just buy only the parts you need and use a blank piece of wood instead of the used playfield, the process is exactly the same. The advantage of an existing playfield is that you don’t have to think about the layout and placement of parts, the downside of course is that you are restricted by the original design. The machine is controlled by a single Arduino Mega 2560. If you want to see the machine in action, go to this link, or watch here:

The case

As you can see from the picture, I build a simple wooden case (using MDF) fitting the playfield.

You have to decide what your machine should look like and consider your options beforehand. I opted against building a “standard” machine with legs and a “back” (used to keep scores) since I wanted to be able to pick up the machine and move it or store it with minimal space requirements. Therefore I build the case with a bottom that opens to the side, with this you can place the machine on any surface (for example a table), play it and then store it upright, taking up very little space. For maintenance, the side opening panel allows easy access to all the parts.

The bottom panel houses the power supplies, the Arduino and the power distribution is mounted on the side panels. The playfield rests on brackets mounted on the side panels and is secured with screws. The case and playfield surface is built at a right angle, to play you angle the playfield elevating the back end of the case. This will be done by legs in the future, currently I simply use a solid piece of wood to get the playfield to a 7 degree angle. I didn’t yet install a lid, this will be a simple piece of Plexiglas mounted on the surface of the case with some hinges.

Pinball mechanisms and components

A pinball game usually consists of a core set of components and mechanisms which you need to address and include in your project.

Sensors

Sensors can be of varying types depending on the specific part, but generally it’s a kind of switch which sends a signal once it is triggered by the ball. Most common are leaf switches, rollover switches, targets and micro switches. These will be the main source of inputs coming into our Arduino.

Lights

Lights are an important part, giving the playfield “life” and giving a direct feedback about objectives, points, bonuses and so on. I used simple LEDs, soldered them to an appropriate resistor and mounted them directly under the playfield. This is a very cheap (10 cents per mounted LED) and very lazy way of doing this, using bulbs and sockets is of course a better method, especially for maintenance purposes. This will be the main source of outputs coming out of our Arduino.

Flippers, Pop Bumpers and Slingshots

These are the core components of most pinball machines. If you buy them (or strip them of an old playfield) you are left wondering what to do with them at first, clear instructions are rarely found.

This site is a necessity for everybody thinking about building a pinball machine, all the basics are explained and you can find helpful pictures. The heart of every one of these components is a solenoid, which is simply a tightly wound coil of wire. Once powered, it produces a magnetic field. This is used to propel a “plunger”, s rod of metal into the coil, powering the different, mechanical actions.

Flippers

Wiring the Flippers is best demonstrated using this picture from above mentioned site.

I used the “old” style of coils and wiring, meaning I use coils with 3 contacts. The principle behind flipper coils is that they have to be very strong for the first “kick”, propelling the ball. However, if you continue to hold down the flipper button the coil would simply melt due to the high amperage flowing through it for a prolonged time. “Old” coils use an End-of-Stroke (EOS) switch which mechanically opens once the flipper has reached its maximum elevation. This “forces” the current to go through a second set of wiring with a much higher resistance, resulting in a lower heat production and the survival of the coil for a prolonged amount of time. Coils from modern machines are regulated via the CPU, power send to the coil is reduced after a certain amount of time. This could probably be done with an Arduino, however, I went for the mechanical solution, the upside being that it’s simple and reliable. In addition, “old” coils from the EM era used low voltages of 24V, making them easier to handle in general. The flippers are the only part of the machine not linked in any way to the Arduino, they are triggered (or short circuited) by a simply pair of micro switches and push buttons.

Slingshots

Slingshots generally consist of 2 sensors (leaf switches) and a coil powering a “kicker” which propels the ball away one it triggers the switches. I found a nice blogpost about slingshots and solenoids on this site. Again, like in the case of the flippers, you have to decide how to trigger them. On old EM machines, these coils were linked directly to the power supply, making them very responsive and fast. The switches therefore don’t send a signal but simply short circuit the coil. Since we still need a signal, the triggering of the coil mechanically activates a leaf switch mounted underneath it, this is our signal for the Arduino.

Pop bumpers

Bumpers give the ball a good kick once it makes contact. This is made possible by the white disc seen around most pop bumpers. When a ball rolls onto the white disk it pushes a shaft down and triggers a leaf switch.

I choose to trigger them with the Arduino for 2 reasons. If you go for a mechanical solution (like with the slingshots) you will only get a weak “kick” out of your pop bumpers since the coils are activated for a very short amount of time before the ball is propelled out again. Originally this was solved by adding a second set of switches which were triggered when the coil had been fully energized. Only then power to the coil was cut, allowing for a good, powered kick. Modern machines are triggered by the CPU, the switch sends a signal to the CPU (our Arduino) which in turn energizes the coil for the right amount of time. You probably know that 24V and the Arduino do not work well together; therefore we have to use MOSFETS (metal–oxide–semiconductor field-effect transistor) as our mediators. I used IRL540N MOSFETS, they are logical level MOSFETS (meaning you can reliably trigger them with the 5V signal from the Arduino) and can handle the currents and amperage involved. For the wiring I used this basic layout, please do some research on the topic beforehand though, 24V will kill your Arduino quickly if your wiring is incorrect.

This however allows for a precise timing (and scoring) of the pop bumpers. Since we have a very quick action here, delays are not practical (and shouldn’t be used anyway…more in the code section). I used millis() to time the start and end of the bumper activation, try and error left me with 40 milliseconds activation as a good value.

Display

I used a generic I2C display. This is pretty standard and can be customized as to your needs, I use it to display the score, high score and number of balls played.

Sound

I used a MP3 shield board based on the VS1053B for the sound. This was in hindsight a bad choice. This board is cheap and relatively easy to use, however, the processing time and resulting delay is too high for some pinball actions. This is probably not noticeable in most applications, however the pop bumpers with their 40 milliseconds timing are thrown of just enough to disrupt gameplay. Sound is therefore restricted to “slow” actions like rollover switches, targets and general music.

Arduino and coding

As you can see from the picture, including the mp3 shield and the display, I used up every one of the available pins from an Arduino Mega 2560. To go further, I would have needed to use shift registers, this would have been cleaner, but I’m no expert and the project was complicated enough already, next time perhaps when I need even more pins….

The Arduino is the brain behind everything, it determines when switches are activated, it turns lights on or off accordingly, it keeps track of the scoring, it displays the score and ball number, it supplies the coils with energy and keeps track of the game logic.

I tried to keep the code simple and clean (and failed in most cases…) using separate functions (void) for nearly everything. Besides the simple in/out relations between signals (if target is hit, turn of light A, turn on light B, set condition X to 1, etc..) there is some game logic involved.

I based this on the original game (AZTEC pinball), for example if you manage to spell out the word AZTEC you activate the bonus ball feature, meaning if you manage to hit the centre target you are awarded an extra ball. This also included the activation of double bonus features, extra points, and so on. You are free to do what you like, since we are not restricted by the old EM limitations of witches and relays, you can make the game logic as complicated or as simple as you like.

If you are interested in building you own machine, I’m sure you will find bits and pieces of my code helpful, especially the pop bumper timing was a lot of try and error and might come in handy for your own projects.

The machine also includes a very basic “Attract” mode, meaning it does something while you are not playing. I went for a simple lightshow using the LEDs controlled by the Arduino. If you take a look at this section of the code, beware! This was towards the end of the project and is a disgrace, using delays, no arrays and is basically a wall of copied text and commands. You can start playing by pushing the start button at the front, this is possible by using the Interrupt feature of the Arduino.

If you want to see the attract mode in action, go to this link, or watch here:

Power Supply

To power the machine, I use 3 different voltages. A 24 volt power supply powers the coils, a 12V power supply powers the ambient lighting and a 5V power supply powers the Arduino.

Wiring

I can’t tell how much wire went into this machine, let’s just say a lot! Since this was my first project of this magnitude, my wiring is a mess and should serve as a deterrent. I have no colour coding (didn’t have enough wire of the respective colour and was too impatient to wait for more) and I didn’t construct a wiring harness….lazy. On the upside I can at least say that there are no loose wires, I tied everything down and I used crimp terminals for all the connections. This allows me to quickly disconnect and exchange parts and component without additional soldering. Despite claims to the contrary, I never had a problem with crimp terminals coming loose despite the “action” of the pinball machine.

I hope this mess encourages you to do better, I know I will with my next projects.

Summary

I hope I could be of some help if you are interested in a similar project. It was a lot of work, and you will undoubtedly discover obstacles and challenges on the way. However, it was (and is) a lot of fun and is definitely a worthwhile project if you like pinball.

Schematics

MOSFET wiring for solenoid control
sketchmosfet_0kjKc2XneW.fzz

Code

Arduino controlled Pinball Machine CodeC/C++
Allows the Arduino to control the game play of a home made pinball machine. Controls lights, sensors, voltage to coils, scoring, etc.
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

#include <SPI.h>
#include <SdFat.h>
#include <FreeStack.h>
//and the MP3 Shield Library
#include <SFEMP3Shield.h>
#include <EEPROMex.h>
#include <Arduino.h>

SdFat sd;
SFEMP3Shield MP3player;

LiquidCrystal_I2C lcd(0x3f, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

 
 
 //Variables
int Balls = 1;  //Number of Balls
int MaxBalls = 5; //Number of Maxballs
int Lapscountertemp = 0;  //Testing
int Resetcounter =0;  //Reset at Loss of Ball
long Score = 0;  //Total Score


int adress = 0;
long Highscore;
long Bonus = 0;  //Bonus
int DoubleBonus = 0;
long DoubleBonuscounter = 0;  //Counter for 2xBonus
int AdvanceBonus = 0;   
int AdvanceBonuscounter = 0;
int Arrowcounter = 0;
int Arrowbonus = 0;
int DoubleBonus_Lit = 0; 
int Milli = 150; //Delay 1
int MilliRoll = 100; //Delay 2
int Milli_Bumper = 40; //Delay for Bumpers
int AZTEC_A = 0;
int AZTEC_Z = 0;
int AZTEC_T = 0;
int AZTEC_E = 0;
int AZTEC_C = 0;
int Ball_Bonus = 0;
int Kickout_Bonus =0;
int Target_Middle = 0;
int Target_Points = 0;
volatile int AttractMode = 0;
int Attractcounter1 = 0;
int Attractcounter2 = 0;
int Attractcounter3 = 0;
int Attractcounter4 = 0;
int Attractdelay1 = 800;
int Attractdelay2 = 400;
int Startplay_A = 0;
int Startplay_ACTIVE = 0;

int RolloverLinks_Rechts_int_last =LOW;
int RolloverMitte_int_last = LOW;
int Slingshots_Links_Rechts_last = LOW;
int kickoutreset = 0;

int  Target_Z_last= LOW;
int  Target_T_last= LOW;
int  Target_E_last= LOW;
int  Target_C_last= LOW;
int  Target_Middle_last= LOW;
int  Target_Points_last= LOW;
int  Ramp_last= LOW;

int SwitchtopLinks_Rechts_last = LOW;
int SwitchtopMitte_last = LOW;

int Outlanes_Links_Rechts_last =LOW;
int Sidelanes_Links_Rechts_last = LOW;


//Mosfet Variables
const long interval = 40;           // interval at which to trigger solenoids (milliseconds)
unsigned long  Solenoid_TimeTemp;
unsigned long  Solenoid_FireTime;
unsigned long previousMillis = 0;
unsigned long currentMillis = 0;
int MosfetState = LOW;    

int Kickout_Trigger = 0;
int BumperLinks_Trigger = 0;
int BumperRechts_Trigger = 0;
int BumperUnten_Trigger = 0;

//PINS
//int Startplay = 19;
int RolloverLinks_Rechts = 22; 
int RolloverMitte = 23;

int Kickout = 24; 
int Bumper_Links = 25; 
int Bumper_Rechts = 26; 
int Bumper_Unten = 27; 

int Target_Z = 28; 
int Target_T = 29; 
int Target_E = 30; 
int Target_C = 31; 
int Target_M = 32; 
int Target_P = 33; 

int SwitchtopLinks_Rechts = 34; 
int SwitchtopMitte = 35;
int Release = 36; 


int Spinner = 37;
int Ramp = 38;
int Slingshots_Links_Rechts = 39;


int Outlanes_Links_Rechts = 42;
int Sidelanes_Links_Rechts = 43;
const int solenoidPin_Kickout = 44;
const int solenoidPin_BumperLinks = 45;
const int solenoidPin_BumperRechts = 46;


//50,51,52 Display
const int solenoidPin_Release = 49;
const int solenoidPin_BumperUnten = 48;


//Lights

char Light_A = A0;    //x2
char Light_Z = A1;    //x2
char Light_T = A2;    //x2
char Light_E = A3;    //x2
char Light_C = A4;    //x2
char Light_Ball_Bonus = A5;
int Light_A_Target = A6;
int Light_Z_Target = A7;
int Light_T_Target = A8;
int Light_E_Target = A9;
int Light_C_Target = A10;
int Light_Arrow = A11;
int Light_Double_Bonus_Lit = A12;   //x2
int Light_Advance_Bonus = A13;  //x3
int Light_Double_Bonus = A14;  //x1

int Light__Bonus_1 = 14;
int Light__Bonus_2 = 15;
int Light__Bonus_3 = 16;
int Light__Bonus_4 = 17;
int Light__Bonus_5 = 41;//18
int Light__Bonus_6 = 19;  
int Light__Bonus_7 = 40;
int Light__Bonus_8 = A15;
int Light__Bonus_9 = 5;
int Light__Bonus_10 = 47;
//mp3 shield 2,2,3,6,7,8,9

//-A15

//SOUNDS

//1 Bumper
//2 Slingshots
//3 Spinner
//4 Target
//5 Kickoutlane
//6 Ball lost
//7 Game Over

void setup() {
  // put your setup code here, to run once:



  
lcd.begin(16,4);   // initialize the lcd for 16 chars 4 lines, turn on backlight
lcd.clear();
lcd.print("Aztec Pinball");


//MP3

sd.begin(SD_SEL, SPI_FULL_SPEED);
MP3player.begin();
//

//Variables



// Inputs

 pinMode(RolloverLinks_Rechts,INPUT);  //Rollover Left and right
 pinMode(RolloverMitte,INPUT);  //Rollover Mid
 pinMode(Target_Z,INPUT);  //Target Z
 pinMode(Target_T,INPUT);  //Target T
 pinMode(Target_E,INPUT);  //Target E
 pinMode(Target_C,INPUT);  //Target C
 pinMode(Target_M,INPUT);  //Target M
 pinMode(Target_P,INPUT);  //Target P

 pinMode(Release,INPUT);  //Release
 pinMode(Kickout,INPUT);  //Kickout
 pinMode(Bumper_Rechts,INPUT); 
 pinMode(Bumper_Links,INPUT); 
 pinMode(Bumper_Unten,INPUT); 

pinMode(SwitchtopLinks_Rechts,INPUT); 
pinMode(SwitchtopMitte,INPUT); 
pinMode(Spinner,INPUT); 
pinMode(Ramp,INPUT); 

//pinMode(Startplay,INPUT); 
pinMode(Outlanes_Links_Rechts,INPUT); 
pinMode(Sidelanes_Links_Rechts,INPUT); 

//Outputs
pinMode(solenoidPin_Release, OUTPUT);
pinMode(solenoidPin_Kickout, OUTPUT);
pinMode(solenoidPin_BumperLinks, OUTPUT);
pinMode(solenoidPin_BumperRechts, OUTPUT);
pinMode(solenoidPin_BumperUnten, OUTPUT);


pinMode(Light_A, OUTPUT);
pinMode(Light_Z, OUTPUT);
pinMode(Light_T, OUTPUT);
pinMode(Light_E, OUTPUT);
pinMode(Light_C, OUTPUT);
pinMode(Light_Ball_Bonus, OUTPUT);
pinMode(Light_Arrow, OUTPUT);

pinMode(Light_A_Target, OUTPUT);
pinMode(Light_Z_Target, OUTPUT);
pinMode(Light_T_Target, OUTPUT);
pinMode(Light_E_Target, OUTPUT);
pinMode(Light_C_Target, OUTPUT);

pinMode(Light_Double_Bonus_Lit, OUTPUT);
pinMode(Light_Double_Bonus, OUTPUT);
pinMode(Light_Advance_Bonus, OUTPUT);

pinMode(Light__Bonus_1, OUTPUT);
pinMode(Light__Bonus_2, OUTPUT);
pinMode(Light__Bonus_3, OUTPUT);
pinMode(Light__Bonus_4, OUTPUT);
pinMode(Light__Bonus_5, OUTPUT);
pinMode(Light__Bonus_6, OUTPUT);
pinMode(Light__Bonus_7, OUTPUT);
pinMode(Light__Bonus_8, OUTPUT);
pinMode(Light__Bonus_9, OUTPUT);
pinMode(Light__Bonus_10, OUTPUT);
/////////

digitalWrite(Light_A, LOW);
digitalWrite(Light_Z, LOW);
digitalWrite(Light_T, LOW);
digitalWrite(Light_E, LOW);
digitalWrite(Light_C, LOW);
digitalWrite(Light_Ball_Bonus, LOW);
digitalWrite(Light_Arrow, LOW);

digitalWrite(Light_Double_Bonus_Lit, LOW); 
digitalWrite(Light_Double_Bonus, LOW); 
digitalWrite(Light_Advance_Bonus, LOW); 

digitalWrite(Light_A_Target, HIGH); 
digitalWrite(Light_Z_Target, HIGH); 
digitalWrite(Light_T_Target, HIGH); 
digitalWrite(Light_E_Target, HIGH); 
digitalWrite(Light_C_Target, HIGH); 

digitalWrite(Light__Bonus_1, LOW); 
digitalWrite(Light__Bonus_2, LOW); 
digitalWrite(Light__Bonus_3, LOW); 
digitalWrite(Light__Bonus_4, LOW); 
digitalWrite(Light__Bonus_5, LOW); 
digitalWrite(Light__Bonus_6, LOW); 
digitalWrite(Light__Bonus_7, LOW); 
digitalWrite(Light__Bonus_8, LOW); 
digitalWrite(Light__Bonus_9, LOW); 
digitalWrite(Light__Bonus_10, LOW); 


}  //END SETUP

//////////////////////////////////////////////////////////////////////////////////////////////////////////MAIN
void loop() { 
  // put your main code here, to run repeatedly:


EIFR = bit (INTF5);
attachInterrupt(5, interruptstart, RISING);

  
if (AttractMode == 0) {

ATTRACT();
  } //END ATTRACT



if (AttractMode == 1)  {


if (Startplay_ACTIVE == 0){

    Startplay_ACTIVE = 1;
    MP3player.stopTrack();
    MP3player.playMP3("009.mp3");
    ResetGame();
    Kickout_ball();
}

unsigned long currentMillis = millis();       //Starting Time
detectCollision();                              //Collision and Switch detection
control_lights();                              //Lights
check_conditions();                            //Checks for Bonuses

//Timed Soneloid Triggers running in Main Loop


//MOSFET !

int difference = currentMillis - previousMillis;
 
 if ((difference >= interval)and (BumperLinks_Trigger == 1)) {
   previousMillis = currentMillis; 
  BumperLinks_Trigger = 0;
 digitalWrite(solenoidPin_BumperLinks, LOW);
 }
if ((difference >= interval)and (BumperRechts_Trigger == 1)) {
   previousMillis = currentMillis; 
  BumperRechts_Trigger = 0;
 digitalWrite(solenoidPin_BumperRechts, LOW);
 } 
 if ((difference >= interval)and (BumperUnten_Trigger == 1)) {
   previousMillis = currentMillis; 
  BumperUnten_Trigger = 0;
 digitalWrite(solenoidPin_BumperUnten, LOW);
 }

}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////MAIN ENDE
void interruptstart(){      //  ISR!
  
    AttractMode = 1;
    detachInterrupt(5);
  }


void ATTRACT (){      //Bad, lazy code !!
long Highscore = EEPROM.readLong(adress);
lcd.clear();
lcd.print("Aztec Pinball");
lcd.setCursor(0,1);
lcd.print("Highscore  ");
lcd.print(Highscore);

  
while (AttractMode == 0) {
    

lcd.clear();
lcd.print("Aztec Pinball");
lcd.setCursor(0,1);
lcd.print("Highscore  ");
lcd.print(Highscore);

Attractcounter1 = 0;
Attractcounter2 = 0;
Attractcounter3 = 0;
Attractcounter4 = 0;
AttractMode = 0;

digitalWrite(Light_A_Target, LOW); 
digitalWrite(Light_Z_Target, LOW); 
digitalWrite(Light_T_Target, LOW); 
digitalWrite(Light_E_Target, LOW); 
digitalWrite(Light_C_Target, LOW); 
digitalWrite(Light_A, LOW);
digitalWrite(Light_Z, LOW);
digitalWrite(Light_T, LOW);
digitalWrite(Light_E, LOW);
digitalWrite(Light_C, LOW);
digitalWrite(Light_Ball_Bonus, LOW);
digitalWrite(Light_Arrow, LOW);
digitalWrite(Light_Double_Bonus_Lit, LOW); 
digitalWrite(Light_Double_Bonus, LOW); 
digitalWrite(Light_Advance_Bonus, LOW); 
digitalWrite(Light__Bonus_1, LOW); 
digitalWrite(Light__Bonus_2, LOW); 
digitalWrite(Light__Bonus_3, LOW); 
digitalWrite(Light__Bonus_4, LOW); 
digitalWrite(Light__Bonus_5, LOW); 
digitalWrite(Light__Bonus_6, LOW); 
digitalWrite(Light__Bonus_7, LOW); 
digitalWrite(Light__Bonus_8, LOW); 
digitalWrite(Light__Bonus_9, LOW); 
digitalWrite(Light__Bonus_10, LOW); 




digitalWrite(Light__Bonus_1, HIGH); 
delay(Attractdelay1);if (AttractMode == 1)  {break;}; 
digitalWrite(Light__Bonus_2, HIGH); 
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light__Bonus_3, HIGH); 
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light__Bonus_4, HIGH); 
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light__Bonus_5, HIGH); 
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light__Bonus_6, HIGH); 
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light__Bonus_7, HIGH); 
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light__Bonus_8, HIGH); 
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light__Bonus_9, HIGH); 
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light__Bonus_10, HIGH); 
delay(Attractdelay1);if (AttractMode == 1)  {break;};
while (Attractcounter1 <4){
digitalWrite(Light__Bonus_1, LOW); 
digitalWrite(Light__Bonus_2, LOW); 
digitalWrite(Light__Bonus_3, LOW); 
digitalWrite(Light__Bonus_4, LOW); 
digitalWrite(Light__Bonus_5, LOW); 
digitalWrite(Light__Bonus_6, LOW); 
digitalWrite(Light__Bonus_7, LOW); 
digitalWrite(Light__Bonus_8, LOW); 
digitalWrite(Light__Bonus_9, LOW); 
digitalWrite(Light__Bonus_10, LOW); 
delay(Attractdelay2);if (AttractMode == 1)  {break;};
digitalWrite(Light__Bonus_1, HIGH); 
digitalWrite(Light__Bonus_2, HIGH); 
digitalWrite(Light__Bonus_3, HIGH); 
digitalWrite(Light__Bonus_4, HIGH); 
digitalWrite(Light__Bonus_5, HIGH); 
digitalWrite(Light__Bonus_6, HIGH); 
digitalWrite(Light__Bonus_7, HIGH); 
digitalWrite(Light__Bonus_8, HIGH); 
digitalWrite(Light__Bonus_9, HIGH); 
digitalWrite(Light__Bonus_10, HIGH);     
delay(Attractdelay2);if (AttractMode == 1)  {break;};
Attractcounter1 +=1;
}

digitalWrite(Light_A, HIGH);
digitalWrite(Light_A_Target, HIGH); 
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light_Z, HIGH);
digitalWrite(Light_Z_Target, HIGH); 
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light_T, HIGH);
digitalWrite(Light_T_Target, HIGH); 
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light_E, HIGH);
digitalWrite(Light_E_Target, HIGH); 
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light_C, HIGH);
digitalWrite(Light_C_Target, HIGH); 
delay(Attractdelay1);if (AttractMode == 1)  {break;};

while (Attractcounter2 <4){
digitalWrite(Light_A, LOW);
digitalWrite(Light_A_Target, LOW); 
digitalWrite(Light_Z, LOW);
digitalWrite(Light_Z_Target, LOW); 
digitalWrite(Light_T, LOW);
digitalWrite(Light_T_Target, LOW); 
digitalWrite(Light_E, LOW);
digitalWrite(Light_E_Target, LOW); 
digitalWrite(Light_C, LOW);    
digitalWrite(Light_C_Target, LOW); 
delay(Attractdelay2);if (AttractMode == 1)  {break;};
digitalWrite(Light_A, HIGH);
digitalWrite(Light_A_Target, HIGH); 
digitalWrite(Light_Z, HIGH);
digitalWrite(Light_Z_Target, HIGH); 
digitalWrite(Light_T, HIGH);
digitalWrite(Light_T_Target, HIGH); 
digitalWrite(Light_E, HIGH);
digitalWrite(Light_E_Target, HIGH); 
digitalWrite(Light_C, HIGH);
digitalWrite(Light_C_Target, HIGH); 
delay(Attractdelay2);if (AttractMode == 1)  {break;};
Attractcounter2 +=1;
}

digitalWrite(Light_Ball_Bonus, HIGH);
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light_Arrow, HIGH);
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light_Double_Bonus_Lit, HIGH); 
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light_Double_Bonus, HIGH); 
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light_Advance_Bonus, HIGH); 
delay(Attractdelay1);if (AttractMode == 1)  {break;};
while (Attractcounter3 <4){
digitalWrite(Light_Ball_Bonus, LOW);
digitalWrite(Light_Arrow, LOW);
digitalWrite(Light_Double_Bonus_Lit, LOW); 
digitalWrite(Light_Double_Bonus, LOW); 
digitalWrite(Light_Advance_Bonus, LOW); 
delay(Attractdelay2);if (AttractMode == 1)  {break;};
digitalWrite(Light_Ball_Bonus, HIGH);
digitalWrite(Light_Arrow, HIGH);
digitalWrite(Light_Double_Bonus_Lit, HIGH); 
digitalWrite(Light_Double_Bonus, HIGH); 
digitalWrite(Light_Advance_Bonus, HIGH); 
delay(Attractdelay2);if (AttractMode == 1)  {break;};
Attractcounter3 +=1;
}
delay(2000);if (AttractMode == 1)  {break;};

digitalWrite(Light__Bonus_1, LOW); 
digitalWrite(Light_Ball_Bonus, LOW);
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light__Bonus_2, LOW); 
digitalWrite(Light_C, LOW); 
digitalWrite(Light_Z_Target, LOW);  
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light__Bonus_3, LOW); 
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light__Bonus_4, LOW); 
digitalWrite(Light_E, LOW);
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light_Arrow, LOW);
digitalWrite(Light__Bonus_5, LOW); 
digitalWrite(Light_T_Target, LOW); 
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light__Bonus_6,LOW); 
digitalWrite(Light_T, LOW);
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light__Bonus_7, LOW); 
digitalWrite(Light_Advance_Bonus, LOW); 
digitalWrite(Light_E_Target, LOW); 
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light_Double_Bonus_Lit, LOW); 
digitalWrite(Light__Bonus_8, LOW); 
digitalWrite(Light_Z, LOW);
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light__Bonus_9, LOW); 
digitalWrite(Light_C_Target, LOW); 
digitalWrite(Light_Double_Bonus, LOW);  
delay(Attractdelay1);if (AttractMode == 1)  {break;};
digitalWrite(Light__Bonus_10, LOW);
digitalWrite(Light_A, LOW);
digitalWrite(Light_A_Target, LOW); 
delay(Attractdelay1);if (AttractMode == 1)  {break;};



}
}

void check_conditions(){
 if ((AZTEC_A ==1) && (AZTEC_Z ==1) && (AZTEC_T ==1) && (AZTEC_E ==1) && (AZTEC_C ==1 && (Resetcounter ==0))){
  Ball_Bonus =1;
  DoubleBonus =1;
  Resetcounter = 1;
 }

 if (DoubleBonuscounter >50) {
  DoubleBonus =1; 
 }



 if (AdvanceBonuscounter >10) {
  if (AdvanceBonus == 0) {
    AdvanceBonus ==1; 
  }
  else if (AdvanceBonus == 1) {
    AdvanceBonus ==0;
  }
  AdvanceBonuscounter = 0;
 }
}


void detectCollision(){
  
int RolloverLinks_Rechts_int = digitalRead(RolloverLinks_Rechts);  //Variable for Rollover Switches
int RolloverMitte_int = digitalRead(RolloverMitte);  //Variable for Rollover Switches

int SwitchtopLinks_Rechts_int = digitalRead(SwitchtopLinks_Rechts);  //Variable for Rollover Switches
int SwitchtopMitte_int = digitalRead(SwitchtopMitte);  //Variable for Rollover Switches
int Ramp_int = digitalRead(Ramp);  //Variable for Ramp
int Spinner_int = digitalRead(Spinner);  //Variable for Spinner
int Outlanes_Links_Rechts_int = digitalRead(Outlanes_Links_Rechts);  //Variable for Outlanes Links Rechts
int Sidelanes_Links_Rechts_int = digitalRead(Sidelanes_Links_Rechts);  //Variable for Sidelanes Links Rechts
int Slingshots_Links_Rechts_int = digitalRead(Slingshots_Links_Rechts);  //Variable for Sidelanes Links Rechts

int Target_Z_int = digitalRead(Target_Z);  //Variable for Target Z
int Target_T_int = digitalRead(Target_T);  //Variable for Target T
int Target_E_int = digitalRead(Target_E);  //Variable for Target E
int Target_C_int = digitalRead(Target_C);  //Variable for Target C
int Target_M_int = digitalRead(Target_M);  //Variable for Target M
int Target_P_int = digitalRead(Target_P);  //Variable for Target P

//Rollovers Links und Rechts und Mitte

if ((RolloverLinks_Rechts_int == HIGH) && (RolloverLinks_Rechts_int_last == LOW)  ){      //Rollover pressed

Score100f();
RolloverLinks_Rechts_int_last = HIGH;
 MP3player.stopTrack();
 MP3player.playMP3("001.mp3");
}

else if ((RolloverLinks_Rechts_int == LOW) && (RolloverLinks_Rechts_int_last == HIGH)  ){    //Rollover released
 RolloverLinks_Rechts_int_last = LOW; 
delay (MilliRoll);
}

if ((RolloverMitte_int == HIGH) && (RolloverMitte_int_last == LOW)  ){      //Rollover pressed

Bonusf();
RolloverMitte_int_last = HIGH;
 MP3player.stopTrack();
MP3player.playMP3("001.mp3");
}

else if ((RolloverMitte_int == LOW) && (RolloverMitte_int_last == HIGH)  ){ //Rollover released
 RolloverMitte_int_last = LOW;
 delay (MilliRoll); 
}
//Switches Left, right and mid


if ((SwitchtopLinks_Rechts_int == HIGH) && (SwitchtopLinks_Rechts_last == LOW)  ){      //Rollover pressed

Arrowbonus =0;      //deacitvate Spinner Bonus 

if (AdvanceBonus == 0) {  
Score1000f();
}
else if (AdvanceBonus == 1) {  
Score1000f();
Bonusf();
AdvanceBonus = 0;
}


SwitchtopLinks_Rechts_last = HIGH;
//MP3player.stopTrack();
// MP3player.playMP3("001.mp3");
}

else if ((SwitchtopLinks_Rechts_int == LOW) && (SwitchtopLinks_Rechts_last == HIGH)  ){    //Rollover released
 SwitchtopLinks_Rechts_last = LOW; 
delay (MilliRoll);
}

if ((SwitchtopMitte_int == HIGH) && (SwitchtopMitte_last == LOW)  ){      //Rollover pressed
Arrowbonus = 1;        //acitvate Spinner Bonus 
AZTEC_Af();
SwitchtopMitte_last = HIGH;
//MP3player.stopTrack();
 //MP3player.playMP3("001.mp3");
}

else if ((SwitchtopMitte_int == LOW) && (SwitchtopMitte_last == HIGH)  ){    //Rollover released
 SwitchtopMitte_last = LOW; 
delay (MilliRoll);
}

//Slingshots

if ((Slingshots_Links_Rechts_int == HIGH) && (Slingshots_Links_Rechts_last == LOW)  ){      //Rollover pressed


Score150f();
MP3player.stopTrack();
MP3player.playMP3("002.mp3");
 DoubleBonuscounter +=1; 
 //lcd.setCursor(4,3);
 //lcd.print("Slingshots");
Slingshots_Links_Rechts_last = HIGH;
}

else if ((Slingshots_Links_Rechts_int == LOW) && (Slingshots_Links_Rechts_last == HIGH)  ){    //Rollover released
 Slingshots_Links_Rechts_last = LOW; 
delay (MilliRoll);
}


//Outlanes

if ((Outlanes_Links_Rechts_int == HIGH) && (Outlanes_Links_Rechts_last == LOW)  ){      //Rollover pressed

Bonusf();
Score10000f();
 //lcd.setCursor(4,3);
 //lcd.print("Outlane");
Outlanes_Links_Rechts_last = HIGH;
MP3player.stopTrack();
 MP3player.playMP3("001.mp3");
}

else if ((Outlanes_Links_Rechts_int == LOW) && (Outlanes_Links_Rechts_last == HIGH)  ){    //Rollover released
 Outlanes_Links_Rechts_last = LOW; 
delay (MilliRoll);
}


//Sidelanes

if ((Sidelanes_Links_Rechts_int == HIGH) && (Sidelanes_Links_Rechts_last == LOW)  ){      //Rollover pressed


Score5000f();
//lcd.setCursor(4,3);
//lcd.print("Sidelane");
Sidelanes_Links_Rechts_last = HIGH;
MP3player.stopTrack();
 MP3player.playMP3("001.mp3");
}

else if ((Sidelanes_Links_Rechts_int == LOW) && (Sidelanes_Links_Rechts_last == HIGH)  ){    //Rollover released
 Sidelanes_Links_Rechts_last = LOW; 
delay (MilliRoll);
}



  


//RAMP
if ((Ramp_int == HIGH) && (Ramp_last == LOW)  ){      //RAMP Pressed

Rampf();
Ramp_last = HIGH;
}

else if ((Ramp_int == LOW) && (Ramp_last == HIGH)  ){    //Ramp released
 Ramp_last = LOW; 
delay (MilliRoll);
}



// TARGETS

if ((Target_Z_int == HIGH) && (Target_Z_last == LOW)  ){      //Target hit
Target_Z_last = HIGH;
  
  AZTEC_Z = 1;
  Score = Score +1000;
  //lcd.setCursor(4,3);
  //lcd.print("Z");   
  MP3player.stopTrack();
  MP3player.playMP3("004.mp3");
  
delay (MilliRoll); 
}

else if ((Target_Z_int == LOW) && (Target_Z_last == HIGH)  ){ //Target released
 Target_Z_last = LOW;
 delay (MilliRoll); 
}

if ((Target_T_int == HIGH) && (Target_T_last == LOW)  ){      //Target hit
Target_T_last = HIGH;

  AZTEC_T = 1;
  Score = Score +1000;
  //lcd.setCursor(4,3);
  //lcd.print("T");   
  MP3player.stopTrack();
  MP3player.playMP3("004.mp3");
  
delay (MilliRoll); 
}

else if ((Target_T_int == LOW) && (Target_T_last == HIGH)  ){ //Target released
 Target_T_last = LOW;
 delay (MilliRoll); 
}

if ((Target_E_int == HIGH) && (Target_E_last == LOW)  ){      //Target hit
Target_E_last = HIGH;

  AZTEC_E = 1;
  Score = Score +1000;
  //lcd.setCursor(4,3);
  //lcd.print("E");   
  MP3player.stopTrack();
  MP3player.playMP3("004.mp3");
  
delay (MilliRoll); 
}

else if ((Target_E_int == LOW) && (Target_E_last == HIGH)  ){ //Target released
 Target_E_last = LOW;
delay (MilliRoll); 
}


if ((Target_C_int == HIGH) && (Target_C_last == LOW)  ){      //Target hit
Target_C_last = HIGH;

  AZTEC_C = 1;
  Score = Score +1000;
  //lcd.setCursor(4,3);
  //lcd.print("C");   
  MP3player.stopTrack();
  MP3player.playMP3("004.mp3");
  
delay (MilliRoll); 
}

else if ((Target_C_int == LOW) && (Target_C_last == HIGH)  ){ //Target released
 Target_C_last = LOW;
 delay (MilliRoll); 
}

if ((Target_M_int == HIGH) && (Target_Middle_last == LOW)  ){      //Target hit
Target_Middle_last = HIGH;

  Target_Middle = 1;
  Score = Score +500; 
      if (Ball_Bonus ==1){
       MaxBalls +=1;
       Ball_Bonus = 0;
      digitalWrite(Light_Ball_Bonus, LOW);
      }
  
  MP3player.stopTrack();
  MP3player.playMP3("004.mp3");
  Bonusf();
  
delay (MilliRoll); 
}

else if ((Target_M_int == LOW) && (Target_Middle_last == HIGH)  ){ //Target released
 Target_Middle_last = LOW;
 delay (MilliRoll); 
}

if ((Target_P_int == HIGH) && (Target_Points_last == LOW)  ){      //Target hit
Target_Points_last = HIGH;

Target_Points += 1;
//MP3player.stopTrack();
//MP3player.playMP3("004.mp3");

    if (AdvanceBonus == 0) {  
        Score1000f();
        }
    else if (AdvanceBonus == 1) {  
        Score1000f();
        Bonusf();
        AdvanceBonus =0;
        }

delay (45); //shorter because of Bumpers
}

else if ((Target_P_int == LOW) && (Target_Points_last == HIGH)  ){ //Target released
 Target_Points_last = LOW;
 delay (MilliRoll); 
}


//SPINNER
if ((digitalRead(Spinner) == HIGH) ){

Spinnerf();

}



//Ball Release
if ((digitalRead(Release) == HIGH) ){
Releasef();

}

//Kickout
if ((digitalRead(Kickout) == HIGH)&& (kickoutreset ==0) ){
kickoutreset = 1;
Kickoutf();

}

//Bumpers
if ((digitalRead(Bumper_Links) == HIGH) ){

BumperLf();

}
if ((digitalRead(Bumper_Rechts) == HIGH) ){

BumperRf();

}
if ((digitalRead(Bumper_Unten) == HIGH) ){

BumperUf();

}
}  // ENDE Collision Detection


//Lights

void control_lights(){
  
if (AZTEC_A ==1){
  digitalWrite(Light_A, HIGH);
  digitalWrite(Light_A_Target, LOW); 
}
if (AZTEC_Z ==1){
  digitalWrite(Light_Z, HIGH);
   digitalWrite(Light_Z_Target, LOW); 
}
if (AZTEC_T ==1){
  digitalWrite(Light_T, HIGH);
   digitalWrite(Light_T_Target, LOW); 
}
if (AZTEC_E ==1){
  digitalWrite(Light_E, HIGH);
   digitalWrite(Light_E_Target, LOW); 
}
if (AZTEC_C ==1){
  digitalWrite(Light_C, HIGH);
   digitalWrite(Light_C_Target, LOW); 
}
if (Ball_Bonus ==1){
  digitalWrite(Light_Ball_Bonus, HIGH);
}

if (DoubleBonus == 1){
  
  digitalWrite(Light_Double_Bonus, HIGH);
}

else if (DoubleBonus == 0){
    digitalWrite(Light_Double_Bonus, LOW);
}

//###########
if (DoubleBonus_Lit ==1){
  
  digitalWrite(Light_Double_Bonus_Lit, HIGH);
}

else if (DoubleBonus_Lit ==0){
    digitalWrite(Light_Double_Bonus_Lit, LOW);
}

//################





if (Arrowbonus ==1){
  digitalWrite(Light_Arrow, HIGH);
  }

else if (Arrowbonus ==0){
  digitalWrite(Light_Arrow, LOW);
  }


if (AdvanceBonus == 1) {
  digitalWrite(Light_Advance_Bonus, HIGH);
}
else if (AdvanceBonus == 0) {
  digitalWrite(Light_Advance_Bonus, LOW);
}

//Bonus Lights
//###############

if (Bonus == 5000) {
  digitalWrite(Light__Bonus_1, HIGH); 
}
else if (Bonus == 10000) {
  digitalWrite(Light__Bonus_2, HIGH); 
}

else if (Bonus == 15000) {
  digitalWrite(Light__Bonus_3, HIGH); 
}
else if (Bonus == 20000) {
  digitalWrite(Light__Bonus_4, HIGH); 
}
else if (Bonus == 25000) {
  digitalWrite(Light__Bonus_5, HIGH); 
}
else if (Bonus == 30000) {
  digitalWrite(Light__Bonus_6, HIGH); 
}
else if (Bonus == 35000) {
  digitalWrite(Light__Bonus_7, HIGH); 
}
else if (Bonus == 40000) {
  digitalWrite(Light__Bonus_8, HIGH); 
}
else if (Bonus == 45000) {
  digitalWrite(Light__Bonus_9, HIGH); 
}
else if (Bonus == 50000) {
  digitalWrite(Light__Bonus_10, HIGH); 
}

//###############
}










//Scoring



void Score100f()
{
  Score = Score +100;
  AdvanceBonuscounter +=1;
  ScoreDisplay();     //Show Score
 delay(Milli);
}

void Score150f()    //Slingshots
{
  Score = Score +150;
  
  ScoreDisplay();     //Show Score
 delay(Milli);
}

void Score1000f()
{
  Score = Score +1000;
  AdvanceBonuscounter +=1;
  ScoreDisplay();     //Show Score
 delay(Milli);
}
void Score5000f()
{
  Score = Score +5000;
  AdvanceBonuscounter +=1;
  ScoreDisplay();     //Show Score
 delay(Milli);
}

void Score10000f()
{
  Score = Score +10000;
  
  ScoreDisplay();     //Show Score
 delay(Milli);
}

void Kickoutscoref(){
  int AZTEC_SUM = (AZTEC_A + AZTEC_Z +AZTEC_T +AZTEC_E +AZTEC_C);
   
   if (DoubleBonus_Lit == 0) {      //##########
   Score = Score +(5000* AZTEC_SUM);
   }
   else if (DoubleBonus_Lit == 1) {     //##########
   Score = Score +(10000* AZTEC_SUM);
   DoubleBonus = 1;
   }
   AdvanceBonuscounter +=1;
}



void Bonusf()
{
  if (Bonus < 50000){
  Bonus = Bonus +5000;
  }
  ScoreDisplay();     //Show Score
  AdvanceBonuscounter +=1;
 delay(Milli);
}



void Spinnerf(){
  
  MP3player.stopTrack();
  MP3player.playMP3("003.mp3");
  
  if (Arrowbonus == 0) {
  Score = Score +100;
  }
  else if (Arrowbonus == 1) {
  Score = Score +1000;
  }
  
  ScoreDisplay();     //Show Score
 //  lcd.setCursor(4,3);
//  lcd.print("SPINNER !");
 delay(50);
}


void AZTEC_Af(){
  //lcd.setCursor(4,3);
 //lcd.print("Aztec AF called ");
 //lcd.print(AZTEC_A); 
   AZTEC_A = 1;
  Score = Score +1000;
  AdvanceBonuscounter +=1;
  
  //lcd.setCursor(4,3);
  //lcd.print("A");   
  delay(Milli);
}

void Rampf() {
  Bonusf();
  if (DoubleBonus_Lit == 1){        //##########
    DoubleBonus = 1;
  }
  //lcd.setCursor(4,3);
  //lcd.print("Ramp");   
  delay(Milli); 
}








void BumperLf()
{
  Score = Score +200;
  DoubleBonuscounter +=1;
  ScoreDisplay();     //Show Score
  
  previousMillis = millis(); 
  digitalWrite(solenoidPin_BumperLinks, HIGH);
  BumperLinks_Trigger =1 ;
  

  
  delay(Milli_Bumper);

  
}
void BumperRf()
{
  Score = Score +200;
  DoubleBonuscounter +=1;
  ScoreDisplay();     //Show Score
   
  previousMillis = millis(); 
  digitalWrite(solenoidPin_BumperRechts, HIGH);
  BumperRechts_Trigger =1 ;
  

  
  delay(Milli_Bumper);
  
}


void BumperUf()
{
  Score = Score +200;
  DoubleBonuscounter +=1;
  ScoreDisplay();     //Show Score
  
  previousMillis = millis(); 
  digitalWrite(solenoidPin_BumperUnten, HIGH);
  BumperUnten_Trigger =1 ;



  delay(Milli_Bumper);
}


void Kickoutf()
{
  Kickoutscoref();
  
  ScoreDisplay();     //Show Score
  
 MP3player.stopTrack();
MP3player.playMP3("005.mp3");
  delay(1000);
  digitalWrite(solenoidPin_Kickout, HIGH);
  
 delay(Milli);
 digitalWrite(solenoidPin_Kickout,LOW);
 delay(250);
 kickoutreset = 0;
}



void Releasef()
{
  
  
 if (Balls <MaxBalls){
  Balls +=1;
  
  lcd.clear();
  lcd.setCursor(4,3);
  lcd.print("Ball Lost");   
 
 
 Ball_Lost();

 }
 
else if (Balls >=MaxBalls){
  lcd.clear();
  lcd.setCursor(4,3);
  lcd.print("Game Over");  
  Game_Over();
 }
}

void Kickout_ball() {

lcd.setCursor(4,3);
lcd.print("Start"); 
delay(1000);
digitalWrite(solenoidPin_Release, HIGH);
delay (100);    //TEST
digitalWrite(solenoidPin_Release,LOW);
delay (400);  
}


void ResetGame() {
Score = 0;
MaxBalls = 5;
Bonus = 0;
AZTEC_A = 0;
AZTEC_Z = 0;
AZTEC_T = 0;
AZTEC_E = 0;
AZTEC_C = 0;
Ball_Bonus = 0;
Kickout_Bonus =0;
DoubleBonus = 0;
DoubleBonuscounter = 0;  
AdvanceBonus = 0;   
AdvanceBonuscounter = 0;
Arrowbonus = 0;
RolloverLinks_Rechts_int_last =LOW;
RolloverMitte_int_last = LOW;
Target_Z_last = LOW;
Target_T_last = LOW;
Target_E_last = LOW;
Target_C_last = LOW;
Target_Middle_last= LOW;
Target_Points_last= LOW;
Ramp_last = LOW;

int SwitchtopLinks_Rechts_last = LOW;
int SwitchtopMitte_last = LOW;
int Outlanes_Links_Rechts_last = LOW;
int Sidelanes_Links_Rechts_last = LOW;

digitalWrite(Light_A, LOW);
digitalWrite(Light_Z, LOW);
digitalWrite(Light_T, LOW);
digitalWrite(Light_E, LOW);
digitalWrite(Light_C, LOW);
digitalWrite(Light_Ball_Bonus, LOW);
digitalWrite(Light_Arrow, LOW);
digitalWrite(Light_Double_Bonus, LOW);
digitalWrite(Light_A_Target, HIGH); 
digitalWrite(Light_Z_Target, HIGH); 
digitalWrite(Light_T_Target, HIGH); 
digitalWrite(Light_E_Target, HIGH); 
digitalWrite(Light_C_Target, HIGH); 
digitalWrite(Light__Bonus_1, LOW); 
digitalWrite(Light__Bonus_2, LOW); 
digitalWrite(Light__Bonus_3, LOW); 
digitalWrite(Light__Bonus_4, LOW); 
digitalWrite(Light__Bonus_5, LOW); 
digitalWrite(Light__Bonus_6, LOW); 
digitalWrite(Light__Bonus_7, LOW); 
digitalWrite(Light__Bonus_8, LOW); 
digitalWrite(Light__Bonus_9, LOW); 
digitalWrite(Light__Bonus_10, LOW); 

  ScoreDisplay();     //Show Score 
   delay (100);  

}
  

void Ball_Lost() {

MP3player.stopTrack();
MP3player.playMP3("006.mp3");

previousMillis = millis(); 
delay(1000);
digitalWrite(solenoidPin_Release, HIGH);
delay (100);    //TEST
digitalWrite(solenoidPin_Release,LOW);


if (DoubleBonus == 0) {
Score = Score + Bonus;
}
else if (DoubleBonus == 1) {
Score = Score + Bonus + Bonus;
}

Bonus = 0;
AZTEC_A = 0;
AZTEC_Z = 0;
AZTEC_T = 0;
AZTEC_E = 0;
AZTEC_C = 0;
Ball_Bonus = 0;
Kickout_Bonus =0;
DoubleBonus = 0;
DoubleBonuscounter = 0;
Arrowbonus = 0;
RolloverLinks_Rechts_int_last =LOW;
RolloverMitte_int_last = LOW;
Target_Z_last = LOW;
Target_T_last = LOW;
Target_E_last = LOW;
Target_C_last = LOW;
Target_Middle_last= LOW;
Target_Points_last= LOW;
Ramp_last = LOW;

int SwitchtopLinks_Rechts_last = LOW;
int SwitchtopMitte_last = LOW;
int Outlanes_Links_Rechts_last = LOW;
int Sidelanes_Links_Rechts_last = LOW;

digitalWrite(Light_A, LOW);
digitalWrite(Light_Z, LOW);
digitalWrite(Light_T, LOW);
digitalWrite(Light_E, LOW);
digitalWrite(Light_C, LOW);
digitalWrite(Light_Ball_Bonus, LOW);
digitalWrite(Light_Arrow, LOW);
digitalWrite(Light_Double_Bonus, LOW);
digitalWrite(Light_A_Target, HIGH); 
digitalWrite(Light_Z_Target, HIGH); 
digitalWrite(Light_T_Target, HIGH); 
digitalWrite(Light_E_Target, HIGH); 
digitalWrite(Light_C_Target, HIGH); 
digitalWrite(Light__Bonus_1, LOW); 
digitalWrite(Light__Bonus_2, LOW); 
digitalWrite(Light__Bonus_3, LOW); 
digitalWrite(Light__Bonus_4, LOW); 
digitalWrite(Light__Bonus_5, LOW); 
digitalWrite(Light__Bonus_6, LOW); 
digitalWrite(Light__Bonus_7, LOW); 
digitalWrite(Light__Bonus_8, LOW); 
digitalWrite(Light__Bonus_9, LOW); 
digitalWrite(Light__Bonus_10, LOW); 

  ScoreDisplay();     //Show Score 
   delay (100);  
}


void Game_Over(){
AttractMode = 0;
MP3player.stopTrack();
MP3player.playMP3("007.mp3");

if (DoubleBonus == 0) {
Score = Score + Bonus;
}
else if (DoubleBonus == 1) {
Score = Score + Bonus + Bonus;
}


if (Score>Highscore){
  Highscore = Score;
  EEPROM.writeLong(adress, Highscore);
}

  ScoreDisplay();     //Show Score 
   
delay (3000);  
DoubleBonus = 0;
DoubleBonuscounter = 0;
MaxBalls = 5;
Balls = 1;
Startplay_ACTIVE = 0;
AttractMode = 0;
Score = 0;
delay (1000);  
ATTRACT();
}








void ScoreDisplay()
{
  lcd.clear();                // Clear
  lcd.print("Score: ");    // First line
  lcd.print(Score);      // First line
 // lcd.setCursor(0,1);
 // lcd.print("Bonus: ");    // Second line
 // lcd.print(Bonus);      // Second line
  lcd.setCursor(4,3);
  lcd.print("Ball: ");    // Third line
  lcd.print(Balls);      // Third  line
}

Comments

Similar projects you might like

Integrate Node-Red with RAK811 LoRA node using the TTN

Project tutorial by Naresh krish

  • 235 views
  • 0 comments
  • 4 respects

In Servo We Trust!

Project tutorial by Maya

  • 1,319 views
  • 0 comments
  • 7 respects

Flying Drone Mjolnir With Hacked RC Transmitter

Project in progress by Allen Pan

  • 7,128 views
  • 0 comments
  • 29 respects

Fox Advisor

Project tutorial by Celia Garrido Hidalgo

  • 1,306 views
  • 0 comments
  • 7 respects

Remote System Monitor

Project tutorial by Stephen Harrison

  • 2,762 views
  • 0 comments
  • 5 respects

[App Inventor IoT ]LED fading (PWM)

Project tutorial by CAVEDU Education

  • 328 views
  • 0 comments
  • 5 respects
Add projectSign up / Login