Configurable Domination Timer for Airsoft | Paintball

04/05/2021

Domination Timer is a device - a stopwatch with a second resolution that allows you to measure the time (time) of a point occupied. The stopwatch has two times for 2 teams playing against each other, visualizing them on the LCD character display. Time is always added to only one of the teams, or not to one if the point (DOMINATOR) is neutral. 

Each of the teams is trying to occupy a point, which has a certain type of input that is used to occupy it (RFID card, bracelet or hardware buttons for user input). The aim of the game is to keep the point occupied as long as possible. The game can be ended by a time limit to be reached, or by a referee who manually stops the time by pressing his button. The older version of the DOMINATOR button project originally used 4 switch buttons, allowing user input for Team 1 (RED), Team 2 (GRE), Referee and Eraser. 

This version of the DOMINATOR project did not verify the length of time the button was pressed (held) and responded to the press immediately. Based on feedback from Airsoft players, a similar version of the DOMINATOR button was created, which uses only 2 button inputs for team entities -> Team 1 (RED), Team 2 (GRE) and the referee (if he presses both buttons at the same time). The version is extended by a 360 ° rotary encoder, which can be used to change and customize several possible data in the configurable menu - changeable data for the game and the needs of players.

Used hardware components:

  • Arduino Uno / Nano / standalone AVR chip AtMega328P
  • LCD character display 16x2 / 20x4
  • I2C converter for LCD display
  • 2x buttons (switch)
  • 360 ° rotary encoder - e.g. KY-040
  • 2x LEDs
  • Optional - buzzer


Configurable DOMINATOR wiring diagram:

  • Buzzer connects to D10 Arduino (not included in wiring diagram)


Functionality:

After starting the Arduino microcontroller (but also restart, power-on cycles), the main menu is displayed on the 16x2 / 20x4 LCD character display. 

In this menu it is possible to switch (by turning the encoder) between the following menu items:

  • Game start (Domination Timer)
  • Set the time to press the occupancy key
  • Setting the maximum game time
  • Buzzer configuration (detector)
  • Countdown setting - COUNTDOWN
  • Game start (COUNTDOWN)

As can be seen from the menu items, this version of DOMINATOR is also expanded with the COUNTDOWN game mode, which can be used to start the game in Attacking and Defending Team mode. After the start of the game, the set time starts to count down, it is set in minutes. During this time, the member of the attacking team must press and hold both buttons for the set time of pressing the buttons from the menu.

Each time you change (turn the encoder a step to + or -), the current menu item is displayed on the LCD character display 16x2 or 20x4. The Arduino communicates with the display via an I2C bus with a speed of 100 kHz - Standard speed. Programmatically, the individual menu texts are switched via a switch - a branch that responds to the value of the speed counter. In the menu, however, we must distinguish the mode in which the user is. We distinguish between the main menu mode, configuration mode, game mode.

In game mode, the system does not respond at all to the encoder, in main menu mode and configuration modes, it does not respond to the buttons used in the game. The menu item is confirmed via a button that has an integrated encoder. At the same time, logic is executed when the button is pressed (mode change, save ...). Likewise, the program implementation uses the switch for modes and functions as a simple state machine. In a certain state, the system responds to a specific type of input peripherals - buttons, encoder, visualizes the time counter and the like. All configurable values ​​are stored in the Arduino EEPROM memory.

Let's take a closer look at the main menu items:

Start of the game (Domination Timer):

The display shows two times for the RED team and the GRE team, being set to zero values ​​for 00 hours, 00 minutes, 00 seconds. The system responds to two buttons that enter user input (require hold) for the time that can be set in the "Set time to press button for occupancy" menu. After holding enough time, the team's LED will light up and the time in seconds will start to accrue. 

If DOMINATOR occupies the second team, holding its button for the necessary time will stop adding time for the previous team, its LED will go out. The LED of the current team will light up and the time will start to be added to that team. The program implementation can be extended by a state where, if the button is held at least 50% and less than 100% of the time, the time addition stops (the point goes to the neutral state) for the team that was kept active at the given point.

Both times can be stopped by a referee who stops the time at the same time by briefly pressing both buttons. Resetting the game and resetting the current times is performed by restarting the entire Arduino board via the RST button, or by disconnecting and connecting the power supply. The buttons are connected in the INPUT_PULLUP mode, where the digital input is connected via an internal 20kohm resistor to 5V. 

By switching the button, GND is fed to the input - Active LOW signal. If necessary, when the cables are routed to the buttons for a longer time, it is possible to use the INPUT software input and use an external - lower pullup resistor. The wiring diagram provides for pushbuttons, not pushbuttons, which would not work in the program implementation (they would look like they were pressed in the normal state, time would be stopped - the input of the referee).

Set the time to press the occupancy key

The first of the configurable parameters in the system is the point occupancy time. Specifies the time (in seconds) how long the user must hold down the button until the point is occupied and the logic for calculating the time for the team is executed. Using the rotary encoder, it is possible to set the required time in the resolution of seconds and confirm the selection with the encoder button.

The time value (INT) is stored in the internal EEPROM memory at offset (address) 10 after pressing the key. The value is thus available and is unchanged even after restarting / disconnecting and connecting the power supply to the Arduino board. Both DOMINATOR and COUNTDOWN game mode take this value into account.

Setting the maximum game time

The second configurable parameter is the maximum game time expressed in hours. The value is set by turning the rotary encoder and confirmed by pressing the button. The minimum value for a limited time is 1 hour, while it is possible to find a value WITHOUT LIMITATION at the position of the counter 0, when the game is not limited and counts the time from infinity, respectively to the visualized value of 99 hours, 59 minutes, 59 seconds. 16x2 display. 


This value is only taken into account by the DOMINATOR game mode. The value is stored in the internal EEPROM memory at offset 20. This value indicates the automatic end of the game when this time is reached by one of the teams in the DOMINATOR game. After reaching a given time in the game by any team, the game ends and DOMINATOR stops counting time and does not respond to button input.

Buzzer configuration:

The buzzer can be switched on / off by software by turning the rotary encoder. The detector frequency cannot be configured, it is set to 2000 Hz by default. In DOMINATOR game mode, the buzzer only beeps when the point is occupied. In COUNTDOWN game mode, the buzzer beeps every second with a beep length of 50 ms. If the time runs out to 0 seconds, 0 minutes, 0 hours, the buzzer switches to a frequency of 500 Hz and a beep (emits a continuous tone) announcing the end of the game - waiting for a restart.

Countdown setting - COUNTDOWN

Last configurable parameter set in minutes. The countdown length for the countdown game mode is set.

The entire software implementation of this solution takes up about 7 kilobytes of flash memory and 480 bytes of RAM. As the Arduino has 32kB (28kB per program) of flash memory and 2kB of RAM, the system can be expanded with many other functionalities. Since a lot of text strings are used in the program implementation - names of menu items, etc., I used the F macro, which can be used to move these static strings to flash memory.

They do not unnecessarily take up space in RAM, which can be used more efficiently for more complex project functionality and other game modes that can be implemented in the future. The program logic of the counter is executed every 100ms. The time can be counted and displayed on the display in tenths of a second, but from the point of view of using the DOMINATOR project, which is organized into several hour or even daily events, a statement with a resolution of seconds is more than sufficient.

In the menu and configuration submenus, the treated values ​​are acquired by the encoder - counter, when it is not possible to set a value less than 0, there is no overflow of values. Because the button hold time is verified in game mode, a while loop is used to constantly monitor the state value of the input GPIO. The program logic of the time counter must also be inserted into this cycle so that the time does not stop. 

Because the Arduino is a single-core platform, it cannot handle two loops / tasks at the same time. In the case of dual-core platforms, such as ESP32, it is possible to use a system of tasks - angles that can be assigned to each core, and ESP32 can operate both loops at the same time.

More about the Configurable DOMINATOR project can be found at:

For the Configurable DOMINATOR project, there is a software implementation available in machine code (.hex) for the Arduino Uno / Nano platform, or a separate AtMega328P chip. The aim of the program - Shareware version of the project is to verify the compatibility of components (display communicating via I2C bus, functionality of switching buttons, response of the rotary encoder) for the subsequent use of the full version of the project.

The shareware version includes a 30-second system initialization (lazy loading) and subsequent possible stopwatch testing for a maximum measurable time of 1 minute. The stopwatch stops counting down time and does not respond to user buttons from the moment any team reaches a 1 minute occupancy point. 

From the configuration point of view in this free Shareware version, only the occupancy time of a point can be configured. The target time of the system - game time cannot be saved in EEPROM - it is only part of the full version of the project. The Shareware version does NOT include the COUNTDOWN game mode.

The firmware can be uploaded to Arduino via AVRDUDE - a console application used by Arduino IDE to load a compiled (machine code) program. Command to load sketch.ino.hex to COM port 21 (must be modified according to the firmware name and COM port where your Arduino is located): avrdude -CC: avrdude.conf -v -patmega328p -carduino -PCOM21 -b115200 -D - Uflash: w: sketch.ino.hex: i 

If you have no experience with AVRDUDE, try XLoader, which allows you to select the target firmware, target platform and COM port on which your Arduino board is located in a simple graphical interface. In the case of the Arduino Nano with OLD Bootloader, it is necessary to switch the upload speed to 57600 baud / s. Newer bootloaders support a upload speed of 115200 baud / s.

Shareware project firmware Configurable DOMINATOR (designed according to the wiring diagram in this article):

Information about the previous version - Button DOMINATOR and RFID version can be found at:

© 2021 Martin Chlebovec - Arduino Blog - . All rights reserved
Powered by Webnode Cookies
Create your website for free! This website was made with Webnode. Create your own for free today! Get started