For the last day of our summer vacation (after returning home from Cancun!) I dove back into the Fireball HD code for the first time in over a year.
We are exhibiting it twice in the next 60 days – at Player 1 Video Game Bar on July 13th, and at Maker Faire Orlando on Sept 13th & 14th – so I wanted to fix some of the known issues AND add a feature or two.
Of course, I prioritized the new feature over the fix…and so I added Lane Change. This required building a simple voltage divider circuit to get the flipper 24v down to something less than 5v to be read by one of the Arduino boards. The circuit was pretty simple, and the wiring only took an hour or so as I built a cable with connectors that went inline and branched the existing flipper circuit.
I had some empty pins on the solenoid driver and had already hacked it to read the start button after my past problems with spurious GPIO on the Pi. I found the solenoid driver code, and added the new pins & reads. Since the polling was already in the pygame code for the start button, it wasn’t hard to extend it, and then alter the ABCD lanes at the right time.
Since I was feeling confident after adding Lane Change – I wanted to add a Ball Saver feature. I always feel bad for those new to old pinball machines – they are still learning how flippers work as that first ball drains. I added a new configuration variable (the min score for the ball saver), new sound files for a saved ball (turns out I already had the directory and some files, but had never implemented them) and added a bunch of code. I tested it until I was happy with it, then later tweaked it more as I was working on other features (the shoot again light now flashes during ball saver, and you can’t play saved balls infinitely, the ball score accumulates over saved balls).
Feeling more familiar with the code, I hunted down the skipped ball problem. In some cases, you’d start a new ball, then it would IMMEDIATELY end and start the next ball. I’d previously thought this was a spurious switch read and spent time diagnosing that hardware / code – turns out, that it was a simple software issue. I have two functions endBall and endBall2. endBall is triggered by the trough switch, then sets up a timer. The timer handles the bonus payout with light / sound at the end of a ball, then when the bonus is at zero, it calls endBall2. Turns out in certain cases (high bonus), the system load causes an extra timer cycle to fire at bonus = 0 before the timer is killed. I played with the timing a bit, and optimized the function to turn the timer off faster at the end, but in some cases, it still happens. I created a quick semaphore so that endBall2 could only be called once, output a warning when it gets called when it wasn’t expected, and considered it fixed enough for now. After LOTS of play testing – no more skipped balls!
With a new circuit, two new features and an old bug squashed, I was feeling extra confident, and I dove into the old multiplayer code. Turns out that in trying to work around all the extra start button reads from the GPIO problem, we (Bill Stillwell helped me fix a ton of issues around Maker Faire Orlando last year) were ignoring the start button in a lot of places. I had to find and undo those (on both Pi and Arduino), and then make sure that multiplayer worked properly…it did! I then worked to add indications that multiplayer was active, choosing to show all scores on the screen. Working on the score display led me back into the “backglass” object which was a mess from all the prior iterations of display code. I cleaned it up a bit, cutting the number of lines in half with some helper functions. I’d still like to improve the display, but it is getting better.
I code so rarely, that I’m always rusty – but somehow this day, I was on fire. (On the ball? – gotta love puns). There was lots of house cleaning and post-vacation stuff to be done, but it could wait – I had one more thing I wanted to try.
Yep, while it seems simple enough, I’d never added flashing light code to Fireball. I had all the plumbing there for the command flow between pygame and the Arduino code – but had never implemented the flashing. Now this code runs on the Lamp & Switch Arduino – which includes a bunch of hand-adjusted timing to drive the matrix – and I’m always a LOT hesitant to change it. With my confidence from the day, I dove in. I saw a simple way to achieve it, and sure enough within 30 minutes, had three different flashing speeds, and then set the Ball Saver function to flash the Shoot Again light while it was active.
It was a good day, and with a little more work (tie down the new wiring, more play testing, and paint the head) – we are ready for Maker Faire Orlando!