Release 2016.8.28 / Update 2017.6.26

“Shooter” game on Arduino

I have explained about “How to avoid from chattering by a programming” in my article, and I made a game sketch as sample. I was allowed to further develop it. All you need is a switch. You can play the game by using serial monitor of Arduino IDE. You can also enjoy with children.

I wrote a chattering-less switch library with “gauging” method.
(26.6.2017)

Super easy barrage shooting game “SHOOTER”

Minimum Requirements

PC Arduino(confirmed operation in the Arduino UNO) A momentary switch

Wiring

It is very simple. No resistor, because of inside pullup. shu_watch_simple_wiring

How to play

Connect to PC your Arduino and write “shooter” sketch. Then open Serial monitor in your IDE. Rule is simple. Push the switch a lot of times during 10 seconds. There are 3 count before you start.(Also LED of 13 pin tells you the count.)。Aim a high score. Push a switch for a long time, if you want to cancel the game. Your best score is memorized in EEPROM. So, it remains even if you turn off the electricity. Push a switch before you set power on, if you reset the best score.    

Tuning

You can adjust balance of chattering by change value of ‘PUSH_SHORT’. You can know the proper value using a sketch below. Chattering is very small value. So check the chattering value not to over ‘PUSH_SHORT’.

#define SW 4
#define PUSH_SHORT 700
unsigned long intvl = 0;

void setup() {
  pinMode(SW, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop() {
  unsigned long gauge = 0;
  while (!digitalRead(SW)) gauge++;
  if (gauge > 1)
  {
    char cate[2][5] = {"PUSH", "CHTT"};
    bool jdg    = (gauge <= PUSH_SHORT) ? 1 : 0;
    Serial.print(cate[jdg]);
    Serial.print(":");
    Serial.println(gauge);
    intvl = millis();
  }

  if ((millis() - intvl) > 1000)
  {
    Serial.println();
    intvl = millis();
  }
}

Extend

If you add some parts, you can enjoy it like retro game. shu_watch2_ex_parts

LED

LED illumination is fun to know status. It is extend as 13 pin LED.

buzzer(piezo speaker)

“Shooter” makes several sounds. Those are very cheap sound, but effective. Use resistor if the sound loud.

8*2 Character LCD screen(I2C)

It is more effective if you connect it to LCD.

Wiring(Extended)

shu_watch_wiring   Why don’t you make a portable game by extra battery?

“SHOOTER” Sketch


Please enjoy.

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA


This site uses Akismet to reduce spam. Learn how your comment data is processed.