LED CHASER Project
Hello my name is Jason Jassal, today for my final project in tech class I've created this led chaser game inspired by Vigas B’s Led chaser game.
This game has 7 leds flashing in a cycle and your objective is to win by getting 10 points, but you can also lose when you get to -10 points.
I have recreated this circut on tinkercad for easier visuals
https://www.tinkercad.com/things/0MrrMKk8ETN-amazing-albar
Enjoy :)
Supplies
1. 555 Timer x1
2. Johnson's Decade Counter x1
3. Arduino Uno x1
4. 4 Digit Seven Segment Display (prefered version 1.2) x1
5. Potentiometer (10k) x1
6. Assorted LEDs 3 red 2 yellow 2 green
7. Pushbutton x1
8. Resistors (x1 560 Ohms, x1 10K Ohms, x1 1K Ohms)
9. Electrolytic Capacitor (10 uF) x1
10. Wires
11. Male and Female wire 4x
( male and female connectors)
https://www.amazon.ca/breadboard-jumper-wires-female-male-Enchantant/dp/B098JS3HBZ/ref=asc_df_B098JS3HBZ?mcid=6e37763f3ca13fc4843cca86a3fd7536&tag=googleshopc0c-20&linkCode=df0&hvadid=706724917098&hvpos=&hvnetw=g&hvrand=10756907629537970810&hvpone=&hvptwo=&hvqmt=&hvdev=c&hvdvcmdl=&hvlocint=&hvlocphy=9000844&hvtargid=pla-2402231206932&psc=1&hvocijid=10756907629537970810-B098JS3HBZ-&hvexpln=0&gad_source=4
Connecting Base Components
For step one you want to have both 555 time and jhonson decade counters placed in a way where the middle of the bread board separate 2 rails, and then you want to line your LEDs up on the north side of the bread board since in the further steps you will need them there.
Creating the Main Wire Connections
In this step i decided to finish off all the major components needed, and started to wire up my Johnson decade counters with the corresponding LEDS so make that 1,2,3,4,5,6,7 cycle.
In this step make sure to properly have your LEDS set up as it might be difficult to understand how there wired in this photo so please take a look at the schematic.
Arduino Connections.
In this step, you should now get your Arduino, and mini bread board and make your CLK and DIO connections for your 4 digit display, and make your Arduino digital pin connections to finish up the wiring part of this project.
Coding
For this step, ill leave my currently made code in a file here, but in terms on explaining the code and mechanism
its a led flasher game where the arduino doesn't control the leds but rather reads when there high and low which is then inputted with the push button when pressed. The objective is to click the target as in the serial monitor using a 4 loop segment it creates a infinite cycle of targets until you either win or lose. This score is then displayed in the 4 digit display in either negatives if your losing or positives in your winning.
For help my code will be left in the bottom here but i recommend you creating your own code.
(PS: please download the tm1637 display libary if you use the version 1.2 4 digit display.)
#include <TM1637Display.h>
#define CLK_PIN 4
#define DIO_PIN 6
TM1637Display display(CLK_PIN, DIO_PIN);
const int ledPins[7] = {11, 12, 10, 8, 13, 7, 9};
const int buttonPin = 2;
int score = 0;
int target = 0;
bool shown = false;
void setup() {
Serial.begin(9600);
for (int i = 0; i < 7; i++) pinMode(ledPins[i], INPUT);
pinMode(buttonPin, INPUT);
display.setBrightness(7);
display.clear();
randomSeed(analogRead(0));
newTarget();
showScore();
}
void loop() {
if (!shown) {
Serial.print("Target: ");
Serial.println(targetName());
shown = true;
}
if (buttonPressedStable()) {
int active = getActiveLED();
bool correct = (active != -1) && isCorrect(active);
if (correct) {
score++;
Serial.println("Correct!");
showScore();
correctCelebration();
} else {
score--;
Serial.println("Wrong!");
showScore();
delay(250);
}
if (score >= 10 || score <= -10) score = 0;
Serial.print("Score: ");
Serial.println(score);
showScore();
newTarget();
}
}
void newTarget() {
target = random(0, 3);
shown = false;
}
String targetName() {
if (target == 0) return "Red";
if (target == 1) return "Yellow";
return "Green";
}
int getActiveLED() {
for (int i = 0; i < 7; i++) {
if (digitalRead(ledPins[i]) == HIGH) return i;
}
return -1;
}
bool isCorrect(int i) {
if (target == 0) return (i == 0 || i == 3 || i == 6);
if (target == 1) return (i == 1 || i == 4);
return (i == 2 || i == 5);
}
bool buttonPressedStable() {
if (digitalRead(buttonPin) != LOW) return false;
delay(30);
if (digitalRead(buttonPin) != LOW) return false;
while (digitalRead(buttonPin) == LOW) {
delay(5);
}
return true;
}
void showScore() {
int val = abs(score);
if (val > 9) val = 9;
uint8_t segs[4] = {0, 0, 0, 0};
if (score < 0) segs[0] = 0x40;
else segs[0] = 0x00; // blank
segs[1] = display.encodeDigit(val);
display.setSegments(segs);
}
void correctCelebration() {
uint8_t allOn[4] = {0x7F, 0x7F, 0x7F, 0x7F};
uint8_t allOff[4] = {0x00, 0x00, 0x00, 0x00};
for (int i = 0; i < 4; i++) {
display.setSegments(allOn);
delay(120);
display.setSegments(allOff);
delay(120);
}
showScore();
}