Single Player Blackjack Game for Arduino w/ LCD Keypad Shield

I sure had a lot of fun writing this. I uncovered several surprises:

  • There are many ways to seed the random number generator.
  • There is some data type ambiguity with naked constants in the .write method.
  • Integer currency didn’t work with Blackjack payouts (bet x 1.5) and odd value bets (unless you intend to cheat the player). It was actually fun to add the cents though.
  • For some reason one of the LCD special characters (“10”) gets garbled from time to time. Still not sure why.
  • I really need to work with objects more and less with procedural code.
  • Multi-dimensional arrays are cool!

Read the comments at the beginning of the sketch. They’ll tell you everything you need to know. I believe the code is well commented. Let me know if you discover any new bugs. I’d love to have the opportunity to fix them. I welcome suggestions for alternative approaches to some of the programming logic. This really was a lot of fun for me and I hope you enjoy it. 8)

If you found this fun or interesting please make a small donation to my PayPal account at https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=GTBD7T7BXPGQY. I have many more Arduino projects in mind and appreciate your support.

Moderator edit: reference to company selling counterfeit product removed

Arduino_Blackjack.ino (14.1 KB)

Hi!

I'm a Arduino newbee but very interested in your Blackjack project. Where can i find the code?

Greetings from Norway

Bought myself glasses. Downloaded the file.

Hi !

I will "donate" a lot but .... i get the error message:

error: DFR_Key.h: Datei oder Verzeichnis nicht gefunden compilation terminated.

There seems to be the .h missing ? ... Do you have a link to get this ? Thank you ;-) Frank

My version of the Arduino IDE (1.0.5) includes the liquid crystal library. What version are you using? I found the library at C:\Program Files (x86)\Arduino\libraries\LiquidCrystal. In any case I've added the library to the GitHub Repo.

schluerfrank: Hi !

I will "donate" a lot but .... i get the error message:

error: DFR_Key.h: Datei oder Verzeichnis nicht gefunden compilation terminated.

There seems to be the .h missing ? ... Do you have a link to get this ? Thank you ;-) Frank

I got the headder files but I get.

Arduino: 1.6.0 (Windows 8), Board: "Arduino Uno"

Build options changed, rebuilding all

Arduino_Blackjack1.ino: In function 'void loop()': Arduino_Blackjack1.ino:282:33: error: 'playerHandIndex' was not declared in this scope Arduino_Blackjack1.ino:288:14: error: 'playerHandIndex' was not declared in this scope Arduino_Blackjack1.ino:288:32: error: 'handCardIndexMax' was not declared in this scope Arduino_Blackjack1.ino:306:16: error: 'dealerHandIndex' was not declared in this scope Arduino_Blackjack1.ino: In function 'void displayHands()': Arduino_Blackjack1.ino:462:15: error: 'DealerIndex' was not declared in this scope Arduino_Blackjack1.ino:467:15: error: 'PlayerIndex' was not declared in this scope Arduino_Blackjack1.ino: In function 'void displayHand(byte, byte)': Arduino_Blackjack1.ino:482:44: error: 'deckRankIndex' was not declared in this scope Error compiling.

This report would have more information with "Show verbose output during compilation" enabled in File > Preferences.

this code needs work.

I have an Uno and will check out the new IDE build this weekend to see what's up.

Cool project 8)

New to Arduino, tried t run your black jack game with no luck list ed below is the log from after i compile it.

Arduino: 1.6.8 (Mac OS X), TD: 1.28, Board: "Arduino/Genuino Uno"

Arduino_Blackjack:113: error: no matching function for call to 'DFR_Key::DFR_Key()' DFR_Key keypad; ^ /Users/Terry/Documents/Arduino/Personal Sketchbooks/Arduino_Blackjack/Arduino_Blackjack.ino:113:9: note: candidates are: In file included from /Users/Terry/Documents/Arduino/Personal Sketchbooks/Arduino_Blackjack/Arduino_Blackjack.ino:112:0: /Users/Terry/Documents/Arduino/libraries/DFR_Key/DFR_Key.h:17:5: note: DFR_Key::DFR_Key(int) DFR_Key(int);

^ /Users/Terry/Documents/Arduino/libraries/DFR_Key/DFR_Key.h:17:5: note: candidate expects 1 argument, 0 provided /Users/Terry/Documents/Arduino/libraries/DFR_Key/DFR_Key.h:14:7: note: constexpr DFR_Key::DFR_Key(const DFR_Key&) class DFR_Key

^ /Users/Terry/Documents/Arduino/libraries/DFR_Key/DFR_Key.h:14:7: note: candidate expects 1 argument, 0 provided /Users/Terry/Documents/Arduino/libraries/DFR_Key/DFR_Key.h:14:7: note: constexpr DFR_Key::DFR_Key(DFR_Key&&) /Users/Terry/Documents/Arduino/libraries/DFR_Key/DFR_Key.h:14:7: note: candidate expects 1 argument, 0 provided Multiple libraries were found for "LiquidCrystal.h" Used: /Applications/Arduino.app/Contents/Java/libraries/LiquidCrystal Not used: /Users/Terry/Documents/Arduino/libraries/NewliquidCrystal exit status 1 no matching function for call to 'DFR_Key::DFR_Key()'

This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.

Hi Terry_G.

It looks like you are missing the keypad_lcd library. You can find the libraries I used here: https://github.com/linhartr22/Arduino_Blackjack.

Hope that helps!