Main Program (Slot 0) and Simple Flowchart ' {$STAMP BS2e, texas1.bse, texas2.bse, pickup.bse} ' {$PBASIC 2.5} ' -----[ Program Description ]--------------------------------------------- ' SLOT 0 ' This is the main routine that gives the game options. This program will run ' programs texas1, texas2, or pickup depending on the users inputs. ' texas1 is saved to slot 1, texas2 is saved to slot 2, and pickup is saved to slot 3 ' -----[ I/O Definitions ]------------------------------------------------- LCDPin PIN 0 ' serial output to LCD Up PIN 2 ' Up button Down PIN 1 ' Down button Enter PIN 3 ' Enter button Player1 PIN 4 ' Player 1 button Player2 PIN 5 ' Player 2 button Player3 PIN 6 ' Player 3 button Player4 PIN 14 ' Player 4 button Player1LED PIN 15 ' Player 1 LED Player2LED PIN 9 ‘ Player 2 LED Player3LED PIN 10 ' Player 3 LED Player4LED PIN 11 ' Player 4 LED RF_TX PIN 12 ' RF Transmitter vmTX PIN 13 ' VMusic 2 Transmit pin ' -----[ Constants ]------------------------------------------------------- Baud19200 CON 32 ' Baud rate for LCD Screen dealhand CON 0 flop CON 1 fourth CON 2 fifth CON 4 ' -----[ Variables anD aliases]----------------------------------------- btnWrk VAR BYTE game VAR BIT Players VAR NIB counter VAR NIB dealerbutton VAR NIB LED VAR NIB note VAR BIT ' -----[ Initialization ]-------------------------------------------------- Players = %0000 ' Initialize all player positions to zero Reset: HIGH LCDPin ' setup serial output pin PAUSE 2000 ' allow LCD to initialize SEROUT LCDPin, Baud19200, [17] ' Turn on backlight ' -----[ Program Code ]---------------------------------------------------- Main: GOSUB clearscreen DEBUG "main", CR SEROUT LCDPin, Baud19200, ["What game would you like to play?"] SEROUT LCDPin, Baud19200, [169] SEROUT LCDPin, Baud19200, ["Texas Hold 'Em"] SEROUT LCDPin, Baud19200, [189] SEROUT LCDPin, Baud19200, ["Surprise Game"] SEROUT LCDPin, Baud19200, [168] game = 0 GOTO PickGame ' This section of code allows the user to choose between 2 different game options ' The user can "scroll" up or down to select either game option ' The variable game keeps track of which option is the cursor is curently on ' A failsafe has been programmed incase the user pushes the up button when the ' cursor is already at its top position. The code will not allow a user to "do the wrong thing" PickGame: DEBUG "pick game",CR DO BUTTON Up, 1, 200, 200, btnWrk, 1, CursorUp BUTTON Down, 1, 200, 200, btnWrk, 1, CursorDown BUTTON Enter, 1, 200, 200, btnWrk, 1, Enterkey LOOP CursorUp: PAUSE 200 DEBUG "up",CR IF game = 0 THEN GOTO PickGame ENDIF SEROUT LCDPin, Baud19200, [168] game = 0 GOTO PickGame CursorDown: PAUSE 200 DEBUG "down",CR IF game = 1 THEN GOTO PickGame ENDIF SEROUT LCDPin, Baud19200, [188] game = 1 GOTO PickGame Enterkey: PAUSE 200 DEBUG "enter key",CR SELECT game CASE = 0 GOTO options ' Allow the user to choose between play with voice or music CASE = 1 RUN 3 ' Run program 3 - "52 Card Pick up" ENDSELECT ' This code is almost identical to the above code, instead it allow the user to choose ' between texas hold em play with voice or music options: PAUSE 200 GOSUB clearscreen DEBUG "main", CR SEROUT LCDPin, Baud19200, ["Voice Commands or Music?"] SEROUT LCDPin, Baud19200, [169] SEROUT LCDPin, Baud19200, ["Voice"] SEROUT LCDPin, Baud19200, [189] SEROUT LCDPin, Baud19200, ["Music"] SEROUT LCDPin, Baud19200, [168] game = 0 SEROUT vmTX,84,["VPF options.mp3",CR] GOTO choice choice: DEBUG "pick game",CR DO BUTTON Up, 1, 200, 200, btnWrk, 1, Upbutton BUTTON Down, 1, 200, 200, btnWrk, 1, Downbutton BUTTON Enter, 1, 200, 200, btnWrk, 1, Enterbutton LOOP Upbutton: PAUSE 200 DEBUG "up",CR IF game = 0 THEN GOTO choice ENDIF SEROUT LCDPin, Baud19200, [168] game = 0 GOTO choice Downbutton: PAUSE 200 DEBUG "down",CR IF game = 1 THEN GOTO choice ENDIF SEROUT LCDPin, Baud19200, [188] game = 1 GOTO choice Enterbutton: PAUSE 200 DEBUG "enter key",CR SELECT game CASE = 0 RUN 1 ' Run program 1 - texas hold em with voice CASE = 1 RUN 2 ' Run program 2 - texas hold em with music ENDSELECT ' -----[ LCD Screen Routines ]--------------------------------------------------- clearscreen: SEROUT LCDPin, Baud19200, [12] PAUSE 5 RETURN Texas Hold ‘em w/ Voice (Slot 1) and Simple Flowchart ' {$STAMP BS2e} ' {$PBASIC 2.5} ' -----[ Program Description ]--------------------------------------------- ' This version of Texas Hold 'em has voice commands but plays no music. ' The program will continue to loop through dealing rounds until the ' system is reset. There is currently no functionality to return to the main ' menu during game play. ' -----[ I/O Definitions ]------------------------------------------------- LCDPin PIN 0 ' serial output to LCD Up PIN 2 ' Up button Down PIN 1 ' Down button Enter PIN 3 ' Enter button Player1 PIN 4 ' Player 1 button Player2 PIN 5 ' Player 2 button Player3 PIN 6 ' Player 3 button Player4 PIN 14 ' Player 4 button Player1LED PIN 15 ' Player 1 LED Player2LED PIN 9 ‘ Player 2 LED Player3LED PIN 10 ' Player 3 LED Player4LED PIN 11 ' Player 4 LED RF_TX PIN 12 ' RF Transmitter vmTX PIN 13 ' VMusic 2 Transmit pin ' -----[ Constants ]------------------------------------------------------- Baud19200 CON 32 ' Baud rate for LCD Screen dealhand CON 0 flop CON 1 fourth CON 2 fifth CON 4 ' -----[ Variables anD aliases]----------------------------------------- btnWrk VAR BYTE game VAR BIT Players VAR NIB counter VAR NIB dealerbutton VAR NIB LED VAR NIB note VAR BIT ' -----[ Initialization ]-------------------------------------------------- SEROUT vmTX,84,["CD voice",CR] ' -----[ Program ]----------------------------------------------------- ' Display welcome text and play welcome mp3 texas: GOSUB clearscreen SEROUT LCDPin, Baud19200, ["Welcome to Texas Hold 'Em!"] SEROUT LCDPin, Baud19200, [168] SEROUT LCDPin, Baud19200, ["Login and Press Enter When Done"] SEROUT vmTX,84,["VPF texas.mp3",CR] GOTO Login ' This section of code allows players to login. Each subroutine assigns a 0 or 1 to ' a 4 bit variable in the respective player positions. E.g. if players 1, 2 and 4 login ' the 4 bit binary number will be 1011. Read from right to left this binary number represents ' the players that have logged in. This piece of information allows us to customize gameplay ' to serve only the players that have logged in at the begining of the game. This code ' also displays a welcome messages to each player and flashes an the players LED to confirm ' that the player has logged in Login: DO BUTTON Player1, 1, 200, 200, btnWrk, 1, Player1Log BUTTON Player2, 1, 200, 200, btnWrk, 1, Player2Log BUTTON Player3, 1, 200, 200, btnWrk, 1, Player3Log BUTTON Player4, 1, 200, 200, btnWrk, 1, Player4Log BUTTON Enter, 1, 200, 200, btnWrk, 1, SetDealerButton LOOP Player1Log: GOSUB clearscreen SEROUT LCDPin, Baud19200, ["Welcome Player 1!"] Players.BIT0 = 1 LED = 15 GOSUB flashled GOTO login Player2Log: GOSUB clearscreen SEROUT LCDPin, Baud19200, ["Welcome Player 2!"] Players.BIT1 = 1 LED = 9 GOSUB flashled GOTO login Player3Log: GOSUB clearscreen SEROUT LCDPin, Baud19200, ["Welcome Player 3!"] Players.BIT2 = 1 LED = 10 GOSUB flashled GOTO login Player4Log: GOSUB clearscreen SEROUT LCDPin, Baud19200, ["Welcome Player 4!"] Players.BIT3 = 1 LED = 11 GOSUB flashled GOTO Login flashled: FOR counter = 0 TO 1 HIGH LED PAUSE 300 LOW LED PAUSE 300 NEXT RETURN ' In the game of Texas hold 'em there is always one player that has the dealer button ' The player button changes from round to round and signifies who the dealer deals ' cards to first. In our game we use LEDs for each player to represent who has the ' dealer button. This small section of code looks through the player nib bit by bit and ' finds the first player starting from player 1. Once it finds the first player it sets ' that player as the dealer button and turns on their LED. Later subroutines changebutton, ' checkbutton, and setbutton all change the dealer button clockwise between rounds SetDealerButton: IF Players.BIT0 = 1 THEN dealerbutton = 1 HIGH 15 ELSEIF Players.BIT1 = 1 THEN dealerbutton = 2 HIGH 9 ELSEIF Players.BIT2 = 1 THEN dealerbutton = 3 HIGH 10 ELSEIF Players.BIT3 = 1 THEN dealerbutton = 4 HIGH 11 ENDIF GOTO sendplayers ' This code sends the player data to the other stamp for its use. ' Stamp 2 is always in a state of waiting for the character string "ABC" ' When it sees this character string it will read in the next two pieces of information. ' "l", "g", and "m" are arbitrary letters that are used to tell Stamp 2 what kind of ' data is being sent. "l" is used to designate player position data. "g" is used to ' designate in game commands. "m" is used to reset the card shuffle warning LED on ' Stamp 2 sendplayers: PULSOUT RF_TX, 1200 'Sync pulse for the receiver SEROUT RF_TX, 16468, [ "ABC", "l", players] GOTO postblinds ' The following routines instruct the players what to do ‘ and tell Stamp 2 what hand to deal. postblinds: GOSUB clearscreen SEROUT LCDPin, Baud19200, ["Please Post Blinds!"] SEROUT LCDPin, Baud19200, [168] SEROUT LCDPin, Baud19200, ["Press Enter When Done"] SEROUT vmTX,84,["VPF bets.mp3",CR] DO BUTTON Enter, 1, 200, 200, btnWrk, 1, dealplayercards LOOP dealplayercards: PULSOUT RF_TX, 1200 'Sync pulse for the receiver SEROUT RF_TX, 16468, [ "ABC", "g", dealhand] GOSUB clearscreen SEROUT LCDPin, Baud19200, ["Dealing Hole Cards"] SEROUT LCDPin, Baud19200, [168] SEROUT LCDPin, Baud19200, ["Place Bets and PressEnter When Done"] SEROUT vmTX,84,["VPF hole.mp3",CR] PAUSE 2000 SEROUT vmTX,84,["VPF bets2.mp3",CR] PAUSE 5000 DO BUTTON Enter, 1, 200, 200, btnWrk, 1, dealflop LOOP dealflop: PULSOUT RF_TX, 1200 'Sync pulse for the receiver SEROUT RF_TX, 16468, [ "ABC", "g", flop] GOSUB clearscreen SEROUT LCDPin, Baud19200, ["The Flop"] SEROUT LCDPin, Baud19200, [168] SEROUT LCDPin, Baud19200, ["Place Bets and PressEnter When Done"] SEROUT vmTX,84,["VPF flop.mp3",CR] PAUSE 2000 SEROUT vmTX,84,["VPF bets2.mp3",CR] PAUSE 5000 DO BUTTON Enter, 1, 200, 200, btnWrk, 1, fourthstreet LOOP fourthstreet: PULSOUT RF_TX, 1200 'Sync pulse for the receiver SEROUT RF_TX, 16468, [ "ABC", "g", fourth] GOSUB clearscreen SEROUT LCDPin, Baud19200, ["Fourth Street"] SEROUT LCDPin, Baud19200, [168] SEROUT LCDPin, Baud19200, ["Place Bets and PressEnter When Done"] SEROUT vmTX,84,["VPF fourth.mp3",CR] PAUSE 2000 SEROUT vmTX,84,["VPF bets2.mp3",CR] PAUSE 5000 DO BUTTON Enter, 1, 200, 200, btnWrk, 1, fifthstreet LOOP fifthstreet: PULSOUT RF_TX, 1200 'Sync pulse for the receiver SEROUT RF_TX, 16468, [ "ABC", "g", fifth] GOSUB clearscreen SEROUT LCDPin, Baud19200, ["Fifth Street"] SEROUT LCDPin, Baud19200, [168] SEROUT LCDPin, Baud19200, ["Place Bets and PressEnter When Done"] SEROUT vmTX,84,["VPF fifth.mp3",CR] PAUSE 2000 SEROUT vmTX,84,["VPF bets2.mp3",CR] PAUSE 5000 DO BUTTON Enter, 1, 200, 200, btnWrk, 1, ResetOrNextHand LOOP ' This code give the player the option to play a new hand or reset the card count ResetOrNextHand: PAUSE 200 GOSUB clearscreen 'DEBUG "main", CR SEROUT LCDPin, Baud19200, ["Next Hand or Reset Card Count"] SEROUT LCDPin, Baud19200, [169] SEROUT LCDPin, Baud19200, ["Next Hand"] SEROUT LCDPin, Baud19200, [189] SEROUT LCDPin, Baud19200, ["Reset Count"] SEROUT LCDPin, Baud19200, [168] note = 0 SEROUT vmTX,84,["VPF horr.mp3",CR] GOTO handORreset handORreset: 'DEBUG "pick game",CR DO BUTTON Up, 1, 200, 200, btnWrk, 1, CursorUp BUTTON Down, 1, 200, 200, btnWrk, 1, CursorDown BUTTON Enter, 1, 200, 200, btnWrk, 1, Enterkey LOOP CursorUp: PAUSE 200 'DEBUG "up",CR IF note = 0 THEN GOTO handORreset ENDIF SEROUT LCDPin, Baud19200, [168] note = 0 GOTO handORreset CursorDown: PAUSE 200 'DEBUG "down",CR IF note = 1 THEN GOTO handORreset ENDIF SEROUT LCDPin, Baud19200, [188] note = 1 GOTO handORreset Enterkey: PAUSE 200 'DEBUG "enter key",CR SELECT note CASE = 0 GOTO changebutton CASE = 1 PULSOUT RF_TX, 1200 'Sync pulse for the receiver SEROUT RF_TX, 16468, [ "ABC", "m"] GOTO changebutton ENDSELECT ' This code utilizes some if statements and case statements to set the next dealer button ' Changebutton will turn off all LEDs (only one will be on) and then it increments dealerbutton ' by 1. Since there are only 5 players the program will set the dealerbutton to player 1 ' if the dealerbutton reaches a value of 5. changebutton: 'DEBUG "change button", CR LOW 15 LOW 9 LOW 10 LOW 11 dealerbutton = dealerbutton + 1 IF dealerbutton = 5 THEN dealerbutton = 1 ENDIF ' Checkbutton will check to see if there is actually someone sitting at the current ' dealerbutton location. If there is no on sitting there, e.g. players.bit0 = 0 then ' it will set the dealer button clockwise to the next seat. The code will continue ' to loop until the dealer button is set a logged in seat. checkbutton: 'DEBUG "Check Button", CR IF players.BIT0 = 0 AND dealerbutton = 1 THEN dealerbutton = 2 GOTO checkbutton ELSEIF players.BIT1 = 0 AND dealerbutton = 2 THEN dealerbutton = 3 GOTO checkbutton ELSEIF players.BIT2 = 0 AND dealerbutton = 3 THEN dealerbutton = 4 GOTO checkbutton ELSEIF players.BIT3 = 0 AND dealerbutton = 4 THEN dealerbutton = 1 GOTO checkbutton ELSE GOTO setbutton ENDIF ' Set button will turn on the LED of the new dealerbutton setbutton: SELECT dealerbutton CASE = 1 HIGH 15 CASE = 2 HIGH 9 CASE = 3 HIGH 10 CASE = 4 HIGH 11 ENDSELECT GOTO postblinds ' -----[ LCD Screen Routines ]----------------------------------------------------- clearscreen: DEBUG "ClearScreen", CR SEROUT LCDPin, Baud19200, [12] PAUSE 15 RETURN Texas Hold ‘em w/ Music Program (Slot 2) ' {$STAMP BS2e} ' {$PBASIC 2.5} ' -----[ Program Description ]--------------------------------------------- ' This program is identical to texas1.bse except it opens a music directory ' in the mp3 module and plays all the music in that folder. All voice commands ' are eliminated in this version of Texas Hold 'em ' -----[ I/O Definitions ]------------------------------------------------- LCDPin PIN 0 ' serial output to LCD Up PIN 2 ' Up button Down PIN 1 ' Down button Enter PIN 3 ' Enter button Player1 PIN 4 ' Player 1 button Player2 PIN 5 ' Player 2 button Player3 PIN 6 ' Player 3 button Player4 PIN 14 ' Player 4 button Player1LED PIN 15 ' Player 1 LED Player2LED PIN 9 ‘ Player 2 LED Player3LED PIN 10 ' Player 3 LED Player4LED PIN 11 ' Player 4 LED RF_TX PIN 12 ' RF Transmitter vmTX PIN 13 ' VMusic 2 Transmit pin ' -----[ Constants ]------------------------------------------------------- Baud19200 CON 32 ' Baud rate for LCD Screen dealhand CON 0 flop CON 1 fourth CON 2 fifth CON 4 ' -----[ Variables and aliases]----------------------------------------- btnWrk VAR BYTE game VAR BIT Players VAR NIB counter VAR NIB dealerbutton VAR NIB LED VAR NIB note VAR BIT ' -----[ Initialization ]-------------------------------------------------- PAUSE 500 SEROUT vmTX,84,["CD music", CR] ' Open music directory in the mp3 module SEROUT vmTX,84,["V3A", CR] ‘ Play all files in directory ' -----[ Program ]----------------------------------------------------- texas: GOSUB clearscreen SEROUT LCDPin, Baud19200, ["Welcome to Texas Hold 'Em!"] SEROUT LCDPin, Baud19200, [168] SEROUT LCDPin, Baud19200, ["Login and Press Enter When Done"] GOTO Login Login: DO BUTTON Player1, 1, 200, 200, btnWrk, 1, Player1Log BUTTON Player2, 1, 200, 200, btnWrk, 1, Player2Log BUTTON Player3, 1, 200, 200, btnWrk, 1, Player3Log BUTTON Player4, 1, 200, 200, btnWrk, 1, Player4Log BUTTON Enter, 1, 200, 200, btnWrk, 1, SetDealerButton LOOP Player1Log: GOSUB clearscreen SEROUT LCDPin, Baud19200, ["Welcome Player 1!"] Players.BIT0 = 1 LED = 15 GOSUB flashled GOTO login Player2Log: GOSUB clearscreen SEROUT LCDPin, Baud19200, ["Welcome Player 2!"] Players.BIT1 = 1 LED = 9 GOSUB flashled GOTO login Player3Log: GOSUB clearscreen SEROUT LCDPin, Baud19200, ["Welcome Player 3!"] Players.BIT2 = 1 LED = 10 GOSUB flashled GOTO login Player4Log: GOSUB clearscreen SEROUT LCDPin, Baud19200, ["Welcome Player 4!"] Players.BIT3 = 1 LED = 11 GOSUB flashled GOTO Login flashled: FOR counter = 0 TO 1 HIGH LED PAUSE 300 LOW LED PAUSE 300 NEXT RETURN SetDealerButton: IF Players.BIT0 = 1 THEN dealerbutton = 1 HIGH 15 ELSEIF Players.BIT1 = 1 THEN dealerbutton = 2 HIGH 9 ELSEIF Players.BIT2 = 1 THEN dealerbutton = 3 HIGH 10 ELSEIF Players.BIT3 = 1 THEN dealerbutton = 4 HIGH 11 ENDIF GOTO sendplayers sendplayers: PULSOUT RF_TX, 1200 'Sync pulse for the receiver SEROUT RF_TX, 16468, [ "ABC", "l", players] GOTO postblinds postblinds: GOSUB clearscreen SEROUT LCDPin, Baud19200, ["Please Post Blinds!"] SEROUT LCDPin, Baud19200, [168] SEROUT LCDPin, Baud19200, ["Press Enter When Done"] DO BUTTON Enter, 1, 200, 200, btnWrk, 1, dealplayercards LOOP dealplayercards: PULSOUT RF_TX, 1200 'Sync pulse for the receiver SEROUT RF_TX, 16468, [ "ABC", "g", dealhand] GOSUB clearscreen SEROUT LCDPin, Baud19200, ["Dealing Hole Cards"] SEROUT LCDPin, Baud19200, [168] SEROUT LCDPin, Baud19200, ["Place Bets and PressEnter When Done"] PAUSE 5000 DO BUTTON Enter, 1, 200, 200, btnWrk, 1, dealflop LOOP dealflop: PULSOUT RF_TX, 1200 'Sync pulse for the receiver SEROUT RF_TX, 16468, [ "ABC", "g", flop] GOSUB clearscreen SEROUT LCDPin, Baud19200, ["The Flop"] SEROUT LCDPin, Baud19200, [168] SEROUT LCDPin, Baud19200, ["Place Bets and PressEnter When Done"] PAUSE 5000 DO BUTTON Enter, 1, 200, 200, btnWrk, 1, fourthstreet LOOP fourthstreet: PULSOUT RF_TX, 1200 'Sync pulse for the receiver SEROUT RF_TX, 16468, [ "ABC", "g", fourth] GOSUB clearscreen SEROUT LCDPin, Baud19200, ["Fourth Street"] SEROUT LCDPin, Baud19200, [168] SEROUT LCDPin, Baud19200, ["Place Bets and PressEnter When Done"] PAUSE 5000 DO BUTTON Enter, 1, 200, 200, btnWrk, 1, fifthstreet LOOP fifthstreet: PULSOUT RF_TX, 1200 'Sync pulse for the receiver SEROUT RF_TX, 16468, [ "ABC", "g", fifth] GOSUB clearscreen SEROUT LCDPin, Baud19200, ["Fifth Street"] SEROUT LCDPin, Baud19200, [168] SEROUT LCDPin, Baud19200, ["Place Bets and PressEnter When Done"] PAUSE 5000 DO BUTTON Enter, 1, 200, 200, btnWrk, 1, ResetOrNextHand LOOP ResetOrNextHand: PAUSE 200 GOSUB clearscreen SEROUT LCDPin, Baud19200, ["Next Hand or Reset Card Count"] SEROUT LCDPin, Baud19200, [169] SEROUT LCDPin, Baud19200, ["Next Hand"] SEROUT LCDPin, Baud19200, [189] SEROUT LCDPin, Baud19200, ["Reset Count"] SEROUT LCDPin, Baud19200, [168] note = 0 GOTO handORreset handORreset: DO BUTTON Up, 1, 200, 200, btnWrk, 1, CursorUp BUTTON Down, 1, 200, 200, btnWrk, 1, CursorDown BUTTON Enter, 1, 200, 200, btnWrk, 1, Enterkey LOOP CursorUp: PAUSE 200 IF note = 0 THEN GOTO handORreset ENDIF SEROUT LCDPin, Baud19200, [168] note = 0 GOTO handORreset CursorDown: PAUSE 200 IF note = 1 THEN GOTO handORreset ENDIF SEROUT LCDPin, Baud19200, [188] note = 1 GOTO handORreset Enterkey: PAUSE 200 SELECT note CASE = 0 GOTO changebutton CASE = 1 PULSOUT RF_TX, 1200 'Sync pulse for the receiver SEROUT RF_TX, 16468, [ "ABC", "m"] GOTO changebutton ENDSELECT changebutton: LOW 15 LOW 9 LOW 10 LOW 11 dealerbutton = dealerbutton + 1 IF dealerbutton = 5 THEN dealerbutton = 1 ENDIF checkbutton: IF players.BIT0 = 0 AND dealerbutton = 1 THEN dealerbutton = 2 GOTO checkbutton ELSEIF players.BIT1 = 0 AND dealerbutton = 2 THEN dealerbutton = 3 GOTO checkbutton ELSEIF players.BIT2 = 0 AND dealerbutton = 3 THEN dealerbutton = 4 GOTO checkbutton ELSEIF players.BIT3 = 0 AND dealerbutton = 4 THEN dealerbutton = 1 GOTO checkbutton ELSE GOTO setbutton ENDIF setbutton: SELECT dealerbutton CASE = 1 HIGH 15 CASE = 2 HIGH 9 CASE = 3 HIGH 10 CASE = 4 HIGH 11 ENDSELECT GOTO postblinds ' -----[ LCD Screen Routines ]----------------------------------------------------- clearscreen: SEROUT LCDPin, Baud19200, [12] PAUSE 5 RETURN 52-Card Pick (Slot 3) and Simple Flowchart ' {$STAMP BS2e} ' {$PBASIC 2.5} ' -----[ Program Description ]--------------------------------------------- ' This is program tells Basic Stamp 2 to deal 52 Card Pick-UP and then returns ' to the main program in slot 0 ' -----[ I/O Definitions ]------------------------------------------------- LCDPin PIN 0 ' serial output to LCD Up PIN 2 ' Up button Down PIN 1 ' Down button Enter PIN 3 ' Enter button Player1 PIN 4 ' Player 1 button Player2 PIN 5 ' Player 2 button Player3 PIN 6 ' Player 3 button Player4 PIN 14 ' Player 4 button Player1LED PIN 15 ' Player 1 LED Player2LED PIN 9 ‘ Player 2 LED Player3LED PIN 10 ' Player 3 LED Player4LED PIN 11 ' Player 4 LED RF_TX PIN 12 ' RF Transmitter vmTX PIN 13 ' VMusic 2 Transmit pin ' -----[ Constants ]------------------------------------------------------- Baud19200 CON 32 ' Baud rate for LCD Screen dealhand CON 0 flop CON 1 fourth CON 2 fifth CON 4 ' -----[ Variables and aliases]----------------------------------------- btnWrk VAR BYTE game VAR BIT Players VAR NIB counter VAR NIB dealerbutton VAR NIB LED VAR NIB note VAR BIT ' -----[ 52 Card Pick-Up Routines ]-------------------------------------- pickup: GOSUB clearscreen SEROUT LCDPin, Baud19200, ["Welcome to 52 Card Pick-Up!"] SEROUT vmTX,84,["VPF sucker.mp3",CR] PULSOUT RF_TX, 1200 'Sync pulse for the receiver SEROUT RF_TX, 16468, [ "ABC", "g", 8] PAUSE 15000 RUN 0 ' -----[ LCD Screen Routines ]----------------------------------------- clearscreen: SEROUT LCDPin, Baud19200, [12] PAUSE 5 RETURN ----------------------------------------------------------------------------------------------- CODE ' {$STAMP BS2} ' {$PBASIC 2.5} '_____variables_____ positions VAR Nib '4 bit binary, 0=no player @ bit(i) 1=player @ bit(i) cardsdealt VAR Byte 'from 0-51 i VAR Byte 'longer loops j VAR Bit 'dealplayers "loop" ftcards VAR Byte 'surprise variable x VAR Byte 'surprise variable y VAR Word 'surprise variable dealerbut VAR Nib 'dealer button tracker rfsig1 VAR Word 'RF input rfsig2 VAR Word 'RF input modifier '_____pins_____ shuffleled PIN 0 'shuffle warning light pin htserv PIN 1 'position servo pin dealserv PIN 2 'CR/dealer servo pin HB25 PIN 4 'motor controller pin rf PIN 13 'rf receiver pin '_____constants_____ hispeed CON 845 'dc motor high speed for HB25 lospeed CON 845 'dc motor low speed for HB25 dealspeed CON 720 'CR servo turning rate spitdur CON 28 'CR servo turning duration fliptime CON 1 'time to let the card rest on the "flipper" before moving the servo to flip it pulsdur CON 40 'number of pulses sent to position servo to allow for rotation pos1 CON 400 'pos of player 1 pos2 CON 600 'pos of player 2 pos3 CON 775 'pos of player 3 pos4 CON 950 'pos of player 4 flop1 CON 400 'NOTE: flop*(f) are the positions of the players, put in like this for easy calibration flop1f CON 250 ' ' flopf's are not used but could be in the future to flip the house cards face up flop2 CON 500 ' ' flop2f CON 450 ' ' flop3 CON 625 ' ' flop3f CON 600 ' ' see "NOTE" above flop4 CON 750 ' ' flop4f CON 650 ' ' flop5 CON 875 ' ' flop5f CON 850 ' ' '_____initialize_____ DO : LOOP UNTIL HB25 = 1 ' WAIt FOr HB-25 Power Up LOW HB25 ' Make I/O Pin Output/Low PAUSE 5 ' Wait For HB-25 To Initialize PULSOUT HB25, 750 PAUSE 1 PULSOUT HB25, 750 '_____GAMBIT DEALING_____ login: 'gets a signal from the RF transmitter DEBUG "waiting", CR SERIN rf, 16468, [WAIT("ABC"), rfsig1, rfsig2] IF rfsig1="l" THEN positions = rfsig2 ' this extra signal ensures that random "ABC" bits won't do anything to the dealer GOSUB firstdealerbutton DEBUG BIN4 positions, CR DEBUG DEC positions, CR 'same here ELSEIF rfsig1="g" THEN DEBUG "enter", CR GOTO decide '....and here ELSEIF rfsig1="m" THEN cardsdealt=0 LOW shuffleled ENDIF GOTO login 'if nothing makes sense then it goes and waits again decide: IF rfsig2=0 THEN dealplayers ' pick which routine to run based on rf signal IF rfsig2=1 THEN dealflop IF rfsig2=2 THEN dealturn IF rfsig2=4 THEN dealriver IF rfsig2=8 THEN surprise firstdealerbutton: ' make sure the first dealer button is at a filled seat IF positions.BIT0 = 1 THEN dealerbut = 0 RETURN ELSEIF positions.BIT1 = 1 THEN dealerbut = 1 RETURN ELSEIF positions.BIT2 = 1 THEN dealerbut = 2 RETURN ELSEIF positions.BIT3 = 1 THEN dealerbut = 3 RETURN ENDIF dealplayers: DEBUG "in dealplayers", CR GOSUB DConhigh IF dealerbut=0 THEN FOR j=0 TO 1 IF positions.BIT0=1 THEN 'DEAL TO POSITION ONE FIRST DEBUG "pl1", CR FOR i = 1 TO pulsdur PULSOUT htserv, pos1 PAUSE 20 NEXT GOSUB spitcard ENDIF IF positions.BIT1=1 THEN DEBUG "pl2", CR FOR i = 1 TO pulsdur PULSOUT htserv, pos2 PAUSE 20 NEXT GOSUB spitcard ENDIF IF positions.BIT2=1 THEN DEBUG "pl3", CR FOR i = 1 TO pulsdur PULSOUT htserv, pos3 PAUSE 20 NEXT GOSUB spitcard ENDIF IF positions.BIT3=1 THEN DEBUG "pl4", CR FOR i = 1 TO pulsdur PULSOUT htserv, pos4 PAUSE 20 NEXT GOSUB spitcard ENDIF NEXT 'deal 2nd card 'endif ELSEIF dealerbut=1 THEN FOR j=0 TO 1 'DEAL TO PLAYER 2 FIRST IF positions.BIT1=1 THEN DEBUG "pl2", CR FOR i = 1 TO pulsdur PULSOUT htserv, pos2 PAUSE 20 NEXT GOSUB spitcard ENDIF IF positions.BIT2=1 THEN DEBUG "pl3", CR FOR i = 1 TO pulsdur PULSOUT htserv, pos3 PAUSE 20 NEXT GOSUB spitcard ENDIF IF positions.BIT3=1 THEN DEBUG "pl4", CR FOR i = 1 TO pulsdur PULSOUT htserv, pos4 PAUSE 20 NEXT GOSUB spitcard ENDIF IF positions.BIT0=1 THEN 'DEAL TO POSITION ONE DEBUG "pl1", CR FOR i = 1 TO pulsdur PULSOUT htserv, pos1 PAUSE 20 NEXT GOSUB spitcard ENDIF NEXT 'deal 2nd card ELSEIF dealerbut=2 THEN FOR j=0 TO 1 'DEAL TO PLAYER 3 FIRST IF positions.BIT2=1 THEN DEBUG "pl3", CR FOR i = 1 TO pulsdur PULSOUT htserv, pos3 PAUSE 20 NEXT GOSUB spitcard ENDIF IF positions.BIT3=1 THEN DEBUG "pl4", CR FOR i = 1 TO pulsdur PULSOUT htserv, pos4 PAUSE 20 NEXT GOSUB spitcard ENDIF IF positions.BIT0=1 THEN 'DEAL TO POSITION ONE DEBUG "pl1", CR FOR i = 1 TO pulsdur PULSOUT htserv, pos1 PAUSE 20 NEXT GOSUB spitcard ENDIF IF positions.BIT1=1 THEN DEBUG "pl2", CR FOR i = 1 TO pulsdur PULSOUT htserv, pos2 PAUSE 20 NEXT GOSUB spitcard ENDIF NEXT ELSEIF dealerbut=3 THEN FOR j = 0 TO 1 IF positions.BIT3=1 THEN 'DEAL TO PLAYER 4 FIRST DEBUG "pl4", CR FOR i = 1 TO pulsdur PULSOUT htserv, pos4 PAUSE 20 NEXT GOSUB spitcard ENDIF IF positions.BIT0=1 THEN 'DEAL TO POSITION ONE DEBUG "pl1", CR FOR i = 1 TO pulsdur PULSOUT htserv, pos1 PAUSE 20 NEXT GOSUB spitcard ENDIF IF positions.BIT1=1 THEN DEBUG "pl2", CR FOR i = 1 TO pulsdur PULSOUT htserv, pos2 PAUSE 20 NEXT GOSUB spitcard ENDIF IF positions.BIT2=1 THEN DEBUG "pl3", CR FOR i = 1 TO pulsdur PULSOUT htserv, pos3 PAUSE 20 NEXT GOSUB spitcard ENDIF NEXT ENDIF GOSUB DCoff GOSUB movearm GOTO login dealflop: DEBUG "in dealflop", CR ' deals first 3 community cards GOSUB DConlow GOSUB discard FOR i = 1 TO pulsdur PULSOUT htserv, flop1 PAUSE 20 NEXT GOSUB spitcard PAUSE fliptime FOR i = 1 TO pulsdur PULSOUT htserv, flop2 PAUSE 20 NEXT GOSUB spitcard PAUSE fliptime FOR i = 1 TO pulsdur PULSOUT htserv, flop3 PAUSE 20 NEXT GOSUB spitcard PAUSE fliptime GOSUB DCoff GOSUB movearm GOTO login dealturn: DEBUG "in dealturn", CR GOSUB DConlow 'deals 4th community card GOSUB discard FOR i = 1 TO pulsdur PULSOUT htserv, flop4 PAUSE 20 NEXT GOSUB spitcard PAUSE fliptime GOSUB DCoff GOSUB movearm GOTO login dealriver: DEBUG "in dealriver", CR 'deals last community card GOSUB DConlow GOSUB discard FOR i = 1 TO pulsdur PULSOUT htserv, flop5 PAUSE 20 NEXT GOSUB spitcard GOSUB DCoff GOSUB movearm GOSUB changebutton GOTO login '_____subroutines_____ ' This code utilizes some if statements and case statments to set the next dealer button ' Changebutton will turn off all LEDs (only one will be on) and then it increments dealerbutton ' by 1. Since there are only 5 players the program will set the dealerbutton to player 1 ' if the dealerbutton reaches a value of 5. changebutton: dealerbut = dealerbut + 1 IF dealerbut = 4 THEN dealerbut = 0 ENDIF GOTO checkbutton ' Checkbutton will check to see if there is actually someone sitting at the current ' dealerbutton location. If there is no on sitting there, e.g. players.bit0 = 0 then ' it will set the dealer button clockwise to the next seat. The code will continue ' to loop until the dealer button is set a logged in seat. checkbutton: IF positions.BIT0 = 0 AND dealerbut = 0 THEN dealerbut = 1 GOTO checkbutton ELSEIF positions.BIT1 = 0 AND dealerbut = 1 THEN dealerbut = 2 GOTO checkbutton ELSEIF positions.BIT2 = 0 AND dealerbut = 2 THEN dealerbut = 3 GOTO checkbutton ELSEIF positions.BIT3 = 0 AND dealerbut = 3 THEN dealerbut = 0 ELSE RETURN ENDIF DConhigh: DEBUG "in dconhigh", CR 'runs dc motor at high speed FOR i = 0 TO 10 PULSOUT HB25, hispeed PAUSE 20 NEXT PAUSE 20 RETURN DConlow: DEBUG "in dconlow", CR 'runs dc motor at low speed LOW HB25 PAUSE 20 PULSOUT HB25, lospeed PAUSE 20 RETURN DCoff: DEBUG "in dcoff", CR 'turns off dc motor PAUSE 200 PULSOUT HB25, 750 PAUSE 20 LOW HB25 RETURN spitcard: 'gets card out of shoe DEBUG "in spitcard", CR PAUSE 5 FOR i=1 TO spitdur PULSOUT dealserv, dealspeed PAUSE 20 NEXT cardsdealt=cardsdealt+1 IF cardsdealt>34 THEN HIGH shuffleled ENDIF RETURN discard: ' discards when necessary by rules FOR i = 1 TO 20 PULSOUT htserv, 1050 PAUSE 20 NEXT GOSUB spitcard RETURN movearm: ' gets dealer out of the way of the table FOR i = 0 TO 30 PULSOUT htserv, 1200 PAUSE 20 NEXT RETURN surprise: 'surprise game routine GOSUB dconhigh2 DO UNTIL ftcards=51 RANDOM x y=x*10 IF y< 250 OR y> 1250 THEN GOTO surprise ENDIF FOR i = 0 TO 15 PULSOUT htserv, y PAUSE 20 NEXT GOSUB spitcard ftcards=ftcards+1 LOOP GOSUB dcoff GOTO login DConhigh2: DEBUG "in dconhigh", CR FOR i = 0 TO 10 PULSOUT HB25, 950 PAUSE 20 NEXT PAUSE 20 RETURN