Sweden
Offline
Jr. Member
Karma: 0
Posts: 57
Be patient, I'm a total newbie.
|
 |
« on: February 19, 2013, 07:34:28 pm » |
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.htmlStill 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: // 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
|
|
|
|
« Last Edit: April 11, 2013, 02:30:11 pm by SimLego »
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #1 on: February 19, 2013, 07:39:13 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Poole, Dorset, UK
Offline
God Member
Karma: 8
Posts: 669
|
 |
« Reply #2 on: February 19, 2013, 07:40:00 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Poole, Dorset, UK
Offline
God Member
Karma: 8
Posts: 669
|
 |
« Reply #3 on: February 19, 2013, 07:42:57 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Sweden
Offline
Jr. Member
Karma: 0
Posts: 57
Be patient, I'm a total newbie.
|
 |
« Reply #4 on: February 19, 2013, 08:40:20 pm » |
Thank you guys for the input. Wow, you guys are fast! 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". 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...) 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.
|
|
|
|
« Last Edit: February 19, 2013, 08:46:19 pm by SimLego »
|
Logged
|
|
|
|
|
Copenhagen, Denmark
Offline
God Member
Karma: 17
Posts: 827
Have you testrun your PDE file today?
|
 |
« Reply #5 on: February 20, 2013, 12:15:42 pm » |
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.
I'll take you up on that challenge. Without knowing much about this particular pinball or driver board, it is much less demanding than - say - drive a 3D printer (3 steppermotors, LCD display, Serial I/O, monitoring switches, heatbeds etc.) there just have to be delays There is the Two LED without delay which shows you can have several, totally independent "delays" running, that is wait a short time, without using delay()
|
|
|
|
|
Logged
|
|
|
|
|
Sweden
Offline
Jr. Member
Karma: 0
Posts: 57
Be patient, I'm a total newbie.
|
 |
« Reply #6 on: February 20, 2013, 05:13:07 pm » |
I'll take you up on that challenge. Without knowing much about this particular pinball or driver board, it is much less demanding than - say - drive a 3D printer (3 steppermotors, LCD display, Serial I/O, monitoring switches, heatbeds etc.)
Now I see that you're most likely right, so I can't accept your challenge.  It is probably possible with an Uno and some workarounds (multiplexing, shift registers...), but it's going to be quite easy and straightforward with a Mega. I thought that this "blinking without delay()" was some low-level special coding, but now I see it's uncomplicated with the standard function millis().
|
|
|
|
|
Logged
|
|
|
|
|
Poole, Dorset, UK
Offline
God Member
Karma: 8
Posts: 669
|
 |
« Reply #7 on: February 20, 2013, 06:47:20 pm » |
The next trick is polling basically your code should look something like void loop(){ check each input and get there current state; if an input changed (the ball hit something) then do something about it. }
You need to look at "debouncing" - basic when you turn on a switch it does not just go to the on state. It "bounces" doing a few on - off- on - off before it ends up in the on state. Mark
|
|
|
|
|
Logged
|
|
|
|
|
Poole, Dorset, UK
Offline
God Member
Karma: 8
Posts: 669
|
 |
« Reply #8 on: February 20, 2013, 06:48:21 pm » |
Just for fun - how about a photo of this machine.
Mark
|
|
|
|
|
Logged
|
|
|
|
|
Sweden
Offline
Jr. Member
Karma: 0
Posts: 57
Be patient, I'm a total newbie.
|
 |
« Reply #9 on: February 20, 2013, 07:17:10 pm » |
Just for fun - how about a photo of this machine.
I will take some photos along the work, meanwhile you can have a look at a few quite low-res ones at ipdb: http://www.ipdb.org/machine.cgi?id=587(Not my game, but same model.)
|
|
|
|
|
Logged
|
|
|
|
|
Sweden
Offline
Jr. Member
Karma: 0
Posts: 57
Be patient, I'm a total newbie.
|
 |
« Reply #10 on: February 22, 2013, 08:03:56 pm » |
My Uno arrived today from HK, much earlier than expected. Installation and writing/uploading 'Hello World' was totally hassle free, guess it took about ten minutes. I'm already in love! Discovering the non-standard gap between digital pins 7 and 8 was the only unpleasant surprise so far. Makes it much harder to make DIY shields on prototype boards. Now I have to study the Multiplexer/Driver Board once more to see how much is still useful. This will surely take some time...
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15293
Measurement changes behavior
|
 |
« Reply #11 on: February 22, 2013, 08:27:24 pm » |
My Uno arrived today from HK, much earlier than expected. Installation and writing/uploading 'Hello World' was totally hassle free, guess it took about ten minutes. I'm already in love! Discovering the non-standard gap between digital pins 7 and 8 was the only unpleasant surprise so far. Makes it much harder to make DIY shields on prototype boards. Now I have to study the Multiplexer/Driver Board once more to see how much is still useful. This will surely take some time... Yes the non-standard gap can be a hassle. It was just a simple rush to market last min error that didn't get caught when they released their very first version of the arduino board. And once release into the wild they didn't want to correct it as it would make useless any shield made prior if they corrected the spacing. However there is a pretty simple fix, use a bent 'offset header' that will align up with standard .1" spaced proto-boards: https://www.sparkfun.com/products/9374?Lefty
|
|
|
|
|
Logged
|
|
|
|
|
Sweden
Offline
Jr. Member
Karma: 0
Posts: 57
Be patient, I'm a total newbie.
|
 |
« Reply #12 on: February 22, 2013, 08:48:58 pm » |
Great idea, Lefty. Only problem is their international shipping costs are not of this world.
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15293
Measurement changes behavior
|
 |
« Reply #13 on: February 22, 2013, 09:20:09 pm » |
Great idea, Lefty. Only problem is their international shipping costs are not of this world.
Well you are free to bend your own up from standard long pin headers, now that you know the trick. Many E-bay sellers have free shipping. Perhaps setting up your location in your profile settings would help others know from where you are posting and others can tell of possible local suppliers? http://www.ebay.com/sch/i.html?_odkw=arduino+bent+header&_osacat=0&_from=R40&_trksid=p2045573.m570.l1313&_nkw=arduino+stackable+header&_sacat=0
|
|
|
|
« Last Edit: February 22, 2013, 09:22:24 pm by retrolefty »
|
Logged
|
|
|
|
|
Sweden
Offline
Jr. Member
Karma: 0
Posts: 57
Be patient, I'm a total newbie.
|
 |
« Reply #14 on: February 23, 2013, 09:03:55 pm » |
Bad news. Seems like two out of four functions on the Multiplexer/Driver Board are dead. The solenoid drivers are ok, but neither the multiplexer to the switch matrix nor the multiplexer/driver for the Bonus lamps work; some of the inputs are shorted. Remains to see if the other lamp drivers apart from the bonus array work. Well well, I'll begin with making a new Multiplexer board just for the switch matrix. It's very simple and straightforward. Just a 7445 and some 1K2 pullup resistors for the switch lines in use. I don't have a 7445, but I can't see why one of my 7442's shouldn't do the same job. Here's some code I have in mind for scanning the switch matrix. I'll use the same addresses, just to make it easier to refer to the manual. No debounching or any response to input yet. // scan_switches.ino
const int bit0pin = 2; // MA41 (Black) const int bit1pin = 3; // MA43 (Blue) const int bit2pin = 4; // MA45 (Green) // const int bit3pin = 5; // MA47 (Yellow) // Not needed? const int Apin = 6; // JC09 Slate-White or MA48 const int Bpin = 7; // JC10 Yellow-White or MA46 const int Cpin = 8; // JC11 Red-White or MA44 const int Dpin = 9; // JC12 Brown-White or MA42
int ret;
void setup() { pinMode(bit0pin, OUTPUT); pinMode(bit1pin, OUTPUT); pinMode(bit2pin, OUTPUT); // pinMode(bit3pin, OUTPUT); // Not needed? pinMode(Apin, INPUT); pinMode(Bpin, INPUT); pinMode(Cpin, INPUT); pinMode(Dpin, INPUT); }
void loop() { while(1) { ret = scansw(); if(ret == 0) continue; if(ret == 1) // Drain Pit Switch closed { // code... } // if(ret == ...) and so on... } }
int scansw() { // Scan Line 0 digitalWrite(bit0pin, LOW); digitalWrite(bit1pin, LOW); digitalWrite(bit2pin, LOW); // digitalWrite(bit3pin, LOW); // Not needed? if(digitalRead(Apin) == LOW); return(1); // Drain Pit if(digitalRead(Bpin) == LOW); return(2); // Top Target if(digitalRead(Cpin) == LOW); return(3); // 50k Target if(digitalRead(Dpin) == LOW); return(4); // Top Pit
// Scan Line 3 digitalWrite(bit0pin, HIGH); digitalWrite(bit1pin, HIGH); if(digitalRead(Bpin) == LOW); return(32); // 500p Rollovers if(digitalRead(Cpin) == LOW); return(33); // 30p Contacts
// Scan Line 4 digitalWrite(bit0pin, LOW); digitalWrite(bit1pin, LOW); digitalWrite(bit2pin, HIGH); if(digitalRead(Bpin) == LOW); return(42); // 5k Rollovers, Bonus if(digitalRead(Cpin) == LOW); return(43); // Rollovers x2
// Scan Line 5 digitalWrite(bit0pin, HIGH); if(digitalRead(Apin) == LOW); return(51); // Left Drop Target if(digitalRead(Bpin) == LOW); return(52); // Center Drop Target if(digitalRead(Cpin) == LOW); return(53); // Right Drop Target
// Scan Line 6 digitalWrite(bit0pin, LOW); digitalWrite(bit1pin, HIGH); if(digitalRead(Apin) == LOW); return(61); // Left Bumper if(digitalRead(Bpin) == LOW); return(62); // Right Bumper if(digitalRead(Cpin) == LOW); return(63); // Left Slingshot if(digitalRead(Dpin) == LOW); return(64); // Right Slingshot
// Scan Line 7 digitalWrite(bit0pin, HIGH); if(digitalRead(Cpin) == LOW); return(73); // 30k Rollover if(digitalRead(Dpin) == LOW); return(74); // Top Slingshot }
|
|
|
|
|
Logged
|
|
|
|
|
|