Project showcase

# Shut the Box Game + Automatic Probability Calculator! © GPL3+

Shut the Box Game enhanced with battery powered Arduino which automatically calculates your odds of a successful roll.

• 1,669 views
• 0 respects

## Components and supplies

 Arduino UNO
×1
 Alphanumeric LCD, 16 x 2
×1
×2
 9V Battery Clip
×1
 Resistor 10k ohm
×8
 Resistor 4.75k ohm
×4
 Resistor 22K ohm
×4
 Resistor 221 ohm
×1
 Reed Switch; SPST-NO
×12

## Necessary tools and machines

 Drill / Driver, Cordless

I added some tech to a traditional game: 'Shut the Box'. To understand the project, I should first explain 'Shut the Box’ game. The game is somewhat simple, roll 2 dice, and put down numbers, lowest total wins. Attached are the game rules which explain it better than I can..

I’ve done my best to add to the gaming experience by adding tech which automatically calculates your percent chance of successfully rolling. The idea started like most great ideas, while drinking an adult beverage. Some one said it would be cool if it was done and I said “why not”.

For this project I used an Arduino(microcontroller), 12 magnetic reed switches, some resistors, LCD screen, and a “few” hours coding. I started by installed reed switches in each number, wired them in series with specific resisters and connected them to the Arduino. As the numbers are put down, the reed switches are closed, the resistance “felt” by the Arduino increases (or decreases), and the numbers are counted as “shut” appropriately. The Arduino then runs the code I programed, based on the numbers which are shut, it displays your percent chance of successfully rolling (AKA not losing) on that roll.

## Code

##### SHUT_THE_BOX_GAME_FINAL.inoArduino
```#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5,4,3,2);
int Num1 = 0;
int Num2 = 0;
int Num3 = 0;
int Num4 = 0;
int Num5 = 0;
int Num6 = 0;
int Num7 = 0;
int Num8 = 0;
int Num9 = 0;
int Num10 = 0;
int Num11 = 0;
int Num12 = 0;
int NumTotal = 0;
int NumTotalInverse = 0;

int Num33=0;
int Num44=0;
int Num55=0;
int Num66=0;
int Num77=0;
int Num88=0;
int Num99=0;
int Num1010=0;
int Num1111=0;
int Num1212=0;

int Odds1=0;
int Odds2=0;
int Odds3=0;
int Odds4=0;
int Odds5=0;
int Odds6=0;
int Odds7=0;
int Odds8=0;
int Odds9=0;
int Odds10=0;
int Odds11=0;
int Odds12=0;

int Double2=0;
int Double4=0;
int Double6=0;
int Double8=0;
int Double10=0;
int Double12=0;
//-----------------------------
//const unsigned long period = 2000;
//int time_now = 0;
int switchState = 0;

//-----------------------------
int Odds = 36;
int OddsDouble = 36;
int prevOdds = 36;
int prevNumTotal = 0;
int Fraction1 = 0;
int Fraction2 = 0;
int FractionDouble1 = 0;
int FractionDouble2 = 0;
float Oddss = 0;
float dice = .36;
const unsigned long eventInterval1 = 4000;
unsigned long previousTime = 0;

void setup() {
pinMode(7,INPUT);
Serial.begin(9600);
lcd.begin(16,2);
lcd.print("  SHUT THE BOX");
lcd.setCursor(0,1);
lcd.print("  Good luck!");
}

void loop() {

Odds1=0;
Odds2=0;
Odds3=0;
Odds4=0;
Odds5=0;
Odds6=0;
Odds7=0;
Odds8=0;
Odds9=0;
Odds10=0;
Odds11=0;
Odds12=0;
Num1 = 0;
Num2 = 0;
Num3 = 0;
Num4 = 0;
Num5 = 0;
Num6 = 0;
Num7 = 0;
Num8 = 0;
Num9 = 0;
Num10 = 0;
Num11 = 0;
Num12 = 0;
Num33=0;
Num44=0;
Num55=0;
Num66=0;
Num77=0;
Num88=0;
Num99=0;
Num1010=0;
Num1111=0;
Num1212=0;
Double2=0;
Double4=0;
Double6=0;
Double8=0;
Double10=0;
Double12=0;
//unsigned long currentTime = millis();
prevOdds = Odds;
prevNumTotal = NumTotal;
//Serial.println(Val0);
//Serial.println(A00);
//*********************************************************************************************************************************************************************
if(Val0>=680&&Val0<=715){
Num1=1;
// 4.7 resistor - number 1
}
else if(Val0>=450&&Val0<=550){
Num2=2;
// 10 resistor - number 2
}
else if(Val0>=280&&Val0<=400){
Num3=3;
// 20 resistor - number 3
}
else if(Val0>=760&&Val0<=780){
Num1=1;
Num2=2;
// 4.7+10 resistor - numbers1+2
}
else if(Val0>=720&&Val0<=750){
Num1=1;
Num3=3;
// 4.7+20 resistor - numbers 1+3
}
else if(Val0>=580&&Val0<=630){
Num2=2;
Num3=3;
// 10+20 resistor - number 2+3
}
else if(Val0>=780&&Val0<=850){
Num1=1;
Num2=2;
Num3=3;
// 4.7+10+20 resistor - number 1+2+3
}
else{
Num1 = 0;
Num2 = 0;
Num3 = 0;
}
if(Val1>=680&&Val1<=715){
Num4=4;
// 4.7 resistor - number 4
}
else if(Val1>=450&&Val1<=550){
Num5=5;
// 10 resistor - number 5
}
else if(Val1>=280&&Val1<=400){
Num6=6;
// 10 resistor - number 6
}
else if(Val1>=760&&Val1<=780){
Num4=4;
Num5=5;
// 4.7+10 resistor - numbers 4+5
}
else if(Val1>=720&&Val1<=750){
Num4=4;
Num6=6;
// 4.7+20 resistor - numbers 4+6
}
else if(Val1>=580&&Val1<=630){
Num5=5;
Num6=6;
// 10+20 resistor - numbers 5+6
}
else if(Val1>=780&&Val1<=850){
Num4=4;
Num5=5;
Num6=6;
// 4.7+10+20 resistor - number 4+5+6
}
else{
Num4 = 0;
Num5 = 0;
Num6 = 0;
}
if(Val2>=680&&Val2<=715){
Num7=7;
// 4.7 resistor - number 7
}
else if(Val2>=450&&Val2<=550){
Num8=8;
// 10 resistor - number 8
}
else if(Val2>=280&&Val2<=400){
Num9=9;
// 20 resistor - number 9
}
else if(Val2>=760&&Val2<=780){
Num7=7;
Num8=8;
// 4.7+10 resistor - numbers 7+8
}
else if(Val2>=720&&Val2<=750){
Num7=7;
Num9=9;
// 4.7+20 resistor - numbers 7+9
}
else if(Val2>=580&&Val2<=630){
Num8=8;
Num9=9;
// 10+20 resistor - numbers 8+9
}
else if(Val2>=780&&Val2<=850){
Num7=7;
Num8=8;
Num9=9;
// 4.7+10+20 resistor - number 7+8+9
}
else{
Num7 = 0;
Num8 = 0;
Num9 = 0;
}
if(Val3>=680&&Val3<=715){
Num10=10;
// 4.7 resistor - number 10
}
else if(Val3>=450&&Val3<=550){
Num11=11;
// 10 resistor - number 11
}
else if(Val3>=280&&Val3<=400){
Num12=12;
// 20 resistor - number 12
}
else if(Val3>=760&&Val3<=780){
Num10=10;
Num11=11;
// 4.7+10 resistor - numbers 10+11
}
else if(Val3>=720&&Val3<=750){
Num10=10;
Num12=12;
// 4.7+20 resistor - numbers 10+12
}
else if(Val3>=580&&Val3<=630){
Num11=11;
Num12=12;
// 10+20 resistor - numbers 11+12
}
else if(Val3>=780&&Val3<=850){
Num10=10;
Num11=11;
Num12=12;
// 4.7+10+20 resistor - number 10+11+12
}
else{

Num10 = 0;
Num11 = 0;
Num12 = 0;
}
NumTotal=0;
NumTotal=Num1+Num2+Num3+Num4+Num5+Num6+Num7+Num8+Num9+Num10+Num11+Num12;
NumTotalInverse = 78-NumTotal;
//**********************************************************************************************************************************************************************
if(Num1==1 || Num2==2){
Num33=3;
}
if(Num1==1 || Num3==3){
Num44=4;
}
//
if((Num1==1 || Num4==4) && (Num2==2 || Num3==3)){
Num55=5;
}
//15-24
if((Num1==1 || Num5==5) && (Num2==2 || Num4==4)){
Num66=6;
}
//16-25-34-124
if((Num1==1 || Num6==6) && (Num2==2 || Num5==5) && (Num3==3 || Num4==4) && (Num1==1 || Num2==2 || Num4==4)){
Num77=7;
}
//17-26-35-125-134
if((Num1==1 || Num7==7) && (Num2==2 || Num6==6) && (Num3==3 || Num5==5) && (Num1==1 || Num2==2 || Num5==5) && (Num1==1 || Num3==3 || Num4==4)){
Num88=8;
}
//18-27-36-126-135-234
if((Num1==1 || Num8==8) && (Num2==2 || Num7==7) && (Num3==3 || Num6==6) && (Num4==4 || Num5==5) && (Num1==1 || Num2==2 || Num6==6) && (Num1==1 || Num3==3 || Num5==5) && (Num2==2 || Num3==3 || Num4==4)){
Num99=9;
}
//19-28-37-46-127-136-235-1234
if((Num1==1 || Num9==9) && (Num2==2 || Num8==8) && (Num3==3 || Num7==7) && (Num4==4 || Num6==6) && (Num1==1 || Num2==2 || Num7==7) && (Num1==1 || Num3==3 || Num6==6) && (Num2==2 || Num3==3 || Num5==5) && (Num1==1 || Num2==2 || Num3==3 || Num4==4)){
Num1010=10;
}
//110-29-38-47-56-128-137-146-236-245-1235
if((Num1==1 || Num10==10) && (Num2==2 || Num9==9) && (Num3==3 || Num8==8) && (Num4==4 || Num7==7) && (Num5==5 || Num6==6) && (Num1==1 || Num2==2 || Num8==8) && (Num1==1 || Num3==3 || Num7==7) && (Num1==1 || Num4==4 || Num6==6) && (Num2==2 || Num3==3 || Num6==6) && (Num2==2 || Num4==4 || Num5==5) && (Num1==1 || Num2==2 || Num3==3 || Num5==5)){
Num1111=11;
}
//111-210-39-48-57-129-138-147-156-237-246-345-1236
if((Num1==1 || Num11==11) && (Num2==2 || Num10==10) && (Num3==3 || Num9==9) && (Num4==4 || Num8==8) && (Num5==5 || Num7==7) && (Num1==1 || Num2==2 || Num9==9) && (Num1==1 || Num3==3 || Num8==8) && (Num1==1 || Num4==4 || Num7==7) && (Num1==1 || Num5==5 || Num6==6) && (Num2==2 || Num3==3 || Num7==7) && (Num2==2 || Num4==4 || Num6==6) && (Num3==3 || Num4==4 || Num5==5) && (Num1==1 || Num2==2 || Num3==3 || Num6==6)){
Num1212=12;
}
//**********************************************************************************************************************************************************************
Odds1=0;
if(Num2==2){
Odds2=1;
}
if(Num3==3 && Num33==3){
Odds3=2;
}
if(Num4==4 && Num44==4){
Odds4=3;
}
if(Num5==5 && Num55==5){
Odds5=4;
}
if(Num6==6 && Num66==6){
Odds6=5;
}
if(Num7==7 && Num77==7){
Odds7=6;
}
if(Num8==8 && Num88==8){
Odds8=5;
}
if(Num9==9 && Num99==9){
Odds9=4;
}
if(Num10==10 && Num1010==10){
Odds10=3;
}
if(Num11==11 && Num1111==11){
Odds11=2;
}
if(Num12==12 && Num1212==12){
Odds12=1;
}
//**********************************************************************************************************************************************************************
if(Num2==2){
Double2=1;
}
if(Num4==4 && Num44==4){
Double4=1;
}
if(Num6==6 && Num66==6){
Double6=1;
}
if(Num8==8 && Num88==8){
Double8=1;
}
if(Num10==10 && Num1010==10){
Double10=1;
}
if(Num12==12 && Num1212==12){
Double12=1;
}
//**********************************************************************************************************************************************************************
Odds = (36-(Odds1+Odds2+Odds3+Odds4+Odds5+Odds6+Odds7+Odds8+Odds9+Odds10+Odds11+Odds12));

OddsDouble = (36+(Double2+Double4+Double6+Double8+Double10+Double12)-(Odds1+Odds2+Odds3+Odds4+Odds5+Odds6+Odds7+Odds8+Odds9+Odds10+Odds11+Odds12));

//**********************************************************************************************************************************************************************
if(Odds==2){
Fraction1=1;
Fraction2=18;
}
else if(Odds==3){
Fraction1=1;
Fraction2=12;
}
else if(Odds==4){
Fraction1=1;
Fraction2=9;
}
else if(Odds==6){
Fraction1=1;
Fraction2=6;
}
else if(Odds==8){
Fraction1=2;
Fraction2=9;
}
else if(Odds==9){
Fraction1=1;
Fraction2=4;
}
else if(Odds==10){
Fraction1=5;
Fraction2=18;
}
else if(Odds==12){
Fraction1=1;
Fraction2=3;
}
else if(Odds==14){
Fraction1=7;
Fraction2=18;
}
else if(Odds==15){
Fraction1=5;
Fraction2=12;
}
else if(Odds==16){
Fraction1=4;
Fraction2=9;
}
else if(Odds==18){
Fraction1=1;
Fraction2=2;
}
else if(Odds==20){
Fraction1=5;
Fraction2=9;
}
else if(Odds==21){
Fraction1=7;
Fraction2=12;
}
else if(Odds==22){
Fraction1=11;
Fraction2=18;
}
else if(Odds==24){
Fraction1=2;
Fraction2=3;
}
else if(Odds==26){
Fraction1=13;
Fraction2=18;
}
else if(Odds==27){
Fraction1=3;
Fraction2=4;
}
else if(Odds==28){
Fraction1=7;
Fraction2=9;
}
else if(Odds==30){
Fraction1=5;
Fraction2=6;
}
else if(Odds==32){
Fraction1=8;
Fraction2=9;
}
else if(Odds==33){
Fraction1=11;
Fraction2=12;
}
else if(Odds==34){
Fraction1=17;
Fraction2=18;
}
else{
Fraction1=0;
Fraction2=0;
}
//**********************************************************************************************************************************************************************
if(OddsDouble==2){
FractionDouble1=1;
FractionDouble2=18;
}
else if(OddsDouble==3){
FractionDouble1=1;
FractionDouble2=12;
}
else if(OddsDouble==4){
FractionDouble1=1;
FractionDouble2=9;
}
else if(OddsDouble==6){
FractionDouble1=1;
FractionDouble2=6;
}
else if(OddsDouble==8){
FractionDouble1=2;
FractionDouble2=9;
}
else if(OddsDouble==9){
FractionDouble1=1;
FractionDouble2=4;
}
else if(OddsDouble==10){
FractionDouble1=5;
FractionDouble2=18;
}
else if(OddsDouble==12){
FractionDouble1=1;
FractionDouble2=3;
}
else if(OddsDouble==14){
FractionDouble1=7;
FractionDouble2=18;
}
else if(OddsDouble==15){
FractionDouble1=5;
FractionDouble2=12;
}
else if(OddsDouble==16){
FractionDouble1=4;
FractionDouble2=9;
}
else if(OddsDouble==18){
FractionDouble1=1;
FractionDouble2=2;
}
else if(OddsDouble==20){
FractionDouble1=5;
FractionDouble2=9;
}
else if(OddsDouble==21){
FractionDouble1=7;
FractionDouble2=12;
}
else if(OddsDouble==22){
FractionDouble1=11;
FractionDouble2=18;
}
else if(OddsDouble==24){
FractionDouble1=2;
FractionDouble2=3;
}
else if(OddsDouble==26){
FractionDouble1=13;
FractionDouble2=18;
}
else if(OddsDouble==27){
FractionDouble1=3;
FractionDouble2=4;
}
else if(OddsDouble==28){
FractionDouble1=7;
FractionDouble2=9;
}
else if(OddsDouble==30){
FractionDouble1=5;
FractionDouble2=6;
}
else if(OddsDouble==32){
FractionDouble1=8;
FractionDouble2=9;
}
else if(OddsDouble==33){
FractionDouble1=11;
FractionDouble2=12;
}
else if(OddsDouble==34){
FractionDouble1=17;
FractionDouble2=18;
}
else{
FractionDouble1=0;
FractionDouble2=0;
}
//**********************************************************************************************************************************************************************
if (switchState == HIGH) {
lcd.setCursor(0,1);
lcd.print(NumTotalInverse);
}
if (switchState ==  LOW){
lcd.setCursor(0,1);
lcd.print("  ");
}
//**********************************************************************************************************************************************************************
if (NumTotal != prevNumTotal ){
if (NumTotal == 0){
lcd.begin(16,2);
lcd.print("  SHUT THE BOX");
lcd.setCursor(0,1);
lcd.print("  Good luck!");
}
else if (NumTotal == 78){
lcd.begin(16,2);
lcd.print("    YOU SHUT");
lcd.setCursor(0,1);
lcd.print("    THE BOX!");
}
else{
lcd.begin(16,2);
lcd.print("Odds:");

if (Fraction1 >= 1){
lcd.print(Fraction1);
lcd.print("/");
lcd.print(Fraction2);
float Oddss = (Odds/dice);
lcd.setCursor(11,0);
lcd.print(Oddss,0);
lcd.print("%");
}
else {
lcd.print(Odds);
lcd.print("/36");
float Oddss = (Odds/dice);
lcd.setCursor(11,0);
lcd.print(Oddss,0);
lcd.print("%");
}

if (FractionDouble1 >= 1){
lcd.setCursor(5,1);
lcd.print(FractionDouble1);
lcd.print("/");
lcd.print(FractionDouble2);
float Oddss = (OddsDouble/dice);
lcd.setCursor(11,1);
lcd.print(Oddss,0);
lcd.print("%");
}
else {
lcd.setCursor(5,1);
lcd.print(OddsDouble);
lcd.print("/36");
float Oddss = (OddsDouble/dice);
lcd.setCursor(11,1);
lcd.print(Oddss,0);
lcd.print("%");
}

}
}

}
```

## Schematics

• 1 project
• 0 followers

#### Published on

April 18, 2020
See similar projects
you might like

#### Drinking Game for the Brave

Project showcase by jdmgolf123

• 4,631 views
• 20 respects

#### LX' Arduino Tetris

Project showcase by RomanSixty

• 20,856 views
• 58 respects

#### Arduino Pocket Game Console + A-Maze - Maze Game

Project tutorial by Alojz Jakob

• 19,551 views
• 47 respects

#### Arduino Dot Matrix Game Console

Project tutorial by Md. Khairul Alam

• 16,087 views
• 40 respects

#### Arduino Game Controller

Project tutorial by Arnov Sharma and Elektro Punkz

• 11,736 views