산업 제조
산업용 사물 인터넷 | 산업자재 | 장비 유지 보수 및 수리 | 산업 프로그래밍 |
home  MfgRobots >> 산업 제조 >  >> Manufacturing Technology >> 제조공정

DIY LED 룰렛 게임 – 아두이노 나노로 만드는 1인 아케이드

부품 및 소모품

부품수량비고
LED (범용)9빨강 6, 노랑 2, 초록 1
SparkFun 푸시버튼 스위치 12mm1
Arduino Nano R31
암 헤더 8핀 1열 (0.1")1
DC 배럴 잭1

필요한 도구 및 장비

앱 및 온라인 서비스

프로젝트 개요

혼자서도 즐길 수 있는 간단하면서 재미있는 게임을 만들고 싶었습니다. 아두이노 나노 하나로 구동되는 LED 룰렛입니다. 목표는 움직이는 빛을 버튼으로 멈춰 초록 LED에 정지시키는 것. 빨강(6개)과 노랑(2개)은 피해야 합니다. 규칙도 제작도 매우 간단합니다.

개요

Fusion 360으로 전면 플레이트 설계(LED 9개 구멍 + 택트 스위치 구멍). Millright CNC 라우터로 합판 가공.

DIY LED 룰렛 게임 – 아두이노 나노로 만드는 1인 아케이드

게임 메커니즘

제작 과정

사포로 합판 마감 후 핫글루로 조립. 완성된 기기는 휴대용으로도 좋고, 멀티플레이 시 초록에서 떨어진 LED마다 점수 부여해 최저 점수자가 이기는 방식으로 확장 가능.

DIY LED 룰렛 게임 – 아두이노 나노로 만드는 1인 아케이드

DIY LED 룰렛 게임 – 아두이노 나노로 만드는 1인 아케이드

코드

TTBOUNCE 라이브러리 사용 (더블클릭/클릭 감지): GitHub

/* 핀 2-10 사용 */
#include 

int delay_time = 0;
const uint8_t led_array[9] = {4,3,5,6,7,8,9,10,11}; // LED 핀 배열
const uint8_t button = 2;
uint8_t difficulty = 0;
uint8_t current_led = 0;
bool dir_flag = true;      // true: 오른쪽, false: 왼쪽
bool game_ended = false;
bool is_win = false;
bool is_finished_selecting = false;

TTBOUNCE b = TTBOUNCE(button);

void doubleClick() {
  Serial.println("double click");
  is_finished_selecting = true;
  delay_time = floor(500/(difficulty+1)); // 난이도 공식: 500/(난이도+1) ms
  Serial.println("difficulty: " + String(delay_time));
  sweep();
}

void click() {
  Serial.print("Click | ");
  digitalWrite(led_array[difficulty], LOW);
  difficulty++;
  if(difficulty > 8) difficulty = 0;
  digitalWrite(led_array[difficulty], HIGH);
  Serial.println("Difficulty is: " + String(difficulty));
  delay(100);
}

void setup() {
  Serial.begin(9600);
  b.attachDoubleClick(doubleClick);
  b.attachClick(click);
  b.setActiveLow();
  b.enablePullup();
  
  for(int i=0; i<9; i++) pinMode(led_array[i], OUTPUT);
  sweep(); pulse();
  difficulty = 0;
  digitalWrite(led_array[difficulty], HIGH);
  
  while(!is_finished_selecting) b.update();
  b.update();
  
  pinMode(button, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(button), button_pressed, FALLING);
  delay(1000);
}

void loop() {
  if(!game_ended) {
    move_led();
    delay(delay_time);
  } else {
    Serial.println("Game over");
    if(is_win) {
      Serial.println("you won");
      for(int i=0; i<5; i++) { pulse(); delay(100); }
    }
    sweep();
    game_ended = false;
    is_win = false;
    delay(2000);
  }
}

void move_led() {
  digitalWrite(led_array[current_led], LOW);
  if(current_led == 8) { dir_flag = false; current_led--; }
  else if(current_led == 0) { dir_flag = true; current_led++; }
  else if(dir_flag) current_led++;
  else current_led--;
  digitalWrite(led_array[current_led], HIGH);
}

void pulse() {
  for(int i=0; i<9; i++) digitalWrite(led_array[i], HIGH);
  delay(100);
  for(int i=0; i<9; i++) digitalWrite(led_array[i], LOW);
}

void sweep() {
  for(int i=0; i<9; i++) { digitalWrite(led_array[i], HIGH); delay(50); digitalWrite(led_array[i], LOW); }
  for(int i=8; i>=0; i--) { digitalWrite(led_array[i], HIGH); delay(50); digitalWrite(led_array[i], LOW); }
}

void button_pressed() {
  Serial.println("Button pressed on LED: " + String(current_led));
  game_ended = true;
  if(current_led == 4) is_win = true;
  else is_win = false;
  current_led = 0;
  delay(500);
}

회로도

DIY LED 룰렛 게임 – 아두이노 나노로 만드는 1인 아케이드

제조공정

  1. 아두이노 나노와 MPU-6050으로 실시간 자이로스코프 게임 만들기
  2. 아두이노 디지털 주사위: LCD 기반 랜덤 넘버 제너레이터 만들기
  3. 아두이노 나노로 37개 LED 룰렛 게임 만들기
  4. DIY 아두이노 USB 게임 컨트롤러 - 나만의 고성능 게임패드 만들기
  5. 아두이노 나노로 테트리스 게임 만들기: DIY 16×8 LED 매트릭스
  6. 아두이노 블루투스로 LED 제어하기 - HC-05 & MIT App Inventor 입문 가이드
  7. 스마트 아두이노 4족 보행 로봇 제작: 단계별 완벽 가이드
  8. 픽셀 체이서: 아두이노 나노로 만든 인터랙티브 원탭 LED 게임
  9. 볼트 IoT와 아두이노 우노로 구현하는 무선 LED 밝기 제어 (PWM 6채널)
  10. 아두이노 8×8 LED 매트릭스 플립 시계 – DIY 실시간 시계 프로젝트