SNAKE GAME

LED 8X8 MATRIX

Overview

For this project we were tasked to create an interactive game using the 8x8 LED matrix from our parts kit. Part of this was also to create an interactive and inventive input to use for the game. We decided to create the classic snake game on the LED matrix. Rather than using the 4 buttons as is common with this game, we created a new input device. It utilizes lazy Susan hardware, magnets, and HAL sensors to make steering wheel type input device.

Fig1 : Snake Game

Fig2 : Connection for the Game

Demonstration of the Game

Materials and Parts

A table with estimated costs of your materials and parts and links to the source material at an online store such as sparkfun.com, adafruit.com, digikey.com, etc. The last row should provide the total cost.



Schematic

Fig3 : Schematic Diagram for circuit

Challenges
  • Getting the delay for the LED matrix to work. The LED matrix needs to update constantly since it only has one row on at a time. The game shouldn’t update this fast, however. Had to loop over the LED matrix code and then only check the game conditions every now and then.

  • Getting the button to act as an interrupt. We hadn’t ever worked with interrupts before in Arduino. They aren’t too difficult but had to learn how to implement them. Took a while to figure out that only certain pins can have interrupts attached to them.

  • Scrolling text across the screen. It wasn’t very difficult once we got the idea down. Making the matrices that hold the words was the most time-consuming part. Because of the way input variables to functions work we had to create the matrices each with 8 columns rather than 8 rows. This made it harder to figure out the correct bits to use.

Future Work Ideas
  • Add different difficulties. Use the input device and button to select them.

  • Add levels. Each level might have a certain number of food to pick up and they disappear after some time.

  • Add the green LEDs for the food.

  • Add a timer to see how fast you can do it.

  • Add leaderboard.

Thoughts about Project

We really enjoyed this project. It was a good way to think outside of the box. The coding of the actual game play wasn’t very hard, but the goal to create an intuitive and innovative input device was exciting. We had the ability to explore all the possibilities and we are happy with the outcome. It was reinforced to us that the first idea that comes to mind isn’t always the best. We started out by thinking that pushbuttons or a joystick would be best. These are intuitive, but they aren’t very innovative. We then moved on to a wheel approach which is commonly done with potentiometers. This wouldn’t work, however, because of the need to go 360 degrees. The we devised the new approach with the HAL sensors and lazy Susan such that we were able to create an intuitive design with some innovation.

Links to Inspirations, Code Libraries, and Code Samples 

Information on how to structure the matrices for scrolling text - https://howtomechatronics.com/tutorials/arduino/8x8-led-matrix-max7219-tutorial-scrolling-text-android-control-via-bluetooth/

Information on how to attach interrupts to pins -https://www.tutorialspoint.com/arduino/arduino_interrupts.htm

Code for looping over the rows on the LED Matrix - https://bitbucket.org/nerdfirst/arduino-8x8-basics/src/master/Smiley/

void loop() {

  for (int i=0; i<8; i++) {

    if (i==0) {

      digitalWrite(9, LOW);   

    }

    else {

      digitalWrite(i+1, LOW);

    }

 

    for (int j=0; j<8; j++) {

      if (data[i][j] == 1) {

        digitalWrite(j+22, LOW);

      }

      else {

        digitalWrite(j+22, HIGH);

      }

    }

    digitalWrite(i+2, HIGH);

 

    delay(analogRead(A0) / 10);

  }

}

COSC 594

Arduino Nano

Hal Sensor

Push Button

Wooden Plaque

Magnet

LED 8X8 Matrix

Lazy Susan Hardware

Wooden Knobs

Devanshi Patel || Eric Kibry