/*
Arduino Roulette
Single or Double Zero Wheel
2/1/26
AnonEngineering
*/
const int NUM_GROUPS = 6;
const int NUM_SEGMENTS = 7;
const int GROUP_PINS[] = {A1, A2, A3, 2, 3, 4};
const int SEGMENT_PINS[] = {11, 10, 9, 8, 7, 6, 5};
const int BTN_PIN = 12;
const int MODE_PIN = 13;
bool mode = false;
void clearWheel() {
for (int i = 0; i < NUM_GROUPS; i++) {
digitalWrite(GROUP_PINS[i], HIGH); // set group pins HIGH (off)
}
for (int i = 0; i < NUM_SEGMENTS; i++) {
digitalWrite(SEGMENT_PINS[i], LOW); // set seg pins LOW (off)
}
}
void spinWheel() {
int tRandom = 0;
int speed = 10;
// spin the wheel a few times
for (int s = 0; s < 4; s++) {
for (int group = 0; group < NUM_GROUPS; group++) {
digitalWrite(GROUP_PINS[group], LOW);
for (int segment = 0; segment < NUM_SEGMENTS; segment++) {
//Serial.print("Number: ");
//Serial.println((group * NUM_SEGMENTS) + segment);
digitalWrite(SEGMENT_PINS[segment], HIGH);
delay(speed);
digitalWrite(SEGMENT_PINS[segment], LOW);
delay(10);
// single 0, reset at 37th count, double 0, reset at 38th count
int highSegVal = mode ? 1 : 2;
if (group >= 5 && segment >= highSegVal) {
break;
}
}
digitalWrite(GROUP_PINS[group], HIGH);
}
speed = speed + 20;
}
// "pop" the ball a few times
for (int i = 0; i < 5; i++) {
tRandom = random(0, mode ? 37 : 38);
digitalWrite(GROUP_PINS[tRandom / 7], LOW);
digitalWrite(SEGMENT_PINS[tRandom - ((tRandom / 7) * 7)], HIGH);
delay(250);
clearWheel();
}
// drop ball in random pocket
digitalWrite(GROUP_PINS[tRandom / 7], LOW);
digitalWrite(SEGMENT_PINS[tRandom - ((tRandom / 7) * 7)], HIGH);
Serial.print("Winner ");
Serial.println(tRandom);
}
void setup() {
Serial.begin(115200);
for (int i = 0; i < NUM_GROUPS; i++) { // 6 groups
pinMode(GROUP_PINS[i], OUTPUT);
}
for (int i = 0; i < NUM_SEGMENTS; i++) { // 7 "segments" per group
pinMode(SEGMENT_PINS[i], OUTPUT);
}
pinMode(BTN_PIN, INPUT_PULLUP);
pinMode(MODE_PIN, INPUT_PULLUP);
clearWheel();
mode = digitalRead(MODE_PIN);
randomSeed(analogRead(A0));
// splash screen
Serial.println("Arduino Roulette");
Serial.println(mode ? "Single Zero Wheel" : "Double Zero Wheel");
Serial.println("Bonne chance!\n");
}
void loop() {
if (digitalRead(BTN_PIN) == LOW) {
clearWheel();
spinWheel();
}
}
Spin
0 - 00