Virtual bingo machine sketch

Hi All.

I have built a virtual bingo machine, it is like a pinball flipper machine but instead of scoring points the bingo machines have 25 holes, I did not write the sketch, as I have never used an arduino before, I did the mechanics, and my friend, James, did the programming.

I posted this question in 2016, and shortly afterwards, I put the bingo machine into storage in 2017, I have now retired and I have the time to try and fix an issue.

Usually you get one machine, one game, but a man named Joop has written software to be able to run an emulator on a computer, and I have used the base cabinet (the bottom with the 25 holes or the base with the flippers) as the mechanical side, so you have one base unit, and it was10 different machines, it is now 80 machines.

I have a ball gate sensor which is a pair of leaf switches on a hinge, one side goes to a mega2650 and the other goes to ground, as the ball leaves the shooting lane and passes through the gate it closes the contacts, and should lift a ball into the ball runway.

I also have a ball return leaf switch, which when the ball goes down the ball return hole, it closes the contacts and lifts a ball into the ball runway, the ball return works perfectly.

I then switched the wiring over for the ball return onto the gate switch, and it worked, so that proves the gate switch works, the only trouble with it is that it gives more than the set amount of balls.

When I added the routine, I was given for the, ball thro gate, the sketch does not run properly, and the ball thro the gate does nothing.

My question is can someone, please, look at the sketch and see if there is a reason for it not working.

This is the routine I was given to include in the sketch for the ball thro gate.

// Check for ball thro gate

  sensorvalue = digitalRead(A0);

  if (sensorvalue == LOW)

     {

       Serial.print ("z");

       delay(2000);

     }

Cheers.
Ian.

MEGA_21_08 (2).ino (13.9 KB)

I added A0 as ball thro gate, and connected the wire to the arduino mega on pin a0.

Yes, but please, replace your "zip" file with a code block (use the < CODE > button) of your sketch.

What is "working" - returning the original number (set of balls)?... let's see if I get banned for writing that...

#define OPENED 1
#define CLOSED 0

I would name these opposite as you have.

/* 
|| @version build 32
|| 
|| This program is only for use with BALLY Bingo Backglass simulation by Joop.
|| It also requires the UNO Stepper Motor controller.
|| 
*/
#define RELAY_ON  1
#define RELAY_OFF 0
#define RELAY_1 4            // YELLOW RO light
#define RELAY_2 5            // RED RO light
#define ON 1
#define OFF 0
#define OPENED 1
#define CLOSED 0
// Table containing numbered hole codes for JR's simulation
char Ballcodes [26] = 
   {' ','A','B','C','D','E','F','G','H','I','J',
   'K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y'};  
//
char ch;                       // characters from Backglass   
int BallsinPocket [26];        // slots 0 and 26 are not used
int sensorvalue;
int magiclines;
int shutter;               
int Abutton;
int Bbutton;
int Cbutton;
int Dbutton;
int Ebutton;
int Fbutton;
int RedRO;
int YellowRO;
int RedROon;
int YellowROon;
                 
void setup()
{
    Serial.begin  (9600);       // Comms to/from Joops BALLY BINGO simulations
    Serial.begin (9600);       // Comms to UNO Motor Controller(TX only)
    shutter   = CLOSED;         //  
// To indicaate a Magic Line machine hold A button while pressing the RED button at 
// start of game   
    magiclines= OFF;            // set when magic line BALLY BINGO
    Abutton   = OFF;            // Buttons A - F
    Bbutton   = OFF;
    Cbutton   = OFF;
    Dbutton   = OFF; 
    Ebutton   = OFF;
    Fbutton   = OFF;
    YellowROon = OFF;           // set when YELLOW Rollover active
    YellowRO   = OFF;           // YELLOW Rollover switch set
    RedROon    = OFF;           // set when RED Rollover active
    RedRO      = OFF;           // RED Rollover switch set
         
 // Set up Rollover Light relays 
 // Intialise pins so relays are inactive
    digitalWrite(RELAY_1, RELAY_OFF);         // NOTE - needs to be a High Level Trigger
    digitalWrite(RELAY_2, RELAY_OFF);         // Solid State Relay
//
    pinMode(2,INPUT_PULLUP);     // YELLOW rollover
    pinMode(3,INPUT_PULLUP);     // RED rollover
    pinMode(RELAY_1,OUTPUT);     // YELLOW lamp output 
    pinMode(RELAY_2,OUTPUT);     // RED lamp output
    pinMode(6,INPUT_PULLUP);     // White
    pinMode(7,INPUT_PULLUP);     // Blue
    pinMode(8,INPUT_PULLUP);     // Green
    pinMode(9,INPUT_PULLUP);     // R Button
    pinMode(10,INPUT_PULLUP);    // tilt
    pinMode(11,INPUT_PULLUP);    // rotate switch >
    pinMode(12,INPUT_PULLUP);    // rotate switch <
    pinMode(13,OUTPUT);          // test purposes only
//    
    pinMode(A1,INPUT_PULLUP);    // Ball return
    pinMode(A2,INPUT_PULLUP);    // Ball in Lane
    pinMode(A3,INPUT_PULLUP);    // 8th Ball Switch
    pinMode(A8,INPUT_PULLUP);    // Red New Game Button
    pinMode(A9,INPUT_PULLUP);    // Yellow Extra Ball Button
    pinMode(A10,INPUT_PULLUP);   // A Button
    pinMode(A11,INPUT_PULLUP);   // B Button
    pinMode(A12,INPUT_PULLUP);   // C Button  
    pinMode(A13,INPUT_PULLUP);   // D Button
    pinMode(A14,INPUT_PULLUP);   // E Button
    pinMode(A15,INPUT_PULLUP);   // F Button
    delay (2000);                // make sure relays reset
    
 // Setup numbers 1 to 25 on pins 22 to 47 inclusive 
    for (int i=22; i <= 47; i++)
    {
    pinMode( i, INPUT_PULLUP);  
    }                         
}
void loop()
{ 
 //
 //Process commands from backglass
 //
   if (Serial.available()>0)  
    {
     ch = Serial.read(); 
     if (ch == 'l')    
 // check to see if ball in shooter lane if so do not lift ball
 // this should only happen when a ball lands in ballyhole for an extra ball
 // and the next ball is in the shooter lane already
 // also acts as an anti cheat, no balls in shooter lane at beginning of game
     {
      sensorvalue = digitalRead(A2);
 // if switch open no ball in lane so raise new ball
      if (sensorvalue == HIGH) 
       {
         Serial.println ('l');  // send lift ball to UNO motor controller
         delay (3000);
       }
     }
// 
// Check backglass command
// for Yellow and Red lights ON or OFF
// 7 Yellow ON     6 Yellow OFF
// 5 Red    ON     4 Red    OFF
   if (ch == '7' )                       
    {                                     
      digitalWrite(RELAY_1, RELAY_ON);
      YellowROon = 1;
      digitalWrite (13, HIGH);
    }
   if (ch == '6' ) 
    {
     digitalWrite(RELAY_1, RELAY_OFF);
     YellowROon = 0;
     digitalWrite (13, LOW);
    }  
  if (ch == '5' ) 
    {
    digitalWrite(RELAY_2, RELAY_ON);
    RedROon = 1;
    }
  if (ch == '4' ) 
    {
     digitalWrite(RELAY_2, RELAY_OFF);
     RedROon = 0;
    }       
    ch=' ';    
  }

// check for ball over YELLOW rollover
      sensorvalue = digitalRead(2);
        if (sensorvalue == LOW)
          {
           // check if Rollover light ON
           if (YellowROon == 1)
            {
             if (YellowRO == 0)
             {
               Serial.print ("8");
               delay (250);
               Serial.print ("^");
               YellowRO = 1;
               digitalWrite (13, HIGH);   //Debugging
             }
            }        
          }                       
 // check for ball over RED rollover
      sensorvalue = digitalRead(3);
        if (sensorvalue == LOW)
          {
           // check if Rollover light ON
           if (RedROon == 1)
             {
             if (RedRO == 0)
             {
               Serial.print ("9");
               delay (250);
               Serial.print ("^");
               RedRO = 1;
               digitalWrite (13, HIGH);   //Debugging  
             }    
            }  
          }                        
// check for white button
    sensorvalue = digitalRead(6);
       if (sensorvalue == LOW)
         {
          Serial.print ('w');
          delay (500);
          Serial.print ('^');
          delay (500);
          Serial.print ('^');       // stops credits being continuosly counted down
          delay (1000);             // this allows time to release button
         }  
 // check for blue button
     sensorvalue = digitalRead(7);
       if (sensorvalue == LOW)
         {
          Serial.print ('v'); 
          delay (500);
          Serial.print ('^'); 
          delay (500);
          Serial.print ('^');       // stops credits being continuosly counted down
          delay (1000);             // this allows time to release button    
         }   
// check for green button
     sensorvalue = digitalRead(8);
       if (sensorvalue == LOW)
         {
          Serial.print ('u'); 
          delay (500);
          Serial.print ('^'); 
          delay (500);
          Serial.print ('^');       // stops credits being continuosly counted down
          delay (1000);             // this allows time to release button  
         }   
 // check for R button
     sensorvalue = digitalRead(9);
       if (sensorvalue == LOW)
         {
          Serial.print ('r');
          delay (500); 
          Serial.print ('^');
          delay (500);             
          Serial.print ('^');       // stops credits being continuosly counted down
          delay (1000);             // this allows time to release button
         }  
 // Check if machine tilted
     sensorvalue = digitalRead(10);
       if (sensorvalue == LOW)
        {
         Serial.print ('t');
         delay (500);
         Serial.print ('^');
         delay (500);
         Serial.print ('^');
        } 
// Rotate right
      sensorvalue = digitalRead(11);
       if (sensorvalue == LOW)
        {
          Serial.print ('>');
          delay (500);
          Serial.print ('^');
          delay (500);
          Serial.print ('^');
          delay (1000);              // this allows time to release button
       } 
// Rotate left
    sensorvalue = digitalRead(12);
       if (sensorvalue == LOW)
        {
          Serial.print ('<');
          delay (500);
          Serial.print ('^');
          delay (500);
          Serial.print ('^');
          delay (1000);             // this allows time to release button
       } 
  // Check if A Button pressed
      sensorvalue = digitalRead(A10);
       if (sensorvalue == LOW)
        {
        if (Abutton == OFF)
        // button still pressed  
        // do not send anymore A button pressed code  
          {
             Abutton = ON;
             Serial.print ('a');
             delay (250);
             Serial.println ('^');
             delay (250);
             if (magiclines == ON)Serial.print ('^');
           }  
        }
      // button released
       if ((sensorvalue) == HIGH && (Abutton)==ON)
           {
           Abutton = OFF;
           Serial.print ('^');
           }  
 // Check if B Button pressed
     sensorvalue = digitalRead(A11);
       if (sensorvalue == LOW)
        {
         if (Bbutton == OFF)
        // button still pressed  
        // do not send anymore B button pressed code  
           {
             Bbutton = ON;
             Serial.print ('b');
             delay (250);
             Serial.print ('^');
             delay (250);
             if (magiclines == ON)Serial.print ('^');
            }
        }  
        if ((sensorvalue) ==  HIGH && (Bbutton)== ON)
           {
            Bbutton = OFF; 
            Serial.print ('^');
            } 
 // Check if C Button pressed
      sensorvalue = digitalRead(A12);
       if (sensorvalue == LOW)
        {
         if (Cbutton == OFF)
        // button still pressed  
        // do not send anymore C button pressed code  
           {
             Cbutton = ON;
             Serial.print ('c');
             delay (250);
             Serial.print ('^');
             delay (250);
             if (magiclines == ON)Serial.print ('^');
            }
        }  
        if ((sensorvalue) == HIGH && (Cbutton)==ON)
           {
            Cbutton = OFF; 
            Serial.print ('^');
            } 
 // Check if D Button pressed
     sensorvalue = digitalRead(A13);
       if (sensorvalue == LOW)
        {
          if (Dbutton == OFF)
        // button still pressed  
        // then do not send anymore D button pressed code  
           {
             Dbutton = ON;
             Serial.print ('d');
             delay (250);
             Serial.print ('^');
             delay (250);
             if (magiclines == ON)Serial.print ('^');
            }
        }  
        if ((sensorvalue) == HIGH && (Dbutton)==ON)
           {
            Dbutton = OFF; 
            Serial.print ('^');
            }    
 // Check if E Button pressed
     sensorvalue = digitalRead(A14);
       if (sensorvalue == LOW)
        {
          if (Ebutton == OFF)
        // check button pressed still pressed  
        // then do not send anymore E button pressed code  
           {
             Ebutton = ON;
             Serial.print ('e');
             delay (250);
             Serial.print ('^');
             delay (250);
             if (magiclines == ON)Serial.print ('^');
            }
        }  
        if ((sensorvalue) == HIGH && (Ebutton)==ON)
           {
            Ebutton = OFF; 
            Serial.print ('^');
            } 
 // Check if F Button pressed
     sensorvalue = digitalRead(A15);
       if (sensorvalue == LOW)
        {
          if (Fbutton == OFF)
        // check button pressed still pressed  
        // then do not send anymore F button pressed code  
           {
             Fbutton = ON;
             Serial.print ('f');
             delay (250);
             Serial.print ('^');
             delay (250);
             if (magiclines == ON)Serial.print ('^');
            }
        }  
        if ((sensorvalue) == HIGH && (Fbutton)==ON)
           {
            Fbutton = OFF; 
            Serial.print ('^');
            } 
  // Check for ball return
     sensorvalue = digitalRead(A1);
      if (sensorvalue == LOW)
         {
          sensorvalue = digitalRead(A2);
           if (sensorvalue == HIGH) 
            {
             Serial.println ('l');    // send lift ball to UNO motor controller
             delay (3000);
            }
         }
  // Check if Red Button pressed for new game
       sensorvalue = digitalRead(A8);
       if (sensorvalue == LOW)
         {
           RedRO = 0;
           YellowRO = 0;
           RedROon = 0;
           YellowROon = 0; 
           for ( int i=1; i<26; i++)  
            {
             BallsinPocket [i] = 0; 
            }
            if (shutter == CLOSED) 
              {
   // the following is only needed to be excuted once per new game           
                magiclines = OFF;
                if (digitalRead(A10)==LOW) magiclines=ON;
                Serial.print ('q');        // reset machine
                delay (500);
                Serial.print ('h');       // open shutter
                delay (3000);              // allow balls to drop
                Serial.print ('i');       // close shutter
                shutter = OPENED;          // indicate shutter has been opened
              }
             Serial.print ('n');
             delay (500);
             Serial.print ('^');
             delay (500);
             Serial.print ('^');
             delay (1000);
           }  
      
 // Check if YELLOW button pressed for extra ball
     sensorvalue = digitalRead(A9);
       if (sensorvalue == LOW)
        {
          Serial.print ('x');
          delay (500);
          Serial.print ('^');
          delay (500);                 // this allows time to release button
          Serial.print ('^');          // stops credits being continuosly counted down
          delay (1000);      
       } 
   
 // check for ball in numbered hole                    
        for (int i=22; i <= 47; i++)
          {   
           int sensorvalue = digitalRead(i);    
            if ((sensorvalue) == LOW && (BallsinPocket [i-21]) == 0)
              {       
                BallsinPocket [i-21] = 1;
                Serial.print('z');
                delay (500);
                Serial.print('^');
                delay (250);
                Serial.print(Ballcodes [i-21]);
                delay (250);
                Serial.print(Ballcodes [i-21]);
                shutter = CLOSED;                  
              }
       } 
  } 
  

   

The sketch I have just posted is working, without the ball thro gate.

You do not define any button pin numbers. Are they in a header file?
I needed to scroll down to the magic numbers.

 // Check for ball return
     sensorvalue = digitalRead(A1);
      if (sensorvalue == LOW)
         {
          sensorvalue = digitalRead(A2);
           if (sensorvalue == HIGH) 
            {
             Serial3.println ('l');    // send lift ball to UNO motor controller
             delay (3000);
            }
         }
         // Check for ball thro gate open

      sensorvalue = digitalRead(A0);

      if (sensorvalue == LOW)

         {

           Serial.print ("z");

           delay(2000);

         }
  // Check if Red Button pressed for new game
       sensorvalue = digitalRead(A8);
       if (sensorvalue == LOW)
         {
           RedRO = 0;
           YellowRO = 0;
           RedROon = 0;
           YellowROon = 0; 
           for ( int i=1; i<26; i++)  
            {
             BallsinPocket [i] = 0; 
            }
            if (shutter == CLOSED)
          {Use code tags to format code for the forum

This is the line I added, but the script didn't work as it should.

Pin 2 does not show activity.

You will want to post your complete sketch.

Thanks for your replies.

I have posted the complete sketch, further up, I posted the bit I added so you didn't have to go through the sketch again, pin 2 is for the yellow roll over button, if the ball rolls over when it is lit, it gives extra time to move the magic lines.

But the "complete" script you posted above does not contain this code so only you know where you inserted it into the "complete" sketch.

Post the entire sketch that contains this part

Most posts contains many, many versions of the complete sketch.

/*
  || @version build 32
  ||
  || This program is only for use with BALLY Bingo Backglass simulation by Joop.
  || It also requires the UNO Stepper Motor controller.
  ||
*/
#define RELAY_ON  1
#define RELAY_OFF 0
#define RELAY_1 4            // YELLOW RO light
#define RELAY_2 5            // RED RO light
#define ON 1
#define OFF 0
#define OPENED 1
#define CLOSED 0
// Table containing numbered hole codes for JR's simulation
char Ballcodes [26] =
{ ' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
  'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y'
};
//
char ch;                       // characters from Backglass
int BallsinPocket [26];        // slots 0 and 26 are not used
int sensorvalue;
int magiclines;
int shutter;
int Abutton;
int Bbutton;
int Cbutton;
int Dbutton;
int Ebutton;
int Fbutton;
int RedRO;
int YellowRO;
int RedROon;
int YellowROon;

void setup()
{
  Serial.begin  (9600);       // Comms to/from Joops BALLY BINGO simulations
  Serial3.begin (9600);       // Comms to UNO Motor Controller(TX only)
  shutter   = CLOSED;         //
  // To indicaate a Magic Line machine hold A button while pressing the RED button at
  // start of game
  magiclines = OFF;           // set when magic line BALLY BINGO
  Abutton   = OFF;            // Buttons A - F
  Bbutton   = OFF;
  Cbutton   = OFF;
  Dbutton   = OFF;
  Ebutton   = OFF;
  Fbutton   = OFF;
  YellowROon = OFF;           // set when YELLOW Rollover active
  YellowRO   = OFF;           // YELLOW Rollover switch set
  RedROon    = OFF;           // set when RED Rollover active
  RedRO      = OFF;           // RED Rollover switch set

  // Set up Rollover Light relays
  // Intialise pins so relays are inactive
  digitalWrite(RELAY_1, RELAY_OFF);         // NOTE - needs to be a High Level Trigger
  digitalWrite(RELAY_2, RELAY_OFF);         // Solid State Relay
  //
  pinMode(2, INPUT_PULLUP);    // YELLOW rollover
  pinMode(3, INPUT_PULLUP);    // RED rollover
  pinMode(RELAY_1, OUTPUT);    // YELLOW lamp output
  pinMode(RELAY_2, OUTPUT);    // RED lamp output
  pinMode(6, INPUT_PULLUP);    // White
  pinMode(7, INPUT_PULLUP);    // Blue
  pinMode(8, INPUT_PULLUP);    // Green
  pinMode(9, INPUT_PULLUP);    // R Button
  pinMode(10, INPUT_PULLUP);   // tilt
  pinMode(11, INPUT_PULLUP);   // rotate switch >
  pinMode(12, INPUT_PULLUP);   // rotate switch <
  pinMode(13, OUTPUT);         // test purposes only
  //
  pinMode(A0, INPUT_PULLUP);   // Ball thro gate
  pinMode(A1, INPUT_PULLUP);   // Ball return
  pinMode(A2, INPUT_PULLUP);   // Ball in Lane
  pinMode(A3, INPUT_PULLUP);   // 8th Ball Switch
  pinMode(A8, INPUT_PULLUP);   // Red New Game Button
  pinMode(A9, INPUT_PULLUP);   // Yellow Extra Ball Button
  pinMode(A10, INPUT_PULLUP);  // A Button
  pinMode(A11, INPUT_PULLUP);  // B Button
  pinMode(A12, INPUT_PULLUP);  // C Button
  pinMode(A13, INPUT_PULLUP);  // D Button
  pinMode(A14, INPUT_PULLUP);  // E Button
  pinMode(A15, INPUT_PULLUP);  // F Button
  delay (2000);                // make sure relays reset

  // Setup numbers 1 to 25 on pins 22 to 47 inclusive
  for (int i = 22; i <= 47; i++)
  {
    pinMode( i, INPUT_PULLUP);
  }
}
void loop()
{
  //
  //Process commands from backglass
  //
  if (Serial.available() > 0)
  {
    ch = Serial.read();
    if (ch == 'l')
      // check to see if ball in shooter lane if so do not lift ball
      // this should only happen when a ball lands in ballyhole for an extra ball
      // and the next ball is in the shooter lane already
      // also acts as an anti cheat, no balls in shooter lane at beginning of game
    {
      sensorvalue = digitalRead(A2);
      // if switch open no ball in lane so raise new ball
      if (sensorvalue == HIGH)
      {
        Serial3.println ('l');  // send lift ball to UNO motor controller
        delay (3000);
      }
    }
    //
    // Check backglass command
    // for Yellow and Red lights ON or OFF
    // 7 Yellow ON     6 Yellow OFF
    // 5 Red    ON     4 Red    OFF
    if (ch == '7' )
    {
      digitalWrite(RELAY_1, RELAY_ON);
      YellowROon = 1;
      digitalWrite (13, HIGH);
    }
    if (ch == '6' )
    {
      digitalWrite(RELAY_1, RELAY_OFF);
      YellowROon = 0;
      digitalWrite (13, LOW);
    }
    if (ch == '5' )
    {
      digitalWrite(RELAY_2, RELAY_ON);
      RedROon = 1;
    }
    if (ch == '4' )
    {
      digitalWrite(RELAY_2, RELAY_OFF);
      RedROon = 0;
    }
    ch = ' ';
  }

  // check for ball over YELLOW rollover
  sensorvalue = digitalRead(2);
  if (sensorvalue == LOW)
  {
    // check if Rollover light ON
    if (YellowROon == 1)
    {
      if (YellowRO == 0)
      {
        Serial.print ("8");
        delay (250);
        Serial.print ("^");
        YellowRO = 1;
        digitalWrite (13, HIGH);   //Debugging
      }
    }
  }
  // check for ball over RED rollover
  sensorvalue = digitalRead(3);
  if (sensorvalue == LOW)
  {
    // check if Rollover light ON
    if (RedROon == 1)
    {
      if (RedRO == 0)
      {
        Serial.print ("9");
        delay (250);
        Serial.print ("^");
        RedRO = 1;
        digitalWrite (13, HIGH);   //Debugging
      }
    }
  }
  // check for white button
  sensorvalue = digitalRead(6);
  if (sensorvalue == LOW)
  {
    Serial.print ('w');
    delay (500);
    Serial.print ('^');
    delay (500);
    Serial.print ('^');       // stops credits being continuosly counted down
    delay (1000);             // this allows time to release button
  }
  // check for blue button
  sensorvalue = digitalRead(7);
  if (sensorvalue == LOW)
  {
    Serial.print ('v');
    delay (500);
    Serial.print ('^');
    delay (500);
    Serial.print ('^');       // stops credits being continuosly counted down
    delay (1000);             // this allows time to release button
  }
  // check for green button
  sensorvalue = digitalRead(8);
  if (sensorvalue == LOW)
  {
    Serial.print ('u');
    delay (500);
    Serial.print ('^');
    delay (500);
    Serial.print ('^');       // stops credits being continuosly counted down
    delay (1000);             // this allows time to release button
  }
  // check for R button
  sensorvalue = digitalRead(9);
  if (sensorvalue == LOW)
  {
    Serial.print ('r');
    delay (500);
    Serial.print ('^');
    delay (500);
    Serial.print ('^');       // stops credits being continuosly counted down
    delay (1000);             // this allows time to release button
  }
  // Check if machine tilted
  sensorvalue = digitalRead(10);
  if (sensorvalue == LOW)
  {
    Serial.print ('t');
    delay (500);
    Serial.print ('^');
    delay (500);
    Serial.print ('^');
  }
  // Rotate right
  sensorvalue = digitalRead(11);
  if (sensorvalue == LOW)
  {
    Serial.print ('>');
    delay (500);
    Serial.print ('^');
    delay (500);
    Serial.print ('^');
    delay (1000);              // this allows time to release button
  }
  // Rotate left
  sensorvalue = digitalRead(12);
  if (sensorvalue == LOW)
  {
    Serial.print ('<');
    delay (500);
    Serial.print ('^');
    delay (500);
    Serial.print ('^');
    delay (1000);             // this allows time to release button
  }
  // Check if A Button pressed
  sensorvalue = digitalRead(A10);
  if (sensorvalue == LOW)
  {
    if (Abutton == OFF)
      // button still pressed
      // do not send anymore A button pressed code
    {
      Abutton = ON;
      Serial.print ('a');
      delay (250);
      Serial.println ('^');
      delay (250);
      if (magiclines == ON)Serial.print ('^');
    }
  }
  // button released
  if ((sensorvalue) == HIGH && (Abutton) == ON)
  {
    Abutton = OFF;
    Serial.print ('^');
  }
  // Check if B Button pressed
  sensorvalue = digitalRead(A11);
  if (sensorvalue == LOW)
  {
    if (Bbutton == OFF)
      // button still pressed
      // do not send anymore B button pressed code
    {
      Bbutton = ON;
      Serial.print ('b');
      delay (250);
      Serial.print ('^');
      delay (250);
      if (magiclines == ON)Serial.print ('^');
    }
  }
  if ((sensorvalue) ==  HIGH && (Bbutton) == ON)
  {
    Bbutton = OFF;
    Serial.print ('^');
  }
  // Check if C Button pressed
  sensorvalue = digitalRead(A12);
  if (sensorvalue == LOW)
  {
    if (Cbutton == OFF)
      // button still pressed
      // do not send anymore C button pressed code
    {
      Cbutton = ON;
      Serial.print ('c');
      delay (250);
      Serial.print ('^');
      delay (250);
      if (magiclines == ON)Serial.print ('^');
    }
  }
  if ((sensorvalue) == HIGH && (Cbutton) == ON)
  {
    Cbutton = OFF;
    Serial.print ('^');
  }
  // Check if D Button pressed
  sensorvalue = digitalRead(A13);
  if (sensorvalue == LOW)
  {
    if (Dbutton == OFF)
      // button still pressed
      // then do not send anymore D button pressed code
    {
      Dbutton = ON;
      Serial.print ('d');
      delay (250);
      Serial.print ('^');
      delay (250);
      if (magiclines == ON)Serial.print ('^');
    }
  }
  if ((sensorvalue) == HIGH && (Dbutton) == ON)
  {
    Dbutton = OFF;
    Serial.print ('^');
  }
  // Check if E Button pressed
  sensorvalue = digitalRead(A14);
  if (sensorvalue == LOW)
  {
    if (Ebutton == OFF)
      // check button pressed still pressed
      // then do not send anymore E button pressed code
    {
      Ebutton = ON;
      Serial.print ('e');
      delay (250);
      Serial.print ('^');
      delay (250);
      if (magiclines == ON)Serial.print ('^');
    }
  }
  if ((sensorvalue) == HIGH && (Ebutton) == ON)
  {
    Ebutton = OFF;
    Serial.print ('^');
  }
  // Check if F Button pressed
  sensorvalue = digitalRead(A15);
  if (sensorvalue == LOW)
  {
    if (Fbutton == OFF)
      // check button pressed still pressed
      // then do not send anymore F button pressed code
    {
      Fbutton = ON;
      Serial.print ('f');
      delay (250);
      Serial.print ('^');
      delay (250);
      if (magiclines == ON)Serial.print ('^');
    }
  }
  if ((sensorvalue) == HIGH && (Fbutton) == ON)
  {
    Fbutton = OFF;
    Serial.print ('^');
  }
  // Check for ball return
  sensorvalue = digitalRead(A1);
  if (sensorvalue == LOW)
  {
    sensorvalue = digitalRead(A2);
    if (sensorvalue == HIGH)
    {
      Serial3.println ('l');    // send lift ball to UNO motor controller
      delay (3000);
    }
  }
  // Check for ball thro gate open

  sensorvalue = digitalRead(A0);

  if (sensorvalue == LOW)

  {

    Serial.print ("z");

    delay(2000);

  }
  // Check if Red Button pressed for new game
  sensorvalue = digitalRead(A8);
  if (sensorvalue == LOW)
  {
    RedRO = 0;
    YellowRO = 0;
    RedROon = 0;
    YellowROon = 0;
    for ( int i = 1; i < 26; i++)
    {
      BallsinPocket [i] = 0;
    }
    if (shutter == CLOSED)
    {
      // the following is only needed to be excuted once per new game
      magiclines = OFF;
      if (digitalRead(A10) == LOW) magiclines = ON;
      Serial.print ('q');        // reset machine
      delay (500);
      Serial3.print ('h');       // open shutter
      delay (3000);              // allow balls to drop
      Serial3.print ('i');       // close shutter
      shutter = OPENED;          // indicate shutter has been opened
    }
    Serial.print ('n');
    delay (500);
    Serial.print ('^');
    delay (500);
    Serial.print ('^');
    delay (1000);
  }

  // Check if YELLOW button pressed for extra ball
  sensorvalue = digitalRead(A9);
  if (sensorvalue == LOW)
  {
    Serial.print ('x');
    delay (500);
    Serial.print ('^');
    delay (500);                 // this allows time to release button
    Serial.print ('^');          // stops credits being continuosly counted down
    delay (1000);
  }

  // check for ball in numbered hole
  for (int i = 22; i <= 47; i++)
  {
    int sensorvalue = digitalRead(i);
    if ((sensorvalue) == LOW && (BallsinPocket [i - 21]) == 0)
    {
      BallsinPocket [i - 21] = 1;
      Serial.print('z');
      delay (500);
      Serial.print('^');
      delay (250);
      Serial.print(Ballcodes [i - 21]);
      delay (250);
      Serial.print(Ballcodes [i - 21]);
      shutter = CLOSED;
    }
  }
}

Thanks, I have posted the complete sketch.

I see no "ball thro" or "ballthro"

delay() commands are probably making the "button" pushing hard to use.

Its after, ball return and before red button.

I do not see "ball thro" between return and red

So you are not seeing any "z" on the Serial Monitor indicating that A0 is LOW?
It could be that the ball is passing through the gate while you are in one of your delay()s so the code misses the event.

`// Check for ball return
sensorvalue = digitalRead(A1);
if (sensorvalue == LOW)
{
sensorvalue = digitalRead(A2);
if (sensorvalue == HIGH)
{
Serial3.println ('l'); // send lift ball to UNO motor controller
delay (3000);
}
}
// Check for ball thro gate open

sensorvalue = digitalRead(A0);

if (sensorvalue == LOW)

{

Serial.print ("z");

delay(2000);

}
// Check if Red Button pressed for new game``

I will try that tomorrow.

That (post #17) is different from the code you posted. New code posted.

The buttons are working ok, I have to hold on for a split second.