DIY LED 룰렛 게임 – 아두이노 나노로 만드는 1인 아케이드
부품 및 소모품
| 부품 | 수량 | 비고 |
| LED (범용) | 9 | 빨강 6, 노랑 2, 초록 1 |
| SparkFun 푸시버튼 스위치 12mm | 1 | |
| Arduino Nano R3 | 1 | |
| 암 헤더 8핀 1열 (0.1") | 1 | |
| DC 배럴 잭 | 1 | |
필요한 도구 및 장비
앱 및 온라인 서비스
프로젝트 개요
혼자서도 즐길 수 있는 간단하면서 재미있는 게임을 만들고 싶었습니다. 아두이노 나노 하나로 구동되는 LED 룰렛입니다. 목표는 움직이는 빛을 버튼으로 멈춰 초록 LED에 정지시키는 것. 빨강(6개)과 노랑(2개)은 피해야 합니다. 규칙도 제작도 매우 간단합니다.
개요
Fusion 360으로 전면 플레이트 설계(LED 9개 구멍 + 택트 스위치 구멍). Millright CNC 라우터로 합판 가공.

게임 메커니즘
- 불빛이 양 끝 사이를 왕복 이동
- 버튼 누르면 즉시 정지 (인터럽트 사용)
- 각 LED는 배열 인덱스에 매핑, 현재 LED 인덱스 별도 변수 관리
- 스텝 간 딜레이 = 난이도 (짧을수록 어려움)
- 시작 시 버튼 누를 때마다 딜레이 감소(난이도 상승), 더블 클릭으로 확정
- 정지 시 초록 LED(인덱스 4)면 승리, 아니면 패배
제작 과정
사포로 합판 마감 후 핫글루로 조립. 완성된 기기는 휴대용으로도 좋고, 멀티플레이 시 초록에서 떨어진 LED마다 점수 부여해 최저 점수자가 이기는 방식으로 확장 가능.


코드
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);
}
회로도
