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:
  1. Waiting for Coin Drop
  2. Waiting for drawHand to be populated with 5 cards
  3. 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"
};

The next key is to tell the Sketch the 0-51 value of every card on the Pokereno table
// 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.

No comments:

Post a Comment