Go Down

Topic: Pinball Project (Read 4 times) previous topic - next topic

SimLego

Feb 20, 2013, 01:34 am Last Edit: Apr 11, 2013, 09:30 pm by SimLego Reason: 1
Hi,

I'm a total newbie, so please forgive every forum convention I unintensionally break.
I have just made my two first posts, presenting myself and a little of my bigger project plan in this following thread:
http://arduino.cc/forum/index.php/topic,149747.0.html
Still I haven't even recieved my first Arduino units, but I have downloaded and tried the Windows IDE. So far, so good!

In order to restore as much functionality as possible to the old, broken Spanish Solid State pinball, I have decided to try to use one or probably more Arduino units together with some TTL circuits and the boards that still are somewhat functional on the game. See link above for more details.

The first step involving an Arduino unit will be controlling the behaviour of the triple drop target bank. I have written some sketch code that I don't know if it will work, probably not becuse I obviously can't test it before the Arduino boards have arrived. But at least it compiiles fine without warnings or errors in the IDE, but I'd like to have some input on the code to make sure I got it all right. So, here it is:

Code: [Select]

// Drop Target Sketch rev 001 2013-02-19

const int alldropsswPin = 2;     // All Drop Targets Down Switch Pin
const int addBonusPin =  11;      // Add Bonus Pin
const int score1000Pin =  12;      // Score 1000pts/Hi-pitch Beep Pin
const int dropsolenoidPin =  13;      // Reset Drop Target Bank Solenoid Pin


void setup()
{
  // initialize the All Drop Targets Down Switch pin as input:
  pinMode(alldropsswPin, INPUT);   
  // initialize the Add Bonus pin as output:
  pinMode(addBonusPin, OUTPUT);   
  // initialize the Score 1000 Points pin as output:
  pinMode(score1000Pin, OUTPUT);   
  // initialize Reset Drop Target Bank Solenoid pin as output:
  pinMode(dropsolenoidPin, OUTPUT);   

  // Set initial state on output pins
  // All activated/triggered on pin going LOW
  digitalWrite(score1000Pin, HIGH);
  digitalWrite(addBonusPin, HIGH);
  digitalWrite(dropsolenoidPin, HIGH);
}

void loop()
{
  if (alldown())
  {
    delay(200);
    // Score 1000 pts + add 1 bonus
    // TO DO: Disable the 3 individual Target Going Down Momentary Switches!!!
    digitalWrite(score1000Pin, LOW);
    digitalWrite(addBonusPin, LOW);
    delay(40);
    digitalWrite(score1000Pin, HIGH);
    digitalWrite(addBonusPin, HIGH);
    for(int i=0;i<4;i++)
    {
      delay(100);
      digitalWrite(score1000Pin, LOW);
      delay(40);
      digitalWrite(score1000Pin, HIGH);
    }
    delay(200);
    // Reset Drop Targets
    digitalWrite(dropsolenoidPin, LOW);
    delay(200);
    digitalWrite(dropsolenoidPin, HIGH);
    // TO DO: Enable the 3 individual Target Going Down Momentary Switches!!!
  }
   
}

boolean alldown()
{
  // Check if the All Drop Targets Down Switch is closed (ie grounded)
  // If so, double-check if it's still closed after 50 ms
  // just to eliminate the risk of false triggering and other error sources
  // Return TRUE only if switch is closed at both times,
  // Else return FALSE
  if (digitalRead(alldropsswPin) == LOW)
  {
    delay(50);
    if (digitalRead(alldropsswPin) == LOW)
    {
      return (false);
    }
    else return(true);
  }
  else return(true);
}


Many thanks in advance,
/Tore

PaulS

How are the switches (to be) wired to the Arduino? Since you are not using the internal pullup resistors, you'll need external resistors. Using the internal ones is so much easier.

50 milliseconds is a loooong time for a switch to bounce. 10 milliseconds is usually long enough for bouncing to die out.

holmes4

In the long run you have no chance at all of getting code like this to work as it uses delay(). Look at the "blink without delay" example , and then look at FSM's (Finite State Machines) in the playground.

Mark

holmes4

I should also have pointer you at the use of shift registers (and other chips) the extend the number of I/O ports you have.

Mark

SimLego

#4
Feb 20, 2013, 02:40 am Last Edit: Feb 20, 2013, 02:46 am by SimLego Reason: 1
Thank you guys for the input. Wow, you guys are fast!

Quote

How are the switches (to be) wired to the Arduino? Since you are not using the internal pullup resistors, you'll need external resistors. Using the internal ones is so much easier.

50 milliseconds is a loooong time for a switch to bounce. 10 milliseconds is usually long enough for bouncing to die out.


In most of the cases, there will be TTL AND or NAND gates between the switches and the Arduino. But not in the case of the All Drop Targets Down Switch, my guess is that if it makes any difference at all, I'd go for pulling the switch up towards the Arduino's 5 volt level, rather than the pinball game's.

Changed the debounce delay to 10 ms. Thanks. The other delays will most likely be subject to change, too. I just have to hear it to know if it produces the right "feel".

Quote

In the long run you have no chance at all of getting code like this to work as it uses delay(). Look at the "blink without delay" example , and then look at FSM's (Finite State Machines) in the playground.

Mark


I will look at it, right after I've finished writing this post. I think I've already forseen that "blink without delay" issue if I got it right, I'm not sure.
I think there's no chance of using only one Adrino for all the tasks, even if the ports and the memory are sufficient. So this unit will handle three of the four instances where there just have to be delays. (The forth is the two Bumpers, but I will use a dual copy of Gottlieb's System 80 Bumper Driver board there, and the switch signal for 100 points score will go to the other Arduino unit, the one without or with very short delays.)
This one will only control the two pits and the drop target bank. While it works with its delays, the ball will hit the slingshots and other targets That would have posed big troubles if the same unit was supposed to take care of those signals, too. But they will not be sent to this busy unit. And while the ball is in one of the two pits, of course no other inputs are made from the rest of the playfield. (Sorry, my English skills is not 100%, so sometimes I need ten words to express something that should take two words...)

Quote

I should also have pointer you at the use of shift registers (and other chips) the extend the number of I/O ports you have.

Mark


Shift registers are currently beyond my knowledge. I think I got the idea in general, but no details.
Don't know if I have the brain capacity to figure that out. But for now, I think the I/O ports of the Uno will be sufficient for this part of the project.

Go Up