Introduction: CARD DEALER

Picture of CARD DEALER

This project was made as part of an assigment of "Usos academics en terminologia específica en angles I" in which we where asked to build a small project with an Arduino Uno board.

We decided to build a card dealer for poker games (just for the challenge, we know it's not going to be better than someone actually dealing).

Step 1: What You'll Need

- 1 x Arduino Uno board
- 2 x Stepper motors 28byj-48
- 2 x Stepper motor drivers
- 1 x LCD screen 16x2
- 1 x IIC controller
- A bunch of jumpers (lots of them, you'll never have to many jumpers)
- 3 x 1kohm restistors
- 3 x push buttons
- 1 x welding board
- 1 x tin coil for welding
- 1 x welder
- 1 x wood sheet (420x297mm)
- 1 x PMMA sheet (210x297mm)
- 1 x Glue
- 1 x Pain (red in our case)
- 4 x Bearing (10mm inner diam)
- 4 x Nylon axis (15mm long 10mm diam)
- 1 x Stell axis (20mm long 3mm diam)
- 2 x gears (50 tooth and 10 tooth)
- 1 x rubber band

Step 2: Step 1: Build Your Circuit

Picture of Step 1: Build Your Circuit

Step 3: Step 2: Get Your Code and Test It!

The code is like supper beginer, but im very proud of it since its my first arduino code ever :)

(i'll try and enter more commentaries to it later on)

//Enter Libraries

#include #include #define TOTALSTEPS 32*64 LiquidCrystal lcd(0); //Enter Variables int stepstoDo; int state = 0; //Inital state int stage = 1; int i = 0; boolean playerS = false; boolean e = false; int p = 2; int players = 4; int maxplayers = 8; int minplayers = 2;
int Bdelay = 20;
int cardDelay = 2000;
//stepper motors pins
int motorPin1 = 5;
int motorPin2 = 6;
int motorPin3 = 7;
int motorPin4 = 8;
int motorPin5 = 9;
int motorPin6 = 10;
int motorPin7 = 11;
int motorPin8 = 12;
//Arduino pin definition
int const LEFT = 1;
int const ENTER = 3;
int const RIGHT = 4;
//detector
int trigerpin = 13;
int echopin = 2;
float distance;
long t;
void setup() {
  //detector
  digitalWrite(trigerpin, HIGH);
  delay(10);
  digitalWrite(trigerpin, LOW);
  attachInterrupt(echopin, detector, CHANGE);
  // put your setup code here, to run once:
  pinMode(LEFT, INPUT);
  pinMode(ENTER, INPUT);
  pinMode(RIGHT, INPUT);
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("CARD");
  lcd.setCursor(0, 1);
  lcd.print("MASTER");
  delay(3000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("WELCOME!");
  delay(1500);
  lcd.setCursor(0, 1);
  lcd.print("press enter");
  //declare the motor pins as outputs
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
  pinMode(motorPin5, OUTPUT);
  pinMode(motorPin6, OUTPUT);
  pinMode(motorPin7, OUTPUT);
  pinMode(motorPin8, OUTPUT);
  Serial.begin(9600);
}
void loop() {
  if (state == 0 && digitalRead(ENTER) == LOW) {
    lcd.clear();
    state = 1;
  }
  //GAME SELECTION
  if (state == 1) {
    lcd.setCursor(0, 0);
    lcd.print("Select players!");
    playerS = true;
    //PLAYER SELECTION
    if (playerS == true) {
      if (digitalRead(ENTER) == LOW) {
        playerS = false;
        state = 2;
        delay(Bdelay);
      }
      else if (digitalRead(LEFT) == LOW) {
        if (players <= minplayers) {
          players = maxplayers + 1;
        }
        players--;
        delay(Bdelay);
      }
      else if (digitalRead(RIGHT) == LOW) {
        if (players >= maxplayers) {
          players = minplayers - 1;
        }
        players++;
        delay(Bdelay);
      }
      lcd.setCursor(0, 1);
      lcd.print("PLAYERS = "); //print number players
      lcd.print(players); //print number players
    }
  }
  //--------------------------------POKER-------------------------------------------
  else if (state == 2 && playerS == false) {
    if (stage == 1) {
      if (e == false) {
        lcd.clear();
        lcd.print("POKER!!");
        lcd.setCursor(0, 1);
        lcd.print("dealing...");
        e = true;
      }
      else if (e == true) { //deal 2 cards each
        for (i; i < (2 * players) - 1; i++) {
          S_deal();
          stepstoDo = TOTALSTEPS / players;
          S_tower_H();
          delay(Bdelay);
        }
        lcd.setCursor(0, 1);
        lcd.print("press ENTER");
        if ( digitalRead(ENTER) == LOW) {
          stage = 2;
          e = false;
          i = 0;
          delay(Bdelay);
        }
      }
    }
    else if (stage == 2) {
      if (e == false) {
        lcd.clear();
        lcd.setCursor(0, 1);
        lcd.print("dealing...");
        e = true;
      }
      for (i ; i < 1; i++) {
        S_deal(); //burn
        stepstoDo = TOTALSTEPS / 10;  //distance between positions
        S_tower_H();                   //move to position 1
        delay(Bdelay);
        S_deal(); //deal
        S_tower_H();                         //move to position 2
        delay(Bdelay);
        S_deal(); //deal
        S_tower_H();                         //move to position 3
        delay(Bdelay);
        S_deal(); //deal
        stepstoDo = 3 * TOTALSTEPS / 10;
        S_tower_A();                       //go back to burn area
        delay(Bdelay);
      }
      lcd.setCursor(0, 1);
      lcd.print("press ENTER");
      if ( digitalRead(ENTER) == LOW) {
        stage = 3;
        e = false;
        i = 0;
        delay(Bdelay);
      }
      //wait
    }
    else if (stage == 3) {
      if (e == false) {
        lcd.clear();
        lcd.print("dealing...");
        e = true;
      }
      for (i; i < 1; i++) {
        S_deal();       //burn
        stepstoDo = 4 * TOTALSTEPS / 10;
        S_tower_H();
        delay(Bdelay);
        S_deal();       //deal
        S_tower_A();
        delay(Bdelay);
      }
      lcd.setCursor(0, 1);
      lcd.print("press ENTER");
      if ( digitalRead(ENTER) == LOW) {
        stage = 4;
        e = false;
        i = 0;
        delay(Bdelay);
      }
      //burn 1
      //deal 1
      //wait
    }
    else if (stage == 4) {
      if (e == false) {
        lcd.clear();
        lcd.print("dealing...");
        e = true;
      }
      for (i; i < 1; i++) {
        S_deal();  //burn
        stepstoDo = 5 * TOTALSTEPS / 10;
        S_tower_H();                        //move to position 5
        delay(Bdelay);
        S_deal(); //deal
        S_tower_A();                       //go back to home area
        delay(Bdelay);
      }
      lcd.setCursor(0, 1);
      lcd.print("press ENTER");
      if ( digitalRead(ENTER) == LOW) {
        stage = 5;
        e = false;
        i = 0;
        delay(Bdelay);
      }
    }
    else if (stage == 5) {
      if (e == false) {
        lcd.clear();
        lcd.print("END OF GAME");
        e = true;
      }
      lcd.setCursor(0, 1);
      lcd.print("press ENTER");
      if ( digitalRead(ENTER) == LOW) {
        stage = 1;
        state = 1;
        e = false;
        delay(Bdelay);
      }
    }
  }
}

void S_deal() {
for (int d = 0; d <= TOTALSTEPS / 5; d = d + 4) {

int motorSpeed = 5; //variable to set stepper speed // 1 digitalWrite(motorPin4, HIGH); digitalWrite(motorPin3, LOW); digitalWrite(motorPin2, LOW); digitalWrite(motorPin1, LOW); delay(motorSpeed); // // 2 // digitalWrite(motorPin4, HIGH); // digitalWrite(motorPin3, HIGH); // digitalWrite(motorPin2, LOW); // digitalWrite(motorPin1, LOW); // delay (motorSpeed); // 3 digitalWrite(motorPin4, LOW); digitalWrite(motorPin3, HIGH); digitalWrite(motorPin2, LOW); digitalWrite(motorPin1, LOW); delay(motorSpeed); // // 4 // digitalWrite(motorPin4, LOW); // digitalWrite(motorPin3, HIGH); // digitalWrite(motorPin2, HIGH); // digitalWrite(motorPin1, LOW); // delay(motorSpeed); // 5 digitalWrite(motorPin4, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin2, HIGH); digitalWrite(motorPin1, LOW); delay(motorSpeed); // // 6 // digitalWrite(motorPin4, LOW); // digitalWrite(motorPin3, LOW); // digitalWrite(motorPin2, HIGH); // digitalWrite(motorPin1, HIGH); // delay (motorSpeed); // 7 digitalWrite(motorPin4, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin2, LOW); digitalWrite(motorPin1, HIGH); delay(motorSpeed); // // 8 // digitalWrite(motorPin4, HIGH); // digitalWrite(motorPin3, LOW); // digitalWrite(motorPin2, LOW); // digitalWrite(motorPin1, HIGH); // delay(motorSpeed); } delay(cardDelay); }

//declare variables for the motor pins

void S_tower_A() { for (int t = 0; t <= stepstoDo; t = t + 4) {

int motorSpeed = 5; //variable to set stepper speed // 1 digitalWrite(motorPin5, HIGH); digitalWrite(motorPin6, LOW); digitalWrite(motorPin7, LOW); digitalWrite(motorPin8, LOW); delay(motorSpeed); // // 2 // digitalWrite(motorPin5, HIGH); // digitalWrite(motorPin6, HIGH); // digitalWrite(motorPin7, LOW); // digitalWrite(motorPin8, LOW); // delay (motorSpeed); // 3 digitalWrite(motorPin5, LOW); digitalWrite(motorPin6, HIGH); digitalWrite(motorPin7, LOW); digitalWrite(motorPin8, LOW); delay(motorSpeed); // // 4 // digitalWrite(motorPin5, LOW); // digitalWrite(motorPin6, HIGH); // digitalWrite(motorPin7, HIGH); // digitalWrite(motorPin8, LOW); // delay(motorSpeed); // 5 digitalWrite(motorPin5, LOW); digitalWrite(motorPin6, LOW); digitalWrite(motorPin7, HIGH); digitalWrite(motorPin8, LOW); delay(motorSpeed); // // 6 // digitalWrite(motorPin5, LOW); // digitalWrite(motorPin6, LOW); // digitalWrite(motorPin7, HIGH); // digitalWrite(motorPin8, HIGH); // delay (motorSpeed); // 7 digitalWrite(motorPin5, LOW); digitalWrite(motorPin6, LOW); digitalWrite(motorPin7, LOW); digitalWrite(motorPin8, HIGH); delay(motorSpeed); // // 8 // digitalWrite(motorPin5, HIGH); // digitalWrite(motorPin6, LOW); // digitalWrite(motorPin7, LOW); // digitalWrite(motorPin8, HIGH); // delay(motorSpeed); } }

////////////////////////////////////////////////////////////////////////////// //set pins to ULN2003 high in sequence from 4 to 1 //delay "motorSpeed" between each pin setting (to determine speed)

void S_tower_H() {

for (int t = 0; t <= stepstoDo; t = t + 4) {

int motorSpeed = 5; //variable to set stepper speed // 1 digitalWrite(motorPin5, HIGH); digitalWrite(motorPin6, LOW); digitalWrite(motorPin7, LOW); digitalWrite(motorPin8, LOW); delay(motorSpeed); // // 2 // digitalWrite(motorPin5, HIGH); // digitalWrite(motorPin6, LOW); // digitalWrite(motorPin7, LOW); // digitalWrite(motorPin8, HIGH); // delay (motorSpeed); // 3 digitalWrite(motorPin5, LOW); digitalWrite(motorPin6, LOW); digitalWrite(motorPin7, LOW); digitalWrite(motorPin8, HIGH); delay(motorSpeed); // // 4 // digitalWrite(motorPin5, LOW); // digitalWrite(motorPin6, LOW); // digitalWrite(motorPin7, HIGH); // digitalWrite(motorPin8, HIGH); // delay(motorSpeed); // 5 digitalWrite(motorPin5, LOW); digitalWrite(motorPin6, LOW); digitalWrite(motorPin7, HIGH); digitalWrite(motorPin8, LOW); delay(motorSpeed); // // 6 // digitalWrite(motorPin5, LOW); // digitalWrite(motorPin6, HIGH); // digitalWrite(motorPin7, HIGH); // digitalWrite(motorPin8, LOW); // delay (motorSpeed); // 7 digitalWrite(motorPin5, LOW); digitalWrite(motorPin6, HIGH); digitalWrite(motorPin7, LOW); digitalWrite(motorPin8, LOW); delay(motorSpeed); // // 8 // digitalWrite(motorPin5, HIGH); // digitalWrite(motorPin6, HIGH); // digitalWrite(motorPin7, LOW); // digitalWrite(motorPin8, LOW); // delay(motorSpeed); } }

Step 4: Step 3 : Cut Your Wood and Pmma Boart

Picture of Step 3 : Cut Your Wood and Pmma Boart

Use the dwg. file attached.

(if you have acces to a laser cutter then its sooooo much easier)

Step 5: Step 4 : Assembly 1

Picture of Step 4 : Assembly 1

Step 6: Step 5 : Pain Your Case

Picture of Step 5 : Pain Your Case

Step 7: Step 6 : Assembly 2 (connect Your Circuit and Make It Fit)

Picture of Step 6 : Assembly 2 (connect Your Circuit and Make It Fit)

Step 8: Step 7 : Final Assembly

Picture of Step 7 : Final Assembly

Start playing!!

Comments

DIY Hacks and How Tos (author)2017-12-16

Great. If you don't trust your friends to deal, use a robot. The robot won't cheat anyone.

About This Instructable

484views

10favorites

License:

More by VicThorMaps:CARD DEALER
Add instructable to: