/* EasyButton Game Controller This code is used to make your own buzzer control for your own at home games Microcontroller used is an Arduino core on an ATMega (can be used with EASYMSP code as well with minor translation) Program does give preferance to player by number, but if two people manage to press at the same time within less than a microsecond, I say give it to them! This is completly Open Source Code and Open Source Hardware Property of StacyD at doesitpew.blogspot.com 2011 Schematic also available at Doesitpew.Blogspot.com *///Define the Buttons//button input pins (digital)int b1 = 9;int b2 = 8; int b3 = 7;int b4 = 6; //button statusint bu1 = 0;int bu2 = 0;int bu3 = 0;int bu4 = 0;//led outout pins(digital)int l1 = 5; int l2 = 4;int l3 = 3; int l4 = 2; //Status of whether or not a button has been pressedint hold = 0;void setup() { //allows you to see on a computer who buzzed in first Serial.begin(9600); //Lockout Status LED pin with is statndard on the Arduino Board(s) pinMode(13, OUTPUT); //Button inputs defined pinMode(b1, INPUT); pinMode(b2, INPUT); pinMode(b3, INPUT); pinMode(b4, INPUT); //LED outout Pins defined pinMode(l1, OUTPUT); pinMode(l2, OUTPUT); pinMode(l3, OUTPUT); pinMode(l4, OUTPUT); //The delay allows time for the voltage to stabilize (exp. because the electronics are not removed from the buttons!) delay(1000);}void loop() { //Read to see if a button is pushed if(hold == 0){ bu1 = digitalRead(b1); bu2 = digitalRead(b2); bu3 = digitalRead(b3); bu4 = digitalRead(b4); //If the status of any of the Buttons has changed to being pulled low //lockout the other users and light up the appropriate button //player 1 if(bu1 == 0){ digitalWrite(l1, HIGH); hold = 1; //lockout the other users Serial.println("Player 1"); } //player 2 if(bu2 == 0){ digitalWrite(l2, HIGH); hold = 1; //lockout the other users Serial.println("Player 2"); } //player 3 if(bu3 == 0){ digitalWrite(l3, HIGH); hold = 1; //lockout the other users Serial.println("Player 3"); } //player 4 if(bu4 == 0){ digitalWrite(l4, HIGH); hold = 1; //lockout the other users Serial.println("Player 4"); } } else{ digitalWrite(13, HIGH); // set the LED on to indicate that the other users are locked out }}