Project tutorial
LED Roulette Game

LED Roulette Game © GPL3+

A fun pocket-sized travel game for any age. Try your luck and make the light stop on the green LED.

  • 10,211 views
  • 4 comments
  • 24 respects

Components and supplies

Necessary tools and machines

CNC Router

Apps and online services

About this project

Video:

Overview

For quite a while I have been wanting to create a simple, yet fun game that only requires one person to play. It is extremely simple, only taking one Arduino Nano to run it. It is LED roulette. The object of the game is to stop on the green LED, avoiding the red and yellow ones. Seems easy to play and make, and it is.

Step 1

First, I began by designing the device in Fusion 360. I designed the front plate to contain 9 LEDs, 6 red, 2 yellow, and 1 green. I also made a space for a tact switch to go at the bottom. I then used the my Millright CNC router to cut out the pieces that I designed.

Step 2

The game mechanics go like so: A light will "move" back and forth between the two edges, and will stop whenever there is a button press. In order for it to react immediately, I used an interrupt. Each LED corresponds to an index in an array that gets cycled through. the current LED index gets its own variable as well. There is also a delay between each step, corresponding to the difficulty. On startup, the user selects the difficulty by pushing the button to reduce the delay between each change of the LED. After the correct LED is lit up, the user can double click to lock it in.

Step 3

I used some sandpaper to add a nice finish and rounding to the plywood pieces. After that, I used hot glue to fasten the pieces together.

Conlusions

Now, whenever I am in the mood to play a simple game, whether for the road or just to get away from a screen, this device gives me a wonderful reprieve. I can also make it multiplayer by making each LED away from green a certain amount of points, making the person who got the least amount of points at the end wins.

Code

CodeC/C++
/*Use pins 2-10
You can get the TTBOUNCE library here: https://github.com/TOLDOTECHNIK/TTBOUNCE
*/
#include <TTBOUNCE.h>

int delay_time = 0;
const uint8_t led_array[9] = {4,3,5,6,7,8,9,10,11};
const uint8_t button = 2;
uint8_t difficulty = 0;
uint8_t current_led = 0;
bool dir_flag = true; //true goes right, false goes left
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)); //Formula: delay (in ms) = 500 / (difficulty + 1)
  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==false){
		move_led();
		delay(delay_time);
	}
	else if(game_ended){
    Serial.println(game_ended);
    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 -= 1;
	}
	
	else if(current_led == 0){
		dir_flag = true;
		current_led += 1;
	}
	
	else if(dir_flag){
		current_led += 1;
	}
	
	else if(!dir_flag){
		current_led -= 1;
	}
	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 if(current_led != 4){
		is_win = false;
	}
 current_led = 0;
 delay(500);
}

Schematics

Schematic
Schematic bb pegir3304u

Comments

Similar projects you might like

Arduino Pocket Game Console + A-Maze - Maze Game

Project tutorial by Alojz Jakob

  • 5,316 views
  • 7 comments
  • 18 respects

Snake LED Matrix Game

Project tutorial by Team Arduino bro

  • 2,551 views
  • 0 comments
  • 4 respects

Bluetooth control led with lcd led status display real time.

Project tutorial by Youssef Sabaa

  • 17,292 views
  • 4 comments
  • 34 respects

MAX72XX LED matrix display asteroids game

Project tutorial by kreck2003

  • 1,965 views
  • 2 comments
  • 14 respects

LED Dice

Project showcase by EvdS

  • 14,276 views
  • 11 comments
  • 49 respects

LED Emergency Lights using WS2812 RGB LED Module

Project tutorial by bigboystoys13

  • 10,004 views
  • 5 comments
  • 20 respects
Add projectSign up / Login