Good day, dear reader of my article, today in this article I would like to tell you how to assemble the game "tug of war" on arduino
THIS IS WHAT YOU NEED:
1. Arduino Uno
2.2 condensers for 0.1 microfarads
3.14 resistors of 220 ohms
4. LED scale or 10 LEDs at 3 volts
5. Breadboard
6. 2 clock buttons
7. piezo tweeter
8. Schmitt inverting trigger
9. jumper wires
So first, let's program the arduino
Here is a sketch:
Next, we collect everything according to this scheme:
you should get something like this:
after the "rope" has moved to side 1 of the players the game ends, you can restart it by pressing the button on the arduino itself
I hope you enjoyed this project and with you the DeNiS Geek pro100 ball, that's all for now!
THIS IS WHAT YOU NEED:
1. Arduino Uno
2.2 condensers for 0.1 microfarads
3.14 resistors of 220 ohms
4. LED scale or 10 LEDs at 3 volts
5. Breadboard
6. 2 clock buttons
7. piezo tweeter
8. Schmitt inverting trigger
9. jumper wires
So first, let's program the arduino
Here is a sketch:
#define BUZZER_PIN 0
#define FIRST_BAR_PIN 4
#define BAR_COUNT 10
#define MAX_SCORE 20
// global variables used in interrupts (see below)
// must be marked as unstable (volatile)
volatile int score = 0;
void setup ()
{
for (int i = 0; i & lt; BAR_COUNT; ++ i)
pinMode (i + FIRST_BAR_PIN, OUTPUT);
pinMode (BUZZER_PIN, OUTPUT);
// Interruption (English interrupt) suspends the main
// program, performs the specified function, and then resumes
// main program. We need an interrupt at the click of a button,
// i.e. when changing the signal from high to low, i.e. on the
// downward (falling) front
attachInterrupt (INT1, pushP1, FALLING); // INT1 is the 3rd pin
attachInterrupt (INT0, pushP2, FALLING); // INT0 is the 2nd pin
}
void pushP1 () {++ score; } // 1st player interrupt function
void pushP2 () {--score; } // 2nd player interrupt function
void loop ()
{
tone (BUZZER_PIN, 2000, 1000); // give a signal to start.
// while none of the players won, we update the “rope”
while (abs (score) & lt; MAX_SCORE) {
int bound = map (score, -MAX_SCORE, MAX_SCORE, 0, BAR_COUNT);
int left = min (bound, BAR_COUNT / 2 - 1);
int right = max (bound, BAR_COUNT / 2);
for (int i = 0; i & lt; BAR_COUNT; ++ i)
digitalWrite (i + FIRST_BAR_PIN, i & gt; = left && i & lt; = right);
}
tone (BUZZER_PIN, 4000, 1000); // give a signal of victory
while (true) {} // "suspend" the board until reboot
}
Next, we collect everything according to this scheme:
you should get something like this:
after the "rope" has moved to side 1 of the players the game ends, you can restart it by pressing the button on the arduino itself
I hope you enjoyed this project and with you the DeNiS Geek pro100 ball, that's all for now!