Okay so I designed a device to help a user count cards in Blackjack. The idea is to have a nano board wired with a tactile switch in each shoe and servo strapped to each leg. User can click left shoe for low card, right shoe for high card, code evaluates and servos notify user to bet soft or hard.
I have wired a prototype and strung some code together, I am new to the C language and Arduino as a whole, this is my first major project. I can't seem to figure out why my code wont work. Hopefully I commented it well enough for you understand what I'm trying to make my sketch do.
I'm open to all input, chop my code up, rewrite it entirely, whatever. All I ask is that it's well commented so I can understand whats going on. Still learning C you see.
So here is what I came up with so far.
//My card counter
#include <Servo.h> ;
int Left_Button = 2 ; // Left button on pin 2
int Right_Button = 3 ; // Left button on pin 3
//Here I want declare the starting values for up to ten decks. I'm going with the standard +/- system for counting.
//To keep the device from telling me to bet to hard to often I took a conservative angle and flagged cards 2-9 as low
// and 10,J,Q,K,A as high from which I got the formula (-32) + 20 = -12/Deck.
char Shoe_Value(-12 -24 -36 -48 -60 -72 -84 -96 -108 -120) ;
Servo Left_Servo, Right_Servo ; // Create Servo objects
Left_Servo.attach(4) ; // Servo on pin 4
Right_Servo.attach(5) ; // Servo on pin 5
void setup() {
pinMode(Left_Button, INPUT) ; // Left button as input
pinMode(Right_Button, INPUT) ; // Right button as input
}
void loop() {
int Initial_Shoe_Value 0 ; // Create initial shoe value
int Deck_Count 0 ; // Create Deck count
int Card_Count 0 ; // Create card count
int Left_Button_State = digitalRead(Left_Button) ; // Create left button state
int Right_Button_State = digitalRead(Right_Button) ; // Create right button state
Left_Servo.write(180) ; // Set both servos to touch the user to notify that decks are not configured
Right_Servo.write(180) ; // Set both servos to touch the user to notify that decks are not configured
while (Left_Button_State == LOW) { // Configure # of decks right button = +1 left button = move along
if (Right_Button_State == HIGH) {
Deck_Count = Deck_Count + 1 ; // Deck count +1
}
}
switch(Deck_Count) { // Use switch to set card count and initial deck value
case 1:
Initial_Shoe_Value = Shoe_Value[0] ;
Card_Count = Shoe_Value[0] ;
case 2:
Initial_Shoe_Value = Shoe_Value[1] ;
Card_Count = Shoe_Value[1] ;
case 3:
Initial_Shoe_Value = Shoe_Value[2] ;
Card_Count = Shoe_Value[2] ;
case 4:
Initial_Shoe_Value = Shoe_Value[3] ;
Card_Count = Shoe_Value[3] ;
case 5:
Initial_Shoe_Value = Shoe_Value[4] ;
Card_Count = Shoe_Value[4] ;
case 6:
Initial_Shoe_Value = Shoe_Value[5] ;
Card_Count = Shoe_Value[5] ;
case 7:
Initial_Shoe_Value = Shoe_Value[6] ;
Card_Count = Shoe_Value[6] ;
case 8:
Initial_Shoe_Value = Shoe_Value[7] ;
Card_Count = Shoe_Value[7] ;
case 9:
Initial_Shoe_Value = Shoe_Value[8] ;
Card_Count = Shoe_Value[8] ;
case 10:
Initial_Shoe_Value = Shoe_Value[9] ;
Card_Count = Shoe_Value[9] ;
}
Left_Servo.write(90) // Set both servos back to home position
Right_Servo.write(90) // Set both servos back to home position
Game_On() ; // Call the Game_On function
}
void Game_On() {
if (Left_Button_State == HIGH && (Right_Button_State == HIGH)) { // call Dealer_Reshuffle() function if both buttons are pressed at the same time
Dealer_Reshuffle() ;
}
if (Left_Button_State == HIGH) { // Add + 1 to card count if left button is pressed
Card_Count = Card_Count + 1 ;
}
if (Right_Button_State == HIGH) { // Add - 1 to card count if left button was pressed
Card_Count = Card_Count - 1 ;
}
if (Card_Count == >0) { // If card cound = more then 0 call the Bet_Hard() function
Bet_Hard() ;
}
if (Card_Count == <0) { // if card count = less then 0 call Bet_Soft() function
Bet_Soft() ;
}
continue ; // Back to top of Game_On() function
}
void Bet_Hard() { // notify user to bet hard
Right_Servo.write(180) ;
Left_Servo.write(90) ;
Game_On() ; // Back to top of Game_On() function
}
void Bet_Soft() { // notify user to bet soft
Right_Servo.write(90) ;
Left_Servo.write(180) ;
Game_On() ; // Back to top of Game_On() function
}
void Dealer_Reshuffle() { // Set servos back to home position and restart the card count
Left_Servo.write(90) ;
Right_Servo.write(90) ;
Card_Count == Initial_Deck_Value ; // Reset card count
Game_On() ; // Back to top of Game_On() function
}
Also another problem that I have is with servo noise. Anyone who has ever worked with a servo knows about the audable "dzzzt" "dzzzt" that most servos make....
Naturally this would be problematic in a casino. I wired up a servo to a potentometer and notice that the servos hardly make any noise when the move "slowly".
I'm sure there is probably a way to control servo speed with code that I haven't figured out, any help in this department would be greatly appreciated.
That's pretty much what I'm working on right now. I have a diagram I made in fritzing I hope it uploads.
Thanks in advance