//screen is 1600 by 1280
#include <TFT.h>
#include <SPI.h>
#include <Encoder.h> //include Encoder library
#include "BasicStepperDriver.h" //include the Arduino & BasicStepper Driver libraries
#define fullrot 200
#define RPM 120
#define DIR 5
#define STEP 6
#define MICRO_STEPS 1
//define stepper motor constants
BasicStepperDriver stepper(fullrot, DIR, STEP); //define the BasicStepperDriver library as stepper and set the parameters for a full rotation, and the direction and step wires
#define cs 10
#define dc 9
#define rst 8
//define tft constants
int Switch = 4; //set int Switch = 4
int stage = 1;
const int spinstage = 20;
const int bettingstage = 25;
const int tilelength = 10;
const int tileheight = 42;
const int tilelengthln = 11;
const int tileheightln = 43;
int none = 999;
const int insideboardlength = 133;
const int thefinal = 3234;
int wheelnumber;
int currentdigit = 0;
int buttonState;
int currentround = 1;
long payout = 0;
//misc constants
Encoder Enc(3, 2);
TFT screen = TFT(cs, dc, rst);
//enable encoder and screen
void setup() {
pinMode(Switch, INPUT_PULLUP);
pinMode(5,OUTPUT);
pinMode(A0,INPUT);
stepper.begin(RPM,MICRO_STEPS);
screen.begin();
screen.background(255, 255, 255);
screen.stroke(0, 0, 0);
screen.setTextSize(2);
Serial.begin(9600);
//set up pins, stepper, and tft screen
}
long oldPosition = -999;
int oldcoordpos = -999;
//initiate encoder values
struct Coordinate {
int x;
int y;
};
struct bettingstoragestruct {
int cent;
int one;
int ten;
int hun;
int tho;
int tot;
};
struct wagerstoragestruct { //0 is 37 and 00 is 38
int multiplier;
int num1;
int num2;
int num3;
int num4;
int num5;
int num6;
int row;
int half;
int third;
int colour;
int oddoreven;
};
//establish structs
wagerstoragestruct wagerstorage[10];
bettingstoragestruct bettingstorage[10];
Coordinate insidenumcoords[38];
int rouletteconversion[] = {38, 35, 27, 10, 25, 29, 12, 8, 19, 31, 18, 6, 21, 33, 16, 4, 23, 14, 2, 37, 28, 9, 26, 30, 11, 7, 20, 32, 17, 5, 22, 34, 15, 3, 24, 36, 13, 1};
//create arrays using structs
void loop() {
buttonState = digitalRead(Switch); //read encoder switch
if (stage == 1) {
stage1();
}
if (stage == 2) {
stage2();
}
if (stage == 3) {
stage3();
}
if (stage == 4) {
stage4();
}
if (stage == 5) {
stage5();
}
if (stage == 6) {
stage6();
}
if (stage == 7) {
stage7();
}
if (stage == 8) {
stage8();
}
if (stage == 9) {
stage9();
}
if (stage == 10) {
stage10();
}
if (stage == 11) {
stage11();
}
if (stage == spinstage) {
spin();
}
if (stage == bettingstage) {
betting();
}
if (stage == thefinal) {
finalstage();
}
//check for each stage
}
int encoderBounds(int upperbound) { //Encoder bounds function, used for encoder input
long newPosition = Enc.read(); //set a var newPosition of type long to the output from the encoder
newPosition = newPosition/4; //divide newPosition by 4
if (newPosition != oldPosition) { //If newPosition doesn't equal oldPosition:
oldPosition = newPosition; //set oldPosition to newPosition
if (newPosition > upperbound){
Enc.write(0);
newPosition = 0;
} //if encoder pos is higher than bound passed to function, return to zero
if (newPosition < 0){
Enc.write(upperbound * 4);
newPosition = upperbound;
} //if encoder pos is lower than zero, return to passed upper bound
}
return newPosition; //return current encoder position
}
void drawinsideboard() { //function to draw the inside board
insidenumcoords[0] = {16,2*tileheightln};
insidenumcoords[1] = {16,tileheightln};
insidenumcoords[2] = {16,0};
for (int a=3;a<36;a+=3) {
insidenumcoords[a] = {16+tilelengthln*(a/3),2*tileheightln};
insidenumcoords[a+1] = {16+tilelengthln*(a/3),tileheightln};
insidenumcoords[a+2] = {16+tilelengthln*(a/3),0};
}
insidenumcoords[36] = {0,0};
insidenumcoords[37] = {0,64};
//create cooridnates for all numbers on the board
screen.background(1,102,0); //make whole background green
screen.stroke(0,0,0);
screen.fill(0,0,0);
screen.rect(15,0,120,128); //create black rectangle where the numbers 1-36 would be (inside board)
for (int i=0; i<=12; i++) {
screen.stroke(255,255,255);
screen.line(15+(tilelengthln*i),0,15+(tilelengthln*i),128);
} //draw vertical lines on inside board
screen.stroke(255,255,255);
screen.line(15,tileheight,160,tileheight);
screen.line(15,1+(tileheight*2),160,1+(tileheight*2));
//draw horizontal lines on inside board
for (int i=0;i<36;i++) {
if (i % 2 == 0) {
screen.noStroke();
screen.fill(36, 36, 236);
screen.rect(insidenumcoords[i].x,insidenumcoords[i].y,tilelength,tileheight);
} //draw black rectangles on even numbered coordinates
else {
screen.noStroke();
screen.fill(0, 0, 0);
screen.rect(insidenumcoords[i].x,insidenumcoords[i].y,tilelength,tileheight);
} //draw red rectangles on odd numbered coordinates
char drawnumt[5];
char drawnum[5];
if ((i+1) < 10) { //write numbers 1-9
sprintf(drawnum, "%d", i+1);
screen.stroke(255,255,255);
screen.text(drawnum,insidenumcoords[i].x+2,insidenumcoords[i].y+18);
} else { //write numbers 10-36
sprintf(drawnum, "%d",((i+1)-((i+1) % 10))/10);
sprintf(drawnumt, "%d",(i+1) % 10);
screen.stroke(255,255,255);
screen.text(drawnum,insidenumcoords[i].x+2,insidenumcoords[i].y+12);
screen.text(drawnumt,insidenumcoords[i].x+2,insidenumcoords[i].y+21);
}
}
screen.stroke(255,255,255);
screen.text("0",2,32);
screen.text("00",2,96);
screen.line(0,64,15,64);
screen.text("2",31+(tilelengthln*11),9);
screen.text("|",31+(tilelengthln*11),9+8);
screen.text("1",31+(tilelengthln*11),9+16);
screen.text("2",31+(tilelengthln*11),9+tileheightln);
screen.text("|",31+(tilelengthln*11),17+tileheightln);
screen.text("1",31+(tilelengthln*11),25+tileheightln);
screen.text("2",31+(tilelengthln*11),9+tileheightln*2);
screen.text("|",31+(tilelengthln*11),17+tileheightln*2);
screen.text("1",31+(tilelengthln*11),25+tileheightln*2);
//write the 0, 00, and 2-1 numbers on the board
}
void stageprogress(int stagein) { //function to progress the stage
buttonState = digitalRead(Switch); //Read the Button's state
if (buttonState == LOW) { //If button is pressed
stage = stagein; //set stage to passed int
oldcoordpos = -999;
while (!digitalRead(Switch)) //until the switch is let go:
{
stage = stagein;
Enc.write(0); //reset encoder to zero
delay(100);
oldcoordpos = -999;
screen.background(255,255,255); //make screen white
}
}
}
void stage1() { //welcome scene
screen.stroke(0,0,0);
screen.setTextSize(2);
screen.text("Welcome", 40, 56);
screen.setTextSize(1);
screen.text("press to continue", 30, 86);
screen.text("rotate to move", 40, 96);
//Read the button state
stageprogress(2);
}
void stage2() { //Place Bets or Spin Wheel Scene
int stage2coordin = encoderBounds(1);
//set upper bound to 1
screen.noFill();
if (oldcoordpos != stage2coordin) {
Coordinate stage2coords[10];
stage2coords[0] = {20,96};
stage2coords[1] = {110,96};
//coordinates for the "Bet" & "Spin Text"
screen.background(255,255,255);
screen.setTextSize(2);
screen.text("Place (More) \n Bet(s)?", 10, 32);
screen.text("Bet",stage2coords[0].x,stage2coords[0].y);
screen.text("Spin",stage2coords[1].x,stage2coords[1].y);
//Serial.println(stage2coordin);
screen.rect(stage2coords[stage2coordin].x, stage2coords[stage2coordin].y,35, 17);
//draw a rect at given coords based on encoder pos
oldcoordpos = stage2coordin;
}
if (stage2coordin == 0) {
stageprogress(3);
//go to next scene if "Bet"
}
else if (stage2coordin == 1) {
stageprogress(spinstage);
//go straight to spin if "Spin"
}
}
void stage3() { //choose between betting on the inside board or the outside board
int stage3coordin = encoderBounds(1); //set upper bound to 1
if (oldcoordpos != stage3coordin) {
Coordinate stage3coords[10];
stage3coords[0] = {30,37};
stage3coords[1] = {30,67};
screen.background(255,255,255);
screen.setTextSize(1);
screen.text("Inside Bet",stage3coords[0].x,stage3coords[0].y);
screen.text("Outside Bet",stage3coords[1].x,stage3coords[1].y);
screen.rect(stage3coords[stage3coordin].x-3, stage3coords[stage3coordin].y-2, 70, 16);
oldcoordpos = stage3coordin;
//same idea as previous stage
}
if (stage3coordin == 0) {
stageprogress(4);
//progress to inside board selection stage
}
else if (stage3coordin == 1) {
stageprogress(5);
//progress to outside board stage
}
}
void stage4() { //inside board bet selection stage
int stage4coordin = encoderBounds(5);
if (oldcoordpos != stage4coordin) {
Coordinate stage4coords[10];
stage4coords[0] = {30,17};
stage4coords[1] = {30,37};
stage4coords[2] = {30,57};
stage4coords[3] = {30,77};
stage4coords[4] = {30,97};
stage4coords[5] = {30,117};
//6 different coords for 6 different types of bets
screen.background(255,255,255);
screen.setTextSize(1);
screen.text("Straight Bet",stage4coords[0].x,stage4coords[0].y);
screen.text("Split Bet",stage4coords[1].x,stage4coords[1].y);
screen.text("Street Bet",stage4coords[2].x,stage4coords[2].y);
screen.text("Corner Bet",stage4coords[3].x,stage4coords[3].y);
screen.text("Six-Line Bet",stage4coords[4].x,stage4coords[4].y);
screen.text("Column Bet",stage4coords[5].x,stage4coords[5].y);
//Serial.println(stage4coordin);
screen.rect(stage4coords[stage4coordin].x, stage4coords[stage4coordin].y, 60, 17);
oldcoordpos = stage4coordin;
}
if (stage4coordin == 0) {
stageprogress(6); //straight bet
}
else if (stage4coordin == 1) {
stageprogress(7); //split bet
}
else if (stage4coordin == 2) {
stageprogress(8); //street bet
}
else if (stage4coordin == 3) {
stageprogress(9); //corner bet
}
else if (stage4coordin == 4) {
stageprogress(10); //six-line bet
}
else if (stage4coordin == 5) {
stageprogress(11); //row bet
}
}
void stage5() { //outside board bet stage
Coordinate stage5coords[10];
for (int i=0;i<3;i++) {
stage5coords[i] = {53*i,0};
}
for (int i=3;i<9;i++) {
stage5coords[i] = {27*(i-3),64};
}
//create coords for outside betting
int stage5coordin = encoderBounds(8);
if (oldcoordpos != stage5coordin) {
screen.background(1,102,0);
screen.fill(36,36,236);
screen.noStroke();
screen.rect(53,64,28,128);
screen.fill(0,0,0);
screen.rect(81,64,26,128);
screen.noFill();
screen.stroke(255,255,255);
screen.rect(0,0,screen.width(),screen.height());
screen.line(53,0,53,128);
screen.line(106,0,106,128);
screen.line(0,64,160,64);
for (int i=0;i<3;i++) {
screen.line(27+(54*i),64,27+(54*i),128);
}
screen.line(80,64,80,128);
screen.stroke(255,255,255);
screen.text("1st 12",stage5coords[0].x+10,stage5coords[0].y+15);
screen.text("2nd 12",stage5coords[1].x+10,stage5coords[1].y+15);
screen.text("3rd 12",stage5coords[2].x+10,stage5coords[2].y+15);
screen.text("1-18",stage5coords[3].x+2,stage5coords[3].y+15);
screen.text("Even",stage5coords[4].x+2,stage5coords[4].y+15);
screen.text("Red",stage5coords[5].x+5,stage5coords[5].y+15);
screen.text("Blk",stage5coords[6].x+5,stage5coords[6].y+15);
screen.text("Odd",stage5coords[7].x+5,stage5coords[7].y+15);
screen.text("19-\n 36",stage5coords[8].x+5,stage5coords[8].y+15);
//draw the ouside board
if (stage5coordin < 3) {
screen.fill(250,206,135);
screen.circle(stage5coords[stage5coordin].x+26,stage5coords[stage5coordin].y+32,5);
//place betting token in top row
}
else if (stage5coordin > 2) {
screen.fill(250,206,135);
screen.circle(stage5coords[stage5coordin].x+13,stage5coords[stage5coordin].y+32,5);
//place betting token in bottom row
}
oldcoordpos = stage5coordin;
}
if (buttonState == LOW) {
if (stage5coordin < 3){ //if bet on which third of the board
wagerstorage[currentround] = {2,none,none,none,none,none,none,none,none,stage5coordin+1,none,none};
}
else if (stage5coordin == 3 || stage5coordin == 8) { //if bet on which half of the board
if (stage5coordin % 2 == 0) {
wagerstorage[currentround] = {1,none,none,none,none,none,none,none,1,none,none,none};
}
else {
wagerstorage[currentround] = {1,none,none,none,none,none,none,none,0,none,none,none};
}
}
else if (stage5coordin == 4 || stage5coordin == 7) { //if bet on odd or even
if (stage5coordin % 2 == 0) {
wagerstorage[currentround] = {1,none,none,none,none,none,none,none,none,none,none,0};
}
else {
wagerstorage[currentround] = {1,none,none,none,none,none,none,none,none,none,none,1};
}
}
else if (stage5coordin == 5 || stage5coordin == 6) { //if bet on red or black
if (stage5coordin % 2 == 0) {
wagerstorage[currentround] = {1,none,none,none,none,none,none,none,none,none,0,none};
}
else {
wagerstorage[currentround] = {1,none,none,none,none,none,none,none,none,none,1,none};
}
}
stageprogress(bettingstage); //go to betting stage
}
}
void stage6() { //straight bet
int stage6coordin = encoderBounds(37);
if (oldcoordpos != stage6coordin) {
drawinsideboard();
screen.stroke(255,255,255);
screen.fill(250,206,135);
if (stage6coordin == 36 || stage6coordin == 37) { //draw betting token on 0 and 00
screen.circle(insidenumcoords[stage6coordin].x+7,insidenumcoords[stage6coordin].y+32,4);
}
else { //draw betting token on rest of the board
screen.circle(insidenumcoords[stage6coordin].x+(tilelength/2),insidenumcoords[stage6coordin].y+(tileheight/2),4);
}
oldcoordpos = stage6coordin;
}
if (buttonState == LOW) { //on button press
wagerstorage[currentround] = {35,stage6coordin+1,none,none,none,none,none,none,none,none,none,none};
stageprogress(bettingstage); //go to betting stage
}
}
void stage7() { //split bet
int stage7coordin = encoderBounds(57);
if (oldcoordpos != stage7coordin) {
drawinsideboard();
screen.stroke(255,255,255);
screen.fill(250,206,135);
if (stage7coordin<=23 && stage7coordin % 2 == 0){ //place token between middle & bottom row in selected column
screen.circle(tilelengthln*(stage7coordin/2)+20,2*tileheightln,4);
}
else if (stage7coordin<=23 && stage7coordin % 2 == 1) { //place token between middle & top row in selected column
screen.circle((tilelengthln*(stage7coordin-1)/2)+20,tileheightln,4);
}
else if (stage7coordin == 24) { //place token between 0 & 00
screen.circle(5,64,4);
}
else if (stage7coordin>=25 && stage7coordin<=35) { //place token between selected columns in bottom row
screen.circle((tilelengthln*((stage7coordin-24)))+15,(tileheight/2)+2*tileheightln,4);
}
else if (stage7coordin>=36 && stage7coordin<=46) { //place token between selected columns in middle row
screen.circle((tilelengthln*((stage7coordin-35)))+15,(tileheight/2)+tileheightln,4);
}
else if (stage7coordin>=47 && stage7coordin<=57) { //place token between selected columns in top row
screen.circle((tilelengthln*((stage7coordin-46)))+15,(tileheight/2),4);
}
oldcoordpos = stage7coordin;
}
if (buttonState == LOW) {
//see earlier if statements for what each of these corresponds to
if (stage7coordin<=23 && stage7coordin % 2 == 0){
wagerstorage[currentround] = {17,1+(3*stage7coordin)/2,2+(3*stage7coordin)/2,none,none,none,none,none,none,none,none,none};
}
else if (stage7coordin<=23 && stage7coordin % 2 == 1){
wagerstorage[currentround] = {17,((3*stage7coordin)+1)/2,1+((3*stage7coordin)+1)/2,none,none,none,none,none,none,none,none,none};
}
else if (stage7coordin == 24) {
wagerstorage[currentround] = {17,37,38,none,none,none,none,none,none,none,none,none};
}
else if (stage7coordin>=25 && stage7coordin<=35) {
wagerstorage[currentround] = {17,(3*stage7coordin)-74,(3*stage7coordin)-71,none,none,none,none,none,none,none,none,none};
}
else if (stage7coordin>=36 && stage7coordin<=46) {
wagerstorage[currentround] = {17,(3*stage7coordin)-106,(3*stage7coordin)-106,none,none,none,none,none,none,none,none,none};
}
else if (stage7coordin>=47 && stage7coordin<=57) {
wagerstorage[currentround] = {17,(3*stage7coordin)-138,(3*stage7coordin)-138,none,none,none,none,none,none,none,none,none};
}
stageprogress(bettingstage);
}
}
void stage8() { //street bet
int stage8coordin = encoderBounds(11);
if (oldcoordpos != stage8coordin) {
drawinsideboard();
screen.stroke(255,255,255);
screen.fill(250,206,135);
screen.circle(15+(tilelength/2)+(tilelengthln*stage8coordin),4,4); //place betting token at top of selected column
oldcoordpos = stage8coordin;
}
if (buttonState == LOW) {
wagerstorage[currentround] = {11,(3*stage8coordin)-2,(3*stage8coordin)-1,(3*stage8coordin),none,none,none,none,none,none,none,none};
stageprogress(bettingstage);
}
}
void stage9() { //corner bet
int stage9coordin = encoderBounds(22);
if (oldcoordpos != stage9coordin) {
drawinsideboard();
screen.stroke(255,255,255);
screen.fill(250,206,135);
if (stage9coordin<=21 && stage9coordin % 2 == 0){ //place token at corner of selected tiles on bottom row
screen.circle((tilelengthln*(stage9coordin/2))+26,(2*tileheightln)-1,4);
}
else if (stage9coordin<=21 && stage9coordin % 2 == 1) { //place token at corner of selected tiles on top row
screen.circle((tilelengthln*(stage9coordin-1)/2)+26,(tileheightln)-1,4);
}
else if (stage9coordin == 22) { //place token at corner of 0,00,1,2,3
screen.circle(16,64,4);
}
oldcoordpos = stage9coordin;
}
if (buttonState == LOW) {
if (stage9coordin<=21 && stage9coordin % 2 == 0){ //if bottom row
wagerstorage[currentround] = {8,1+(3*stage9coordin)/2,2+(3*stage9coordin)/2,4+(3*stage9coordin)/2,5+(3*stage9coordin)/2,none,none,none,none,none,none,none};
}
else if (stage9coordin<=21 && stage9coordin % 2 == 1){ //if top row
wagerstorage[currentround] = {8,((3*stage9coordin)+1)/2,1+((3*stage9coordin)+1)/2,3+((3*stage9coordin)+1)/2,4+((3*stage9coordin)+1)/2,none,none,none,none,none,none,none};
}
else if (stage9coordin == 22) { //if 0,00,1,2,3
wagerstorage[currentround] = {6,1,2,3,37,38,none,none,none,none,none,none};
}
stageprogress(bettingstage);
}
}
void stage10() { //six-line bet
int stage10coordin = encoderBounds(10);
if (oldcoordpos != stage10coordin) {
drawinsideboard();
screen.stroke(255,255,255);
screen.fill(250,206,135);
screen.circle(15+(tilelengthln)+(tilelengthln*stage10coordin),4,4); //place token at intersection of two columns at the top? (idk how to explain)
oldcoordpos = stage10coordin;
}
if (buttonState == LOW) {
wagerstorage[currentround] = {5,(3*stage10coordin)+1,(3*stage10coordin)+2,(3*stage10coordin)+3,(3*stage10coordin)+4,(3*stage10coordin)+5,(3*stage10coordin)+6,none,none,none,none,none};
stageprogress(bettingstage);
}
}
void stage11() { //row bet
int stage11coordin = encoderBounds(2);
if (oldcoordpos != stage11coordin) {
drawinsideboard();
screen.stroke(255,255,255);
screen.fill(250,206,135);
screen.circle(160-6,(tileheightln/2)+(tileheightln*stage11coordin),4); //place token on 2-1 indicating rows
oldcoordpos = stage11coordin;
}
if (buttonState == LOW) {
wagerstorage[currentround] = {2,none,none,none,none,none,stage11coordin+1,none,none,none,none};
stageprogress(bettingstage);
}
}
void betting() { //betting stage
int bettingval;
if (currentdigit == 0) {
bettingval = encoderBounds(99); //set upper bound to 99 if currently modifying cents place
}
else if (currentdigit != 0) {
bettingval = encoderBounds(9); //set upper bound to 9 otherwise
}
buttonState = digitalRead(Switch); //Read the Button's state
Coordinate digitcoords[10];
digitcoords[4] = {40,57};
digitcoords[3] = {60,57};
digitcoords[2] = {80,57};
digitcoords[1] = {100,57};
digitcoords[0] = {125,57};
//create coordinates for digits
if (oldcoordpos != bettingval) {
screen.background(255,255,255);
screen.stroke(0,0,0);
screen.setTextSize(2);
screen.text("$",20,57);
screen.text("_",digitcoords[4].x,digitcoords[4].y);
screen.text("_",digitcoords[3].x,digitcoords[3].y);
screen.text("_",digitcoords[2].x,digitcoords[2].y);
screen.text("_.",digitcoords[1].x,digitcoords[1].y);
screen.text("__",digitcoords[0].x,digitcoords[0].y);
//print blank digits
if (currentdigit > 0) {
int displaycent = bettingstorage[currentround].cent;
char centval[15];
int textlength = sprintf(centval,"%02d",displaycent);
screen.text(centval,digitcoords[0].x,digitcoords[0].y-5);
}
if (currentdigit > 1) {
int displayone = bettingstorage[currentround].one;
char oneval[15];
int textlength = sprintf(oneval,"%1d",displayone);
screen.text(oneval,digitcoords[1].x,digitcoords[1].y-5);
}
if (currentdigit > 2) {
int displayten = bettingstorage[currentround].ten;
char tenval[15];
int textlength = sprintf(tenval,"%1d",displayten);
screen.text(tenval,digitcoords[2].x,digitcoords[2].y-5);
}
if (currentdigit > 3) {
int displayhun = bettingstorage[currentround].hun;
char hunval[15];
int textlength = sprintf(hunval,"%1d",displayhun);
screen.text(hunval,digitcoords[3].x,digitcoords[3].y-5);
}
//above if statements are for printing previously inputted digits
char textinval[15];
if (currentdigit == 0) {
int textlength = sprintf(textinval, "%02d", bettingval);
screen.text(textinval,digitcoords[currentdigit].x,digitcoords[currentdigit].y-5);
oldcoordpos = bettingval;
//print digit being modified in cents place
}
else {
int textlength = sprintf(textinval, "%1d", bettingval);
screen.text(textinval,digitcoords[currentdigit].x,digitcoords[currentdigit].y-5);
oldcoordpos = bettingval;
//print digit being modified otherwise
}
}
if (buttonState == LOW && currentdigit != 4) { //If button is pressed
if (currentdigit == 0) {
bettingstorage[currentround].cent = bettingval;
}
if (currentdigit == 1) {
bettingstorage[currentround].one = bettingval;
}
if (currentdigit == 2) {
bettingstorage[currentround].ten = bettingval;
}
if (currentdigit == 3) {
bettingstorage[currentround].hun = bettingval;
}
currentdigit += 1;
Enc.write(0);
//Serial.println(currentdigit);
while (!digitalRead(Switch)) //until the switch is let go:
{
delay(100);
oldcoordpos = -999;
Enc.write(0);
}
//on button press, store value selected and reset encoder
}
else if (buttonState == LOW && currentdigit == 4) {
bettingstorage[currentround].tho = bettingval;
bettingstorage[currentround].tot = (bettingstorage[currentround].tho * 1000) + (bettingstorage[currentround].hun * 100) + (bettingstorage[currentround].ten * 10) + (bettingstorage[currentround].one * 1) + (bettingstorage[currentround].cent * 0.01);
Serial.println(wagerstorage[currentround].num1);
Serial.println(wagerstorage[currentround].num2);
Serial.println(wagerstorage[currentround].num3);
Serial.println(wagerstorage[currentround].num4);
Serial.println(wagerstorage[currentround].num5);
Serial.println(wagerstorage[currentround].num6);
Serial.println(wagerstorage[currentround].oddoreven);
Serial.println(wagerstorage[currentround].half);
Serial.println(wagerstorage[currentround].colour);
Serial.println(wagerstorage[currentround].third);
currentround++;
stageprogress(2);
currentdigit = 0;
//if thousands place has been inputted, calculate total and store it, then go back to stage 2
}
}
void spin() { //stage to spin the wheel
screen.stroke(0,0,0);
screen.text("Spinning...",30,50);
randomSeed((analogRead(A0)*currentround+none)); //set random seed to whatever the A0 pin picks up multiplied by the current round added to an arbitrary constant
wheelnumber = random(0,38); //random number from 1-38, 37 is 0 and 38 is 00
int wheelrotval = (wheelnumber * 360)/38; //convert random number to rotation value in degrees
stepper.rotate(1440); //rotate the wheel 4 times
stepper.rotate(wheelrotval); //rotate by rotation value
stage = thefinal; //set stage to final stage
Serial.println(rouletteconversion[wheelnumber]);
screen.background(255,255,255);
}
void finalstage() {
boolean won = false; //set a boolean "won"
screen.stroke(0,0,0);
for (int b = (currentround-1); b > 0; b--) { //for the amount of stages
if (rouletteconversion[wheelnumber] < 37){ //if wheel number isn't 0 or 00
if ((rouletteconversion[wheelnumber]%3 == wagerstorage[b].row || (rouletteconversion[wheelnumber]%3) + 3 == (wagerstorage[b].row)) && wagerstorage[b].row != none){
won = true;
Serial.print("row won: ");
Serial.println(wagerstorage[b].row);
}
else if ((rouletteconversion[wheelnumber] < (19+wagerstorage[b].half*18) && rouletteconversion[wheelnumber] > (wagerstorage[b].half*18)) && wagerstorage[b].half != none) {
won = true;
Serial.print("half won: ");
Serial.println(wagerstorage[b].half);
}
else if ((rouletteconversion[wheelnumber] <= (wagerstorage[b].third*12) && rouletteconversion[wheelnumber] >= ((wagerstorage[b].third*12)-11)) && wagerstorage[b].third != none) {
won = true;
Serial.print("third won: ");
Serial.println(wagerstorage[b].third);
}
else if ((rouletteconversion[wheelnumber]%2 == wagerstorage[b].colour) && wagerstorage[b].colour != none) {
won = true;
Serial.print("colour won: ");
Serial.println(wagerstorage[b].colour);
}
else if ((rouletteconversion[wheelnumber]%2 == wagerstorage[b].oddoreven) && wagerstorage[b].oddoreven != none) {
won = true;
Serial.print("oddoreven won: ");
Serial.println(wagerstorage[b].oddoreven);
}
}
else if (wagerstorage[b].num1 == rouletteconversion[wheelnumber] || wagerstorage[b].num2 == rouletteconversion[wheelnumber] || wagerstorage[b].num3 == rouletteconversion[wheelnumber] || wagerstorage[b].num4 == rouletteconversion[wheelnumber] || wagerstorage[b].num5 == rouletteconversion[wheelnumber] || wagerstorage[b].num6 == rouletteconversion[wheelnumber]) {
won = true;
Serial.println("inside won");
}
else {
won = false;
}
//these all check the various conditions of members of wagerstorage[]
if (won == true) {
payout += (bettingstorage[b].tot * wagerstorage[b].multiplier); //if a given bet wins, multiply bet by multiplier & add to payout
}
else if (won==false){
payout -= bettingstorage[b].tot; //otherwise subtract from payout
}
Serial.println(won);
}
currentround = -999;
char wheelnumdisplay[10];
if (rouletteconversion[wheelnumber] < 37){
sprintf(wheelnumdisplay,"Winner: %d",rouletteconversion[wheelnumber]); //convert wheel number rolled to char array with "Winner: " in fron to fit
}
else if (rouletteconversion[wheelnumber] == 37) {
sprintf(wheelnumdisplay,"Winner: %d",0); //convert wheel number rolled to char array with "Winner: " in fron to fit
}
else if (rouletteconversion[wheelnumber] == 38) {
sprintf(wheelnumdisplay,"Winner: %d",0); //convert wheel number rolled to char array with "Winner: " in fron to fit
}
//Serial.print("Payout: ");
//Serial.println(won);
//Serial.println("Winner: ");
//Serial.print(rouletteconversion[wheelnumber]);
screen.setTextSize(2);
if (payout > 0) { //If total payout is positive
char payoutdisplay[10];
sprintf(payoutdisplay,"+$%ld",payout);
screen.text(wheelnumdisplay,10,30);
screen.text("You Won:",10,80);
screen.text(payoutdisplay,10,100);
//display which number was rolled as well as the payout
}
else if (payout == 0) { //if total payout is 0
char payoutdisplay[10];
sprintf(payoutdisplay,"$%ld",payout);
screen.text(wheelnumdisplay,10,30);
screen.text("You're Even",10,50);
//display which number was rolled as well as being even
}
else if (payout < 0) { //if total payout was negative
char payoutdisplay[10];
sprintf(payoutdisplay,"$%ld",payout);
screen.text(wheelnumdisplay,10,30);
screen.text("You Lost:",10,80);
screen.text(payoutdisplay,10,100);
//display which number was rolled as well as the payout
}
delay(50);
}