Tuesday, February 18, 2020
Pokereno Sketch
This post is not meant to be a tutorial on how to write an Arduino Sketch... but if you want to see how this was programmed I have posted a zip file with my PokerenoFinal.ino file.
The Game Stats has 3 modes:
- Waiting for Coin Drop
- Waiting for drawHand to be populated with 5 cards
- Calculate Win
The first key is to assign every card in the deck a number from 0-51... (This logic was used from another Poker sketch I located on Arduino.cc the author was not attributed so it remains so in my sketch.) This allows the checkWin calculation to know if we have all Hearts or a Straight etc.
// Used to calculate hands in checkWin
// cards are value 0-51 // 0-12 Hearts // 13-25 Spades // 26-38 Diamonds // 39-51 Clubs
const char* cardDeck[] = {
"Ah","2h","3h","4h","5h","6h","7h","8h","9h","Th","Jh","Qh","Kh",
"As","2s","3s","4s","5s","6s","7s","8s","9s","Ts","Js","Qs","Ks",
"Ad","2d","3d","4d","5d","6d","7d","8d","9d","Td","Jd","Qd","Kd",
"Ac","2c","3c","4c","5c","6c","7c","8c","9c","Tc","Jc","Qc","Kc"
};
// Backglass map to the position of the Cards 0-51 value
const int cardValue[6][6] = {
{34,9,23,37,25,39},
{21,48,10,50,12,26},
{8,35,49,11,25,13},
{47,9,36,50,51,0},
{8,22,23,11,38,39},
{21,35,36,24,51,26}
};
The first card in the upper left corner is a 9 of Diamonds (34), the next card is 10 of Hearts (9). You notice there are 6 cards in each of the 6 rows just like the backglass. When the balls roll into one of the holes the switch goes to ground and the Optisolator sends a 5V signal to the Arduino. The sketch listens until 5 are populated and then it calculates the poker hand using the sub-routine checkWin. This triggers the number of wins tripping the relays controlling the Winner Lamp, Bell and Ticket dispenser.
A fair amount of the settings you will see in the Sketch (like cardFace & winName) are simply to provide "English" words to use in the serial output for debugging. I've commented on the sketch to help me remember what I did. If you use this for a project let me know. Don't forget Arduino arrays always start with 0.
Saturday, February 8, 2020
Wiring the New Pokereno Logic Board
Since I was going with a no-solder design. I started with a piece of plywood and about $250 of parts and accessories. The primary components are:
I skipped pin_18 through pin_21 because they are used as interrupts on the Mega. (I wasn't sure if I would need interrupts for the coin-drop detection, more about that in the programming post.)
From the lower connector the pins were connected as follows:
- One (1) Arduino Mega $20
- One (1) Electronics-Salon Screw Terminal Block Breakout Module $30,
- Five (5) Alzard 24V to 5V 8 Channel Optocoupler Isolation Boards, $75 ($15 ea)
- One (1) 8 Channel 12V 5V Relay Board Module $12
- One (1) 12V to 5V DC converter. $10
- Two (2) Corsham 22/44 Pin Extenders (one cut down to 12 pins with a Dremel). $50 ($25 ea.)
- 22AWG Solid Core wire in 10 colors. $35.
I skipped pin_18 through pin_21 because they are used as interrupts on the Mega. (I wasn't sure if I would need interrupts for the coin-drop detection, more about that in the programming post.)
From the lower connector the pins were connected as follows:
- Token-In - to Alzard 14v to Ardiuno pin_5 (INPUT)
- Ball Release - to Relay_2 to Ardiuno pin_11 (OUTPUT)
- Dime-In - to Alzard 14v to Ardiuno pin_6 (INPUT)
- Lamp Coin-In - to Relay_1 to Ardiuno pin_12 (OUTPUT)
- Bell - To Relay_3 to Ardiuno pin_10 (OUTPUT)
- Tickets Disp - to Relay_4 to Ardiuno pin_9 (OUTPUT)
- Lamp Winner - to Relay_5 to Ardiuno pin_8 (OUTPUT)
- Lamp Game Over - to Relay_6 to Ardiuno pin_A13 (OUTPUT)
- skipped
- 14V+ - to 8 screw junction block
- Ground - to 4 screw junction block
The Arduino pins were selected based on their contiguous locations on the Electronics-Salon Screw Terminal. I skipped pin_13 because it "flutters" during the Arduino boot sequence.
The Arduino no-solder replacement for the Pokereno logic board. 10 lbs of Electronics in a 5 lb sack. This design is neither practical or cheap, but it is a DIY project. |
Subscribe to:
Posts (Atom)