# Problem With Creating a Roulette Game on Arduino

I'm making a game of roulette on arduino and cannot figure out how I would use the serial monitor to send/place a bet in the game. Basically I have it set so that the code begins with a push-button and it generates a random number of anywhere from 1-38 to be the number that the ball lands on, then a random number is given to the player as the number they are putting a bet on(which i would like to change to the number the player chooses) and if they get the right number then they win and the bet they placed is doubled, however if they lose then the amount they bet is subtracted from their money total. I don't know how to enable people to place bets on the numbers of their choice using the serial monitor. Is that even possible to do with arduino? Ps: my code is only partially finished.

Here is my code so far:

``````int number = 0;
int point = 0;
int money = 15000;
int bet = 0
#define button 13
void setup() {
Serial.begin(9600);
pinMode(button, INPUT);
}

void loop() {
if (digitalRead(button) == HIGH){
point = random(0, 39);
number = random(0, 39);
Serial.println ((point) && (outcome))
delay(2000);
Serial.println ((number) && ("...and this is your number"));
if (number == point){
((money = (bet * 2)))
Serial.println("Winner");
delay(1000);
}
else{
Serial.println("loser");
delay(1000);
}
}
}
``````

Why not use one of the analog inputs? So long as you have a display for the 'player' number then they can turn a knob until their desired number shows on the display.

After the wheel is started, the input is ignored and the player's number cannot be changed.

I can see how that would work. Using a potentiometer I could do that. How can you have it display the number as it changes though? would it just Serial.println(val) and show the numbers of the potentiometer as it changes?

rando m numders are not randum, why not spin an encoded wheel

I don't know how to enable people to place bets on the numbers of their choice using the serial monitor. Is that even possible to do with arduino?

How many players do you want in the game?

If it's only one player, you can remove the button from the programming logic:
The user could input his bet using the serial monitor, and as soon as he did so, the game starts.

So how many players?
One player enters his bet, then the game starts automatically?
Or do you want many players enter their many different bets, then the game starts when a button is pressed?

one player is what i'm going for. How do I program the arduino to use the serial monitor to input the amount bet and the number chosen?

one player is what i’m going for. How do I program the arduino to use the serial monitor to input the amount bet and the number chosen?

Example code reading winning number and bet amount from serial monitor before game starts:

``````int readSerialBet()
{
static char str; // For strings of max length=20
if (!Serial.available()) return -1;
delay(64); // wait for all characters to arrive
memset(str,0,sizeof(str)); // clear str
byte count=0;
while (Serial.available())
{
if (c>=32 && count<sizeof(str)-1)
{
str[count]=c;
count++;
}
}
str[count]='\0'; // make it a zero terminated string
return atoi(str);
}

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

void loop()
{
Serial.print("Please enter winning number and press enter at the end:\n");
int betNumber=-1;
while (betNumber<0 || betNumber>36) betNumber=readSerialBet();

Serial.print("Please enter bet amount and press enter at the end:\n");
int betAmount=0;