0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ESP32マイコン搭載のAtomS3Rを使ったイライラ棒ゲームの作り方

0
Last updated at Posted at 2026-08-19

概要

 ESP32マイコン搭載のAtomS3Rを使って、イライラ棒ゲームを製作する方法をご紹介します。タイム計測、クラッシュ表示、ブザー動作など、数多くの演出とともにゲームを楽しむ事ができます。
簡単に製作できますので、是非マイコン学習等にお使いください。

4.png

部品リスト

 使用部品は以下です。リンクを載せますが、2026/8/19時点のリンクですので、今後削除される可能性あります。ご参考までに。

AtomS3R
ブザー


接続

 配線の接続手順等はこちらの動画内で紹介しております。是非ご覧ください。
(2026/8/21公開予定)


 https://www.youtube.com/channel/UCmMiial_to0sEagnPoYHSNA

プログラム例

プログラム例を紹介いたします。
AtomS3Rの画面をクリックすると、タイム計測をスタートし、もう一度クリックすると停止します。
G5端子を出力にし、ブザーを接続して鳴らしています。
G6端子を入力にしイライラ棒を接続します。コース側をGNDに接続しておき、イライラ棒がGNDに接触したらブザーが鳴り、画面に「Crash!」の文字表示とともに、タイムに10秒加算する動きとしています。

#include "M5Unified.h"

int game_start=0;
int s10_cnt=0;
int s_cnt=0;
int m_cnt=0;

void setup() {
  M5.begin();
  pinMode(5, OUTPUT);   //buzzer output
  pinMode(6, INPUT);    //iraira stick input
  pinMode(6, INPUT_PULLUP);
  M5.Display.setRotation(1);
  M5.Lcd.fillScreen(TFT_BLACK);
  M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
  M5.Lcd.setCursor(0, 0);
  M5.Lcd.setTextSize(2);
  game_start=2;
}

void loop() {
  M5.update();

  if (M5.BtnA.wasPressed()) {
    game_start=game_start+1;
  }

  // Game Start ////
  if(game_start==1){
    delay(100);
    s10_cnt=s10_cnt+1;
    if(s10_cnt>9){
      s10_cnt=0;
      s_cnt=s_cnt+1;
    }
    if(s_cnt>59){
      s_cnt=0;
      m_cnt=m_cnt+1;
    }
    M5.Lcd.setCursor(0, 30);
    M5.Lcd.printf("\n\n %d:%d:%d00\n", m_cnt,s_cnt,s10_cnt);

    if (digitalRead(6) == LOW){   //crash judgement
        digitalWrite(5, HIGH);
        M5.Lcd.fillScreen(TFT_YELLOW);
        M5.Lcd.setTextColor(TFT_RED, TFT_YELLOW);
        M5.Lcd.setCursor(0, 0);
        M5.Lcd.printf("\n\n\n  Crash!!\n\n");
        delay(2000);
        s_cnt=s_cnt+12;   //+10-second penalty
        if(s_cnt>59){
          s_cnt=s_cnt-60;
          m_cnt=m_cnt+1;
        }
        digitalWrite(5, LOW);
        M5.Lcd.fillScreen(TFT_BLUE);
        M5.Lcd.setTextColor(TFT_WHITE, TFT_BLUE);
    }
  }

  // Game Stop ////
  if(game_start==2){
      delay(100);
      M5.Lcd.fillScreen(TFT_RED);
      M5.Lcd.setCursor(0, 0);
      M5.Lcd.setTextColor(TFT_WHITE, TFT_RED);
      M5.Lcd.printf("\n<< Stop >>\n\n");
      M5.Lcd.printf("\n %d:%d:%d00\n", m_cnt,s_cnt,s10_cnt);
    }

  // Game Ready ////
  if(game_start==3){
      M5.Lcd.fillScreen(TFT_BLACK);
      M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
      M5.Lcd.setCursor(15, 0);
      M5.Lcd.setTextSize(18);
      M5.Lcd.printf("3");   
      delay(1000);
      M5.Lcd.setCursor(15, 0);
      M5.Lcd.printf("2");   
      delay(1000);
      M5.Lcd.setCursor(15, 0);
      M5.Lcd.printf("1");   
      delay(1000);
      M5.Lcd.setCursor(0, 0);
      M5.Lcd.setTextSize(2);
      M5.Lcd.fillScreen(TFT_BLUE);
      M5.Lcd.setTextColor(TFT_WHITE, TFT_BLUE);
      M5.Lcd.printf("\n<< Go!! >>\n\n");   
      s_cnt=0;
      m_cnt=0;
      game_start=1;
    }
}

動作説明、ゲームの仕方

 AtomS3RにUSB電源を接続します。そうすると画面上に「Stop」の文字が表示されます。
画面上を一度押すと、「3,2,1」とカウントダウンが始まり、ゲームがスタートします。
スタートするとタイム計測が始まります。
イライラ棒を持って、ゴールをめざしてください。
イライラ棒がコースに接触すると、タイムに10秒加算されてしまいます。
ゴールまで到達したら、再度画面を押すと、タイム計測が止まります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?