Team 4.2 – Code Talk (The Hit new Talk Show starring Team 4.2)

First, the code driving it is fairly simple. The main initializes the board, the delays, and the IO ports. Then each pin that is being utilized in the project is set as either an input or output, depending on its functionality, with J1’s pins 0-2 being the input pins, J3 pins 0-2 and J2 pins 3-7 being the output pins for the LEDs. All the pins are then set to low, and the game starts. When the game starts, the input pins are enabled, and a while loop is entered:

while(player2selection==0)
{
//Waits until the player selects his option
if(gpio_pin_is_high(J1_PIN0)==true&&gpio_pin_is_high(J1_PIN1)==true&&gpio_pin_is_high(J1_PIN2))
{
player2selection=0;
}
if(gpio_pin_is_high(J1_PIN0)==true&&GPIO_PUSH_BUTTON_0)
{
player2selection=1;
}
else if(gpio_pin_is_high(J1_PIN2)==true)
{
player2selection=3;
}
else if(gpio_pin_is_high(J1_PIN1)==true)
{
player2selection=2;
}
else
{
player2selection=0;
}
}

As stated before, the pins that are referenced are the three input pins, corresponding to Rock, Paper, and Scissors respectively. This while loop stays active until one of the IO Pins are seen as being at a high logic value, and the corresponding selection is made for player 2, AKA the human player. (The first line of it where every pin is checked for being high was to combat some of the anomalies we had reached, and it was found that this did help filter some of them out.)

After the user inputs a value the pins for inputs are disabled, and the computer randomly selects a number between 1 and 3 for its selection.

 

comp=rand()%3+1;

After this a function is entered that lights up the selection LEDs by setting the corresponding pins as high for both the player and the computer for one second. Those pins are then set to low again, turning off the LEDs.

else if(player1selection==3 && player2selection==2)
{
//Set P1 P and C S
ioport_set_pin_high(J2_PIN6);
ioport_set_pin_high(J2_PIN7);
delay_ms(1000);
ioport_set_pin_low(J2_PIN7);
ioport_set_pin_low(J2_PIN6);
}

Next the code compares the computer and user selections to determine a winner, and the correct winner LED is lit up (if it is a tie then both of the red LEDs light up) for 3 seconds before turning off.

if(player1selection==player2selection)
{
ioport_set_pin_high(J3_PIN0);
ioport_set_pin_high(J3_PIN1);
delay_ms(3000);
ioport_set_pin_low(J3_PIN0);
ioport_set_pin_low(J3_PIN1);
}
else if((player2selection==1&&player1selection==2)||(player2selection==2&&player1selection==3)||(player2selection==3&&player1selection==1))
{
ioport_set_pin_high(J3_PIN0);
delay_ms(3000);
ioport_set_pin_low(J3_PIN0);
}

The computer’s and player’s selections are then reset to 0, all the pins being used set to low again, and finally the function that runs the game is run again, repeating the process until the power is cut to the board. (There is currently no end state for the game. Ideally we would have wanted to implement another couple selection buttons to indicate if a person wanted to stop playing, but we did not have time to implement it. So for now, you’re stuck playing. FOREVER. Or until you walk away. Or cut the power. Or unwire something. Or punch it.)

 

Team 4.2 – Rock, Paper, Scissors Working Video

This video is an explanation of our project, Rock, Paper Scissors.

For our project Rock is blue, Paper is Green, and Scissors is Yellow.  Our 1 player game, allows a user to select an input via one of three buttons(blue, green, yellow).  Then the micro controller randomly selects a player 2 input.  The results are shown on LEDs with a winner displayed via the red LED

IMG_0951