Tuesday, September 03, 2013

Arduino Jeopardy

My work is having a little offsite and one of the events they want to do is a Jeopardy style game.  I thought this'd be a good opportunity to dust off the Arduino and make some fun buzzers.  Initially it seems like a pretty simplistic task.  You have 4 buttons.  1 button is for the host.  This person starts the game and starts each round.  The other 3 buttons are for the contestants.  Putting it together was straight forward.  4 buttons each feed into their own digital pin.  We also have LEDs for each contestant that light up when they're the winners.

So we haven't done anything complicated yet.  I got this part up and running in about 10 minutes.  The next part is really the only time it gets complicated.  I'll tell you about my very simple solution that I wrote just to get it done and then I'll tell you about my more complicated solution that I'm going to attempt.

The issue is knowing who buzzed in first.  Two people can press the button at the same time with a millisecond of difference in between.  My simple approach is to have a random button checked first using a random number.  This random number is between 1 and 3.  If the number 2 is selected, the system checks buttons 2,3,1 (in that order) to see if they're HIGH.  If nothing, we repeat the loop with a new number.  The random number generator is seeded with one of the analog inputs which produces static noise when it's not being used, so it's randomish.  This works but it still gives an advantage.  In the example above, the random number selected is 2.  If contestant 3 presses in a millisecond before contestant 2, contestant 2 will still win because it is checked first.

So I thought of a more complicated approach that I will attempt if I have some time.  I need to research interrupts in Arduino and see what it supports.  I am using an Arduino 2560 and I believe it has 6 interrupts, so my thought is that I can put each button on an interrupt.  In theory this seems like a much simpler approach because we no longer need the random number generator.  Just attach each button to an interrupt and when the button is pressed, trigger a method that tells the main game code that "Button X was pressed."  If we're in a round, that person wins.  If not, move on.  In execution, I think this might be a little more complicated but that's mainly because I haven't done any interrupt work with Arduino yet.

So that's my latest Arduino work.  I had to take apart my old Jeeputer that I built to use the Mega 2560 for this project.  I'm not sure if I posted about that at all.  I'll have to go through and dig up some old notes and videos, but in a nutshell I used the computer to detect the pitch and lean of my jeep so I could make a better decision about how hard I wanted to push up a hill.  I also had purchased several relays so I could control certain parts of my jeep with the jeeputer, but I never got around to adding them and I ended up selling the rig.  The nice thing about Arduino is it's very easy to quickly prototype something.  In the case of the Jeopardy game, I'm not going to bother putting it on an Arduino Pro because it'll be a once and done thing.  Here's a quick video showing the wiring and how it all works.  I'll make another post later this week when I have the final buttons/lights set up.

1 comment:

Ed said...

Hola, disculpa ¿me podrías pasar el esquemático y el código?

Hi, sorry Can you provide the code and the schematic for the circuit?