Tristan TysonAdam KennedyDaniel Vo
Published © GPL3+

Blackjack For Dummies

A simplified game of blackjack. For all the fun and a fraction of the thought

BeginnerFull instructions provided5 hours8
Blackjack For Dummies

Things used in this project

Hardware components

Argon
Particle Argon
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Membrane Keyboard
×1
Button
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

Daniel Diagram

Adam Diagram

Code

Dealer Station Code

C/C++
This code plays the roll of the dealer. It iterates through the players in the game. The players send a hit or stay option over the cloud (using Webhooks), which the dealer station receives. The dealer station then deals the player a new card if they selected hit, or passes over them if they selected stay.
#include <iostream>
using namespace std;



void setup() {
    
    Serial.begin(9600);
    
    

}

void loop() {
    int sum = 0;
    int TristanCards[] = {0,0,0,0,0};
    int AdamCards[] = {0,0,0,0,0};
    int DanielCards[] = {0,0,0,0,0};
    TristanCards[0] = rand()%(11-1 + 1) + 1;
    TristanCards[1] = rand()%(11-1 + 1) + 1;
    AdamCards[0] = rand()%(11-1 + 1) + 1;
    AdamCards[1] = rand()%(11-1 + 1) + 1;
    DanielCards[0] = rand()%(11-1 + 1) + 1;
    DanielCards[1] = rand()%(11-1 + 1) + 1;
  
    for (int i = 1; i <= 6; i++){
        if (i==1){
            int randNum = rand()%(11-1 + 1) + 1;
            TristanCards[2] = randNum;
            sum = 0;
            for (i = 0; i < 3; i++){
               sum = TristanCards[i] + sum;
                if (i==2){
                    if (sum > 21){
                      Particle.publish("Dealer Busted");
                        Particle.publish("sum", String(sum), PRIVATE);
                    }
                    if (sum == 21){
                      Particle.publish("Blackjack!", PRIVATE);
                    }
                    Particle.publish("sum", String(sum), PRIVATE);
                }
            }
        }
        if (i==2){
           int press = Particle.subscribe("hook-response/buttonPressAdam", myHandler, MY_DEVICES);
           if (press == 1){
                int randNum = rand()%(11-1 + 1) + 1;
                AdamCards[2] = randNum;
                sum = 0;
                for (i = 0; i < 3; i++){
                    sum = AdamCards[i] + sum;
                    if (i==2){
                        if (sum > 21){
                          Particle.publish("Adam Busted");
                            Particle.publish("sum", String(sum), PRIVATE);
                        }
                        if (sum == 21){
                          Particle.publish("Blackjack!");
                        }
                        Particle.publish("sum", String(sum), PRIVATE);
                    }
                }
           }
         
        
        if (i==3){
            int press2 = Particle.subscribe("hook-response/buttonPressDaniel", myHandler, MY_DEVICES);
            if (press2 == 1){
                int randNum = rand()%(11-1 + 1) + 1;
                DanielCards[2] = randNum;
                sum = 0;
                for (i = 0; i < 3; i++){
                   sum = DanielCards[i] + sum;
                    if (i==2){
                        if (sum > 21){
                          Particle.publish("Daniel Busted");
                            Particle.publish("sum", String(sum), PRIVATE);
                        }
                        if (sum == 21){
                          Particle.publish("Blackjack!");
                        }
                        Particle.publish("sum", String(sum), PRIVATE);
                    }
                }
            }
        }
        if (i==4){
            int randNum = rand()%(11-1 + 1) + 1;
            TristanCards[3] = randNum;
            sum = 0;
            for (i = 0; i < 4; i++){
                sum = TristanCards[i] + sum;
                if (i==2){
                    if (sum > 21){
                      Particle.publish("Dealer Busted");
                        Particle.publish("sum", String(sum), PRIVATE);
                    }
                    if (sum == 21){
                      Particle.publish("Blackjack!");
                    }
                    Particle.publish("sum", String(sum), PRIVATE);
                }
            }
            
        }
        if (i==5){
            int press3 = Particle.subscribe("hook-response/buttonPressAdam", myHandler, MY_DEVICES);
            if (press3 == 1){
                int randNum = rand()%(11-1 + 1) + 1;
                AdamCards[3] = randNum;
                sum = 0;
                for (i = 0; i < 4; i++){
                    sum = AdamCards[i] + sum;
                    if (i==2){
                        if (sum > 21){
                          Particle.publish("Adam Busted");
                            Particle.publish("sum", String(sum), PRIVATE);
                        }
                        if (sum == 21){
                          Particle.publish("Blackjack!");
                        }
                        Particle.publish("sum", String(sum), PRIVATE);
                    }
                }
            }
            
        }
        if (i==6){
            int press4 = Particle.subscribe("hook-response/buttonPressDaniel", myHandler, MY_DEVICES);
            if (press4 == 1){
                int randNum = rand()%(11-1 + 1) + 1;
                DanielCards[3] = randNum;
                sum = 0;
                for (i = 0; i < 4; i++){
                    sum = DanielCards[i] + sum;
                    if (i==2){
                        if (sum > 21){
                          Particle.publish("Daniel Busted");
                            Particle.publish("sum", String(sum), PRIVATE);
                        }
                        if (sum == 21){
                         Particle.publish("Blackjack!");
                        }
                        Particle.publish("sum", String(sum), PRIVATE);
                    }
                }
            }
            
        }
    }
}
   void myHandler(const char *event, const char *data) {
  // Handle the integration response
}

         
          

    

Webhook Test Code

C/C++
This code is used to ensure that the communication between the argons is valid. It sends a value to the webhook, which can then be logged into the verify that the webhook received the value.
void setup() {

}

void loop() {
    Particle.subscribe("hook-response/buttonPressAdam", myHandler, MY_DEVICES);
    Particle.subscribe("hook-response/buttonPressDaniel", myHandler, MY_DEVICES);
    Particle.publish("sum", String(1), PRIVATE);

}
void myHandler(const char *event, const char *data) {
  // Handle the integration response
}

Daniel (player code)

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <Keypad_Particle.h>


const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

void setup(){
  Serial.begin(9600);
  Particle.variable("buttonPressDaniel", hexaKeys[ROWS][COLS]);
}
  
void loop(){
  char customKey = customKeypad.getKey();
  
  if (customKey){
    Serial.println(customKey);
    Particle.publish("buttonPressDaniel", String(customKey), PRIVATE);
    
  }
}

#include <Adafruit_DHT.h>  

#define DHTPIN 9           
#define DHTTYPE DHT12	    

DHT dht(DHTPIN, DHTTYPE);  

const int TMP12Pin = A1;    
const int MQ2 = A5;          

double voltage, TMP12F, TMP12C, h, t, f, MQ2value;
int reading = 0;

void setup() {
    
	Serial.begin(9600); 
	Serial.println("IOT PROJECT IAMS Serial Test OKAY");
	
	pinMode(TMP12Pin, INPUT);   
	pinMode(MQ2, INPUT);        
    
	dht.begin(); 
	
	
	Particle.variable("DHT-12 in degF", f);
	Particle.variable("DHT-12 in degC", t);
	Particle.variable("DHT-12 in %h", h);
	
	Particle.variable("TMP12 in degF", TMP36F);
	Particle.variable("TMP12 in degC", TMP36C);
	Particle.variable("TMP12 volts", voltage);
	
	Particle.variable("MQ-2 Data", reading);
}

Adam's Code

C/C++
This code allows the players to utilize the membrane switch keypad to interact with the dealer. This device allows the dealer to know what action this player would like to take on his next turn.
#include <Keypad_Particle.h>

const int ROW_NUM = 4; 
const int COLUMN_NUM = 4; 

char keys[ROW_NUM][COLUMN_NUM] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte pin_rows[ROW_NUM] = {8, 7, 6, 5}; 
byte pin_column[COLUMN_NUM] = {4, 3, 2,1}; 

Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );


void setup() { 

  Serial.begin(9600);
  
  Particle.variable("buttonPressAdam",keys[ROW_NUM][COLUMN_NUM]);

}

void loop(){
 
  char key = keypad.getKey();
if (key){
    Serial.println(key);

    Particle.publish("buttonPressAdam", String(key), PUBLIC);
    Particle.subscribe("hook-response/sum", myHandler, MY_DEVICES);
}
}
void myHandler(const char *event, const char *data) {
 
}

Credits

Tristan Tyson

Tristan Tyson

1 project • 2 followers
Adam Kennedy

Adam Kennedy

1 project • 1 follower
Daniel Vo

Daniel Vo

1 project • 1 follower

Comments

Add projectSign up / Login