Dice Boxing (electronic)

The purpose of the device is to create surefire method of deciding who “punched” or “blocked” first while Dice Boxing. When one player presses their action button, the other player’s button is disabled.
Code has two separate LED’s, each with its own input and output. Each LED is connected to their respective buttons; however when one button is pressed, the other input is blocked. Code checks if button 1 is on, checks if LED 2 is on; if it is, input to LED 1 is blocked. If the LED 2 isn’t on, LED 1 is turned on, and if nothing is pressed, neither LED is on. This logic works the same way for button 2.
Arduino
2 buttons
2 resistors
2 LEDs
Wires

diceboxingelectronic

diceboxingelectronic2
int ledPin = 13;                // choose the pin for the LED
int inputPin = 3;               // choose the input pin (for a pushbutton)

int ledPin2 = 12;
int inputPin2 = 2;

boolean led1on;                    // variable for reading the pin status
boolean led2on;

void setup() {
pinMode(ledPin, OUTPUT);      // declare LED as output
pinMode(inputPin, INPUT);     // declare pushbutton as input

pinMode(ledPin2, OUTPUT);
pinMode(inputPin2, INPUT);

led1on = true;
led2on = true;
}

void loop(){
readButtons();
turnOnLights();
}

void readButtons(){
// Check your buttons, which are on?
// (if no voltage returns to the pins, its on)
boolean budadptton1on = (digitalRead(inputPin) == LOW);
boolean button2on = (digitalRead(inputPin2) == LOW);

// Button 1 logic
// ==============

if(button1on == true) // Are you pressing button?
{
if(led2on == true) // Is the other light on?
{
led1on = false; // If the other light is on, dont turn this one on.
}
else led1on = true; // Otherwise turn this light on
}
else led1on = false; // This is if you’re not pressing the button

// Button 2 logic
// ==============

if(button2on == true) // Are you pressing button?
{
if(led1on == true) // Is the other light on?
{
led2on = false; // If the other light is on, dont turn this one on.
}
else led2on = true; // Otherwise turn this light on
}
else led2on = false; // This is if you’re not pressing the button

}

void turnOnLights()
{
if(led1on == true) digitalWrite(ledPin, HIGH);
else digitalWrite(ledPin, LOW);

if(led2on == true) digitalWrite(ledPin2, HIGH);
else digitalWrite(ledPin2, LOW);
}

One Comment

  1. Error: Unable to create directory /data/classes/web/Winter09/157A/wp-content/uploads/2019/07. Is its parent directory writable by the server? Eddo
    Posted February 25, 2009 at 10:33 pm | Permalink

    Brian,

    Woudn’t you need 4 Buttons for this to work properly with your game?

    Each player would need a punch button and a block button to choose from ?

    You could even add a third button for the super punch

    and beyond that add a random mechanical dice roller :)

    E