“Only Room for One” (updated for final)

For an  electrical function, I added a turn keeper for my katamari magnet game (http://classes.design.ucla.edu/Winter09/157A/?p=930). In  addition, I added in colour to all the cards.

I used Eddo’s turn keeper code as the basis for what I did. My major modifications for the circuit diagram came in the form of using transistors to allow the arduino to run the 12V lamp buttons. Everything seemed to work fine until I realised that the arduino board gets extremely hot rather quickly. I haven’t figured out the problem yet but it may be due to something causing a short circuit on the board. I checked my board a few times but it is very hard to find a mistake because the wires are jammed together so closely.

Sketch code:

———————————————————————

/*
* INFO:
*********************************************************************
* WHAT: Game Turn Keeper for 4 players (Using Switch Statements and Extra Functions)
* BY:  eddo3ddo for DESMA 157A UCLA W09
* DATE: FEB 15, 2009
*
* THINGS TO LEARN HERE:
*********************************************************************
* SWITCH…CASE - using SWITCH STATEMENT INSTEAD OF A BUNCH OF IF..THEN..ELSE STATEMENTS
* BREAK - DON’T FORGET TO USE BREAK IN YOUR SWITCH STATEMENTS TO BREAK OUT OF THE SWITCH
* FUNCTIONS - USING FUNCTIONS AND FUCNTION CALLS FOR REUSABLE CODE
* RETURN - USING FUNCTIONS WITH AND WITHOUT RETURN VALUES
*
* COMPONENTS LIST:
*********************************************************************
* 1 X ARDUINO D, 1 X BREADBOARD, WIRE, 6x PULLUP REISTORS , 4 x PUSHBUTTONS, 4 X LEDS, 1 X 3 POSITION TOGGLE SWITCH , JUMPER WIRES
*
*
* COMPONENETS SETUP:
*********************************************************************
* LEDS on PINS 6 ,7 , 8 ,9
* PUSHBUTTONS WITH PULL UP RESISTORS ON PINS 2,3,4,5
* BUZZER ON PIN 11
* 3 pOSITION TOGGLE SWITCH ON PINS 0 ,1 WITH PULLUP RESISTORS
* *******************************************************************
*
*/

int CW = 10;         // the PIN of the CW toggle switch
int CCW = 11;       // the PIN of the CCW toggle switch

// YOU WOULD NORMALLY USE A LOOKUP ARRAY TO STORE THESE  - BUT WE ARE TRYING TO KEEP THE CODE SIMPLE - THOUGH WE HAD TO WRITE 2 EXTRA LOOKUP  FUNCTIONS SINCE WE ARENT USING ARRARYS….
// THE ARRAY WOULD LOOK LIKE THIS:
// int Player_BUTTON_Pins[4] = {2,3,4,5};

int Player1_Button_PIN = 2;         // Player 1 Button PIN
int Player2_Button_PIN = 3;         // the number of the input pin
int Player3_Button_PIN = 4;         // the number of the input pin
int Player4_Button_PIN = 5;         // the number of the input pin

int BuzzerPin = 12;       // the number of the output pin Buzzer

// YOU WOULD NORMALLY USE A LOOKUP ARRAY TO STORE THESE  - BUT WE ARE TRYING TO KEEP THE CODE SIMPLE -  THOUGH WE HAD TO WRITE 2 EXTRA LOOKUP FUNCTIONS SINCE WE ARENT USING ARRARYS….
// THE ARRAY WOULD LOOK LIKE THIS:
// int Player_LED_Pins[4] = {2,3,4,5};

int Player1_LED_PIN = 6;         // the number of the input pin
int Player2_LED_PIN = 7;         // the number of the input pin
int Player3_LED_PIN = 8;         // the number of the input pin
int Player4_LED_PIN = 9;         // the number of the input pin

int CurrentPlayer = 1;
int turnorder = CW;              // sets turnorder default as clockwise

void setup()
{
Serial.begin(9600);
pinMode(Player1_Button_PIN, INPUT);
pinMode(Player2_Button_PIN, INPUT);
pinMode(Player3_Button_PIN, INPUT);
pinMode(Player4_Button_PIN, INPUT);

// THIS IS THE white or BLACK BUTTON
pinMode(CW, INPUT);
pinMode(CCW, INPUT);

pinMode(BuzzerPin, OUTPUT);

pinMode(Player1_LED_PIN, OUTPUT);
pinMode(Player2_LED_PIN, OUTPUT);
pinMode(Player3_LED_PIN, OUTPUT);
pinMode(Player4_LED_PIN, OUTPUT);

// CALL THE LED ON FUNCTION TO TURN ON CURRENT PLAYER’S LED  (this starts at PLAYER 1)
Player_LED_ON (CurrentPlayer) ;
}

void loop() {

//READ MASTER CW or CCW SWITCH
if (digitalRead(CW) == LOW && digitalRead(CCW) == HIGH) {
Serial.println(”turn order == CCW”);
turnorder = CCW;
}
else if (digitalRead(CW) == HIGH && digitalRead(CCW) == LOW){
Serial.println(”turn order == CW”);
turnorder = CW;
}

//READ THE CURRENT PLAYER’S BUTTON TO SEE IF IT IS PRESSED
if (Read_Player_Button(CurrentPlayer) == LOW) {
//BUZZ BUZZER FOR 20 ms
digitalWrite(BuzzerPin, HIGH);
delay(20);
digitalWrite(BuzzerPin, LOW);
delay(100);

//INCREMENT TO NEXT PLAYER BASED ON DIRECTION WE ARE GOING
if (turnorder == CW){
Serial.println(”turn order == CW”);
if (CurrentPlayer < 4) {
CurrentPlayer++;
}
else {
CurrentPlayer = 1;
}
}

if (turnorder == CCW){
Serial.println(”turn order == CCW”);
if (CurrentPlayer > 1) {
CurrentPlayer–;
}
else {
CurrentPlayer = 4;
}
}
Serial.print(”Current Player = “);
Serial.println(CurrentPlayer);
// UPDATE STAUTS LIGHT to INDICATE CURRENT PLAYER’S TURN
Player_LED_ON (CurrentPlayer);

}
else { // DO NOTHING - TOGGLE IS IN THE OFF POSITION
// USE CODE TO TURN OFF THE LIGHTS IF YOU WANT THE LIGHT OFF AS WELL WHEN TOGGLE IS OFF
}
}

// THIS FUNCTION receives a player# (1-4) and turns thatPlayer’s LED ON and all other LEDS OFF)
void Player_LED_ON (int player) {

int CurrentPlayerLEDPin;

//FIRST TURN OFF ALL LEDS
digitalWrite(Player1_LED_PIN, LOW);
digitalWrite(Player2_LED_PIN, LOW);
digitalWrite(Player3_LED_PIN, LOW);
digitalWrite(Player4_LED_PIN, LOW);

//Derive Player_LED_PIN from player
switch (player) {
case 1:
CurrentPlayerLEDPin = Player1_LED_PIN;
break;
case 2:
CurrentPlayerLEDPin = Player2_LED_PIN;
break;
case 3:
CurrentPlayerLEDPin = Player3_LED_PIN;
break;
case 4:
CurrentPlayerLEDPin = Player4_LED_PIN;
break;
}
//TURN ON player LED PIN
digitalWrite(CurrentPlayerLEDPin, HIGH);
}

// THIS FUNCTION RECEIVES A PLAYER # (1-4) AND READS THEIR BUTTON - IT RETURNS THE STATE OF THE BUTTON
int Read_Player_Button (int player) {

int CurrentPlayerBUTTONPin;
int state;

switch (player) {
case 1:
CurrentPlayerBUTTONPin = Player1_Button_PIN;
break;
case 2:
CurrentPlayerBUTTONPin = Player2_Button_PIN;
break;
case 3:
CurrentPlayerBUTTONPin = Player3_Button_PIN;
break;
case 4:
CurrentPlayerBUTTONPin = Player4_Button_PIN;
break;
}

// READ THE APPROPRIATE BUTTON
state = digitalRead(CurrentPlayerBUTTONPin);

return state;
}

——————————————————–

giant-squidcompton-girl

fruit

photo-0031photo-0030photo-0033photo-0032