Pages: [1]   Go Down
Author Topic: Skill Stop Game (Noob's First Project)  (Read 2158 times)
0 Members and 1 Guest are viewing this topic.
England - UK
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am completely new to Arduino (and programming to that fact), although I have been reading the forum every day for about 3 months now! Learning and absorbing as much as I can, for which I thank the Arduino Community immensly for!! Without this support I would not have been able to even attempt this project, let alone finish it!

My first Arduino Project is a Skill Stop Game consisting of 7 Leds which flash from Left to Right and then back down, Right to Left. The idea is to push the button when either of the 2 Green Leds are lit. A successful hit will increase the speed by 10%. An unsuccessful hit will stop the sequence on the incorrect Led and display the 'level' reached in the Serial Monitor (along with a silly message).

I've also no experience with Electronics, but wanted to build something a little more permanent, without having to incorporate additional Microcontrollers (I think thats abit advanced for me at this stage). So I decided to use VeroBoard with Female Headers at one end enabling me to simply hook up the Arduino with Jumper Wires as and when I wanted to show-off, I mean use it!

I thought I'd share this project to give my fellow 'noobs' an idea of how someone with literately no knowledge in this field, can actually build a working project (even if this is relatively simple)! Pictures and Video below... Please feel free to add any comments and feedback, I'd love to learn 'what I did wrong' and  'what could be better' etc...




Code:
/*
Skill Stop Sketch correct hit increases Speed by 10%.
*/

int ledPins[] = {3, 14, 15, 16, 17, 18, 19}; // Have used Analog Pins as this was easier to set up on Arduino
int delayTime = 250; // Starting Led Speed
int level = 1; // Start at Level 1
boolean greenLed = false; // Boolean to define when greenLed is on
boolean gameOver = false; // Boolean to define when Game Over

void buttonPush(); // Function for interrupt

void setup() {           
  pinMode(2, INPUT);
  for(int i=0; i<7; i++){
  pinMode(ledPins[i], OUTPUT);
  }
  attachInterrupt(0, buttonPush, FALLING);
  Serial.begin(9600);
}

void loop() {
  if(gameOver == true){ // Game Over sequence
    Serial.print("You Reached Level: "); // Display level reached
    Serial.println(level);
    if(level>0 && level<11){
      Serial.println("You can do better than that!"); // Message for score less than 11
    }
    if(level>10 && level<16){
      Serial.println("A worthy effort!"); // Message for score over 11 and less than 16
    }
    if(level>15 && level<21){
      Serial.println("You're a machine!"); // Message for score over 15 and less than 21
    }
    if(level>20){
      Serial.println("Unreal!"); // Message for score over 20
    }
    delay(3000);
    for(int i=0; i<7; i++){ // Flash all Leds to start Game
    digitalWrite(ledPins[i], LOW);
    }
    delay(200);
    for(int i=0; i<7; i++){
    digitalWrite(ledPins[i], HIGH);
    }
    delay(200);
    for(int i=0; i<7; i++){
    digitalWrite(ledPins[i], LOW);
    }
    delay(200);
    for(int i=0; i<7; i++){
    digitalWrite(ledPins[i], HIGH);
    }
    delay(200);
    for(int i=0; i<7; i++){
    digitalWrite(ledPins[i], LOW);
    }
    delay(200);
    for(int i=0; i<7; i++){
    digitalWrite(ledPins[i], HIGH);
    }
    delay(200);
    for(int i=0; i<7; i++){
    digitalWrite(ledPins[i], LOW);
    }
    level = 1; // Reset Level to 1
    delayTime = 250; // Starting delay time
    gameOver = false; // Set Game Over to false
    delay(500);
   }
   
  if(gameOver == false){ // Check Game Over indicator before each Led (this ensures Game ends immediately as an interrupt returns to the position it left off)
    digitalWrite(3, HIGH);
    delay(delayTime);
  }   
  if(gameOver == false){
    digitalWrite(14, HIGH);
    delay(delayTime);
  }
  if(gameOver == false){
  digitalWrite(15, HIGH);
    delay(delayTime);
  }
  if(gameOver == false){
  digitalWrite(16, HIGH);
    delay(delayTime);
  }
  if(gameOver == false){
  digitalWrite(17, HIGH);
    delay(delayTime);
  }
  if(gameOver == false){
  greenLed = true; // Set greenLed True to use during interrupt (correct hit)
  digitalWrite(18, HIGH);
    delay(delayTime);
  }
  if(gameOver == false){
  digitalWrite(19, HIGH);
    delay(delayTime);
  }
  if(gameOver == false){
  digitalWrite(19, LOW);
    delay(delayTime);
  }
  if(gameOver == false){
  digitalWrite(18, LOW);
  greenLed = false; // Set greenLed False to use during interrupt (incorrect hit)
    delay(delayTime);
  }
  if(gameOver == false){
  digitalWrite(17, LOW);
    delay(delayTime);
  }
  if(gameOver == false){
  digitalWrite(16, LOW);
    delay(delayTime);
  }
  if(gameOver == false){
  digitalWrite(15, LOW);
    delay(delayTime);
  }
  if(gameOver == false){
  digitalWrite(14, LOW);
  }
}

void buttonPush(){ // Button push interrupt
  static unsigned long last_interrupt_time = 0;
  unsigned long interrupt_time = millis();
  if (interrupt_time - last_interrupt_time > 300){ // Debounce
    if(greenLed == true){ // If Button pushed during greenLed True
      delayTime = delayTime * 9 / 10; // Increase Delaytime by 10%
      level++; // Increase level by 1
    }
    else{
     gameOver = true; // If greenLed is not true, it must be false, hence set Game Over as True
    }
    last_interrupt_time = interrupt_time;
  }
}


* P5160003.JPG (102.98 KB, 480x640 - viewed 28 times.)
Logged

Portland, OR
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You sir make me cry if you consider that a Noob project. I agree its not the highest tech I've seen on the boards, but I just got excited over a 10 LED Light meter I made. This blows that completely and utterly out of the water. In fact, my most recent project of making a game with no objective other than to scroll LEDs with 2 arcade buttons I salvaged was the peak of my pride, and now after seeing this, my pride, is crushed. This is awesome, very clean looking, and well scripted (including the messages.) I'm really new to the circuits how did you set your LEDs  up like that? I want to learn!
Logged

Damn the Man, Save the Empire

England - UK
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For me, it was all about starting from the basics and then improving my code as I went (believe me, I was over the moon for days when I first got the leds to light up in sequence like that!!)... This Final version ended up being about version 5 (with 1.1, 1.2, 1.3 etc etc in between ha (it took me weeks to get to this by the way))! I'm in the office at the moment, but when I get home I will post my version 1 for reference, just to show how it started. For the circuit, I used Veroboard which has all the vertical holes linked underneath (with copper strip, I think), meaning that the positive side of the Led links to the female header at the top of its vertical column.  For the negative side this links to the little bit of white wire below the Led (via a resistor), which then links to the Ground (on the far left)…
Logged

England - UK
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@seckela
Apologies for 'crushing your pride’!! What you have already achieved is still amazing. It took me a hell of alot of time to complete this project, and it was all from reading this forum, literately everyday, trying to work things out based on previous posts (i.e. how the hell an interrupt works!!!). As mentioned I started by first getting the leds to light up in sequence and then adding more and more complexity a little bit (very little bit) at a time! Keep at it!! Its really addictive!!
Logged

Netherlands
Offline Offline
Full Member
***
Karma: 0
Posts: 132
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice idea, well executed. Looks cool smiley.

Ideas for extension smiley-wink:
- Include an ATMega328 DIP on the board itself so it can run independent from the Arduino link
- Include a LCD for the messages, you might need a ShiftRegister because there are not enough pins available (LCD takes a lot of pins)
- Store highscore in EEPROM smiley-wink
- Put it in an enclosure

Coming from someone who has yet to finish any project smiley-razz.
Logged

Portland, OR
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah it is extremely addictive. I've been spending late nights just reading about projects and other people's work. So to learn something more maybe you can help me:

The way you have your LEDs set up and the jumper set on the board, how many pins are controlling the LED's them self? If its 1 Arduino Pin per LED then nevermind, I know how to do that. I've been looking into learning about shift registers and multiplexing, but I have no idea where to start, and your board, if using an idea like that, seems a good start.
Logged

Damn the Man, Save the Empire

England - UK
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That’s right, 1 Arduino Pin per Led… I haven’t ventured in to Multiplexing yet, sounds interesting though… Will have a read up…
Logged

Portland, OR
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dammit all to hell. Alright well fair enough, still excellent project sir!
Logged

Damn the Man, Save the Empire

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you upload a diagram so I can have a look at it and maybe even try and have a go to make it? I think it's really cool and not much of a noob project! Thanks,
George
Logged

Pages: [1]   Go Up
Jump to: