Skip to content

Instantly share code, notes, and snippets.

@dvberkel
Last active December 10, 2015 01:48
Show Gist options
  • Save dvberkel/4362860 to your computer and use it in GitHub Desktop.
Save dvberkel/4362860 to your computer and use it in GitHub Desktop.
A sumo wrestling inspired, arduino based, reflex test party game
/*
Sumo
A two player sumo wrestling type of game.
When both players have pressed their start pin the game starts.
After a random stretch of time a central LED will light up.
The first player to press the respective target pin wins.
If a player releases the start pin before the central LED lights up
she loses.
*/
const int READY = 0;
const int SET = 1;
const int GO = 2;
const int SIGNAL = 3;
const int WIN_A = 4;
const int WIN_B = 5;
int current_state = READY;
int start_pin_A = 2;
int target_pin_A = 3;
int won_pin_A = 6;
int lost_pin_A = 7;
int start_pin_B = 4;
int target_pin_B = 5;
int won_pin_B = 8;
int lost_pin_B = 9;
int signal_pin = 10;
int start_time = 0;
int target_time = random(750, 3250);
boolean well_played = true;
void setup() {
Serial.begin(9600);
pinMode(start_pin_A, INPUT);
pinMode(target_pin_A, INPUT);
pinMode(start_pin_B, INPUT);
pinMode(target_pin_B, INPUT);
pinMode(won_pin_A, OUTPUT);
pinMode(lost_pin_A, OUTPUT);
pinMode(won_pin_B, OUTPUT);
pinMode(lost_pin_B, OUTPUT);
pinMode(signal_pin, OUTPUT);
digitalWrite(won_pin_A, LOW);
digitalWrite(lost_pin_A, LOW);
digitalWrite(won_pin_B, LOW);
digitalWrite(lost_pin_B, LOW);
digitalWrite(signal_pin, LOW);
}
void loop() {
int start_state_A = digitalRead(start_pin_A);
int target_state_A = digitalRead(target_pin_A);
int start_state_B = digitalRead(start_pin_B);
int target_state_B = digitalRead(target_pin_B);
if (current_state == READY) {
if (start_state_A == HIGH || start_state_B == HIGH) {
current_state = SET;
}
}
if (current_state == SET) {
if (start_state_A == HIGH && start_state_B == HIGH) {
current_state = GO;
start_time = millis();
}
if (start_state_A == LOW && start_state_B == LOW) {
current_state = READY;
}
}
if (current_state == GO) {
if (start_state_A == LOW) {
current_state = WIN_B;
well_played = false;
}
if (start_state_B == LOW) {
current_state = WIN_A;
well_played = false;
}
if (millis() - start_time > target_time) {
current_state = SIGNAL;
}
}
if (current_state == SIGNAL) {
if (target_state_A == HIGH && target_state_B == LOW) {
current_state = WIN_A;
}
if (target_state_A == LOW && target_state_B == HIGH) {
current_state = WIN_B;
}
}
if (current_state == SIGNAL || (well_played && (current_state == WIN_A || current_state == WIN_B))) {
digitalWrite(signal_pin, HIGH);
}
if (well_played && current_state == WIN_A) {
digitalWrite(won_pin_A, HIGH);
}
if (well_played && current_state == WIN_B) {
digitalWrite(won_pin_B, HIGH);
}
if (!well_played && current_state == WIN_A) {
digitalWrite(lost_pin_B, HIGH);
}
if (!well_played && current_state == WIN_B) {
digitalWrite(lost_pin_A, HIGH);
}
Serial.println(current_state);
Serial.println(start_state_A);
Serial.println(target_state_A);
Serial.println(start_state_B);
Serial.println(target_state_B);
Serial.println("-------");
delay(100);
}
@dvberkel
Copy link
Author

You need two sets of buttons to form a two-player game.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment