Advertisement
ChaOSzz

Untitled

May 5th, 2022
1,004
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define BUZZER_PIN 7
  2. #define PLAYER_COUNT 2
  3.  
  4. int buttonPins[PLAYER_COUNT]= {2,13};
  5. int ledPins[PLAYER_COUNT]= {3,12};
  6.  
  7. void setup()
  8. {
  9.   for(int i = 0;i<PLAYER_COUNT;i++)
  10.   {
  11.     pinMode(ledPins[i],OUTPUT);
  12.     pinMode(buttonPins[i],INPUT_PULLUP);
  13.   }
  14.   pinMode(BUZZER_PIN,OUTPUT);
  15. }
  16.  
  17. void loop()
  18. {
  19.     delay(random(1000,3000));
  20.     tone(BUZZER_PIN,2000,400);
  21.    
  22.     delay(400);
  23.    
  24.     for(int player = 0; ;player = (player+1)%PLAYER_COUNT)
  25.     {
  26.       if(digitalRead(buttonPins[player]))
  27.       {
  28.         digitalWrite(ledPins[player],HIGH);
  29.         tone(BUZZER_PIN,3500,300);
  30.         delay(1000);
  31.         digitalWrite(ledPins[player],LOW);
  32.         break;
  33.       }
  34.     }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement