Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int thePotato;
- int danceCheck=false;
- int onButton=A0;
- int buttons[]={A2,2,3,4};
- int redLeds[]={5,6,7,8};
- int greenLeds[]={9,10,11,12};
- int checkOn=false;
- int stillInTheGame[]={true,true,true,true};
- void lightBlink(int r,int g,int timeDelay){
- digitalWrite(redLeds[r],HIGH);
- digitalWrite(greenLeds[g],HIGH);
- delay(timeDelay);
- digitalWrite(redLeds[r],LOW);
- digitalWrite(greenLeds[g],LOW);
- }
- void playerLight(int player,int timeDelay,int state){
- digitalWrite(redLeds[player],state);
- digitalWrite(greenLeds[player],state);
- delay(timeDelay);
- }
- void danceStart(){
- Serial.println("Starting Dance");
- lightBlink(0,0,500);
- lightBlink(1,3,500);
- lightBlink(2,1,500);
- lightBlink(3,2,500);
- for(int i=0;i<4;i++){
- playerLight(i,240,HIGH);
- }
- for(int i=0;i<4;i++){
- playerLight(i,0,LOW);
- }
- delay(1000);
- for(int i=0;i<4;i++){
- playerLight(i,0,HIGH);
- }
- delay(1000);
- for(int i=0;i<4;i++){
- playerLight(i,0,LOW);
- }
- delay(2000);
- danceCheck=true;
- Serial.println("Dancing done!!");
- }
- void loser(int lastPlayer){
- checkOn=false;
- danceCheck=false;
- stillInTheGame[lastPlayer]=false;
- for(int i=0;i<4;i++){
- lightBlink(lastPlayer,lastPlayer,250);
- }
- digitalWrite(redLeds[lastPlayer],HIGH);
- }
- void lightSwitch(int turnOff){
- digitalWrite(greenLeds[turnOff],LOW);
- thePotato=(turnOff+1)%4;
- while(stillInTheGame[thePotato]==false){
- thePotato=(thePotato+1)%4;
- }
- digitalWrite(greenLeds[thePotato],HIGH);
- }
- void setup(){
- Serial.begin(9600);
- for(int counter=0;counter<4;counter++){
- pinMode(buttons[counter],INPUT_PULLUP);
- pinMode(redLeds[counter],OUTPUT);
- pinMode(greenLeds[counter],OUTPUT);
- digitalWrite(redLeds[counter],LOW);
- digitalWrite(greenLeds[counter],LOW);
- }
- pinMode(onButton,INPUT);
- }
- void loop(){
- while(digitalRead(onButton)==LOW){
- Serial.println("The on button is off.");
- }
- Serial.println("The on button has been turned on!!!");
- delay(1000);
- danceStart();
- thePotato=random(0,4);
- for(int losers=0;losers<3;losers++){
- if(losers>=3){
- Serial.println("The game is done!!");
- Serial.print("The winner is player ");
- for(int b=0;b<4;b++){
- if(stillInTheGame[b]){
- Serial.print(b+1);
- }
- }
- Serial.println("!");
- }
- if(losers<3){
- Serial.print("Round ");
- Serial.print(losers+1);
- Serial.println("!");
- }
- else if(losers==3){
- Serial.println("Final Round!!!!");
- }
- long maxTime=random(30,51)*1000;
- Serial.print("Timer set to ");
- Serial.println(maxTime);
- long startTime=millis();
- boolean released=false;
- while(millis()-startTime<maxTime){
- // check if current player has pressed button
- digitalWrite(greenLeds[thePotato],HIGH);
- int buttonState=digitalRead(buttons[thePotato]);
- if(buttonState==HIGH){
- released=true;
- }
- if(released&&buttonState==LOW){
- // move to next player
- lightSwitch(thePotato);
- Serial.print("The player is ");
- Serial.println(thePotato+1);
- released=false;
- }
- }
- loser(thePotato);
- lightSwitch(thePotato);
- }
- delay(1000);
- }
- //LastLine #115
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement