» Topics » DIY ideas »The game" push-button cowboys "on arduino

Button Cowboys game on Arduino

Good day my reader to become, today I would like to tell you how to assemble the game "button cowboys" in arduino

THIS IS WHAT YOU NEED;
1.Arduino (in my case, Uno)
2.2 resistors at 220 ohms
3.2 LEDs (preferably different colors)
4.2 clock buttons
5. piezo
6.Breadboard or solderless breadboard
7. jumper wires



to start, let's program arduino



here is a sketch:

#define BUZZER_PIN 12 // pin with squeaker
#define PLAYER_COUNT 2 // number of cowboy players
// instead of listing all the pins one by one, we declare a pair
// lists: one with pin numbers with buttons, the other with
// LEDs. Lists are also called arrays.
int buttonPins [PLAYER_COUNT] = {3, 13};
int ledPins [PLAYER_COUNT] = {9, 11};
 
void setup ()
{
  pinMode (BUZZER_PIN, OUTPUT);
  for (int player = 0; player & lt; PLAYER_COUNT; ++ player) {
    // using square brackets get the value in the array
    // under the number indicated in them. Numbering starts from scratch.
    pinMode (ledPins [player], OUTPUT);
    pinMode (buttonPins [player], INPUT_PULLUP);
  }
}
 
void loop ()
{
  // give a signal "pli!", waiting for a random time from 2 to 7 seconds
  delay (random (2000, 7000));
  tone (BUZZER_PIN, 3000, 250); // 3 kilohertz, 250 milliseconds
 
  for (int player = 0;; player = (player + 1)% PLAYER_COUNT) {
    // if the player number "player" pressed the button ...
    if (! digitalRead (buttonPins [player])) {
      // ... turn on its LED and victory signal for 1 second
      digitalWrite (ledPins [player], HIGH);
      tone (BUZZER_PIN, 4000, 1000);
      delay (1000);
      digitalWrite (ledPins [player], LOW);
      break; // There is a winner! We exit (English break) from a cycle
    }
  }
}


then we collect everything according to this scheme

Button Cowboys game on Arduino


You should get something like this



and now the game is ready to use
whoever clicks faster and won
and that’s probably all for today


AND YES, TAKE A QUESTIONNAIRE BELOW
Question \ topic is automatically published in the social. site network - stay tuned for answers there:
did you manage to repeat?
Total votes: 5

Suitable for topic

Related topics

Add a comment

    • smilesmilesxaxaokdontknowyahoonea
      bossscratchfoolyesyes-yesaggressivesecret
      sorrydancedance2dance3pardonhelpdrinks
      stopfriendsgoodgoodgoodwhistleswoontongue
      smokeclappingcraydeclarederisivedon-t_mentiondownload
      heatirefullaugh1mdameetingmoskingnegative
      not_ipopcornpunishreadscarescaressearch
      tauntthank_youthisto_clueumnikacuteagree
      badbeeeblack_eyeblum3blushboastboredom
      censoredpleasantrysecret2threatenvictoryyusun_bespectacled
      shokrespektlolprevedwelcomekrutoyya_za
      ya_dobryihelperne_huliganne_othodifludbanclose
8 comments
Author
Thanks for your criteria
No handling of false starts. ((
If after resetting the winner’s LED, without waiting for the sound signal, press the button, then after the signal the LED of the player who pressed the button will turn on immediately. If both players are so cunning, then the zero player will always win.
Wow wow guys easy. A guy learning to program an arduino, don’t have to be so hard, let him study. At the same time, Denis, no offense, but few people are interested in your projects such as "Hello World" and the blinking of the LED, this is interesting for you, but to the rest, believe me, not really. Learn by yourself, but don't try to teach others. And since I decided to become a public person, that is, to publish, be prepared for criticism, especially when it is appropriate, and it is appropriate at this stage of your experience. I myself have a bucket of human life results that I could pour on your article, but in no case I will not, because young technicians should be encouraged, prompted, instructed, and not criticized. Tossy expressions “WHAT? You break my brain right now” do not show you in the best light, know how to hold a blow and respond to it with dignity.

P.S. And check the text before publishing at least in Word.
you break my brain right now
Is there anything to break? smile
Author
WHAT? you break my brain right now
it processes the signal, is an important part of this project
But buttons with two pairs of contacts, normally closed contacts of one button when pressed open the circuit of normally open another? smile
Author
it processes the signal, is an important part of this project,
whoever clicks faster and won
well and Arduino - then why? scratch

We advise you to read:

Hand it for the smartphone ...