Eleanor's Final Project

From CSclasswiki
Revision as of 16:57, 5 May 2020 by 270m (talk | contribs) (Schematic)
Jump to: navigation, search

Project Proposal

I am choosing to do the Arduino only option. My project idea is to utilize the 8x8 grid and the joystick to create the game Snake, and for Part 3 to use the 8x8 grid, the joystick, and the button to recreate space invaders.

Part 1: Name Print

The name printing aspect was a fairly straightforward introduction to using the 8x8 LED screen

Helpful Links

Video Tutorial with links to example code: https://www.youtube.com/watch?v=TOuKnOG8atk

Libraries

LedControl: https://randomnerdtutorials.com/guide-for-8x8-dot-matrix-max7219-with-arduino-pong-game/

Schematic

*All schematics using photos from https://www.arduino.cc/en/Tutorial/MultiSerialMega and https://educ8s.tv/arduino-8x8-led-matrix-tutorial/
Pt1scheme.png

Code

#include <LedControl.h>

int DIN = 12;
int CS =  11;
int CLK = 10;

//obtained binary letter values from : https://create.arduino.cc/projecthub/SAnwandter1/programming-8x8-led-matrix-23475a
byte A[] = {  B00000000,B00111100,B01100110,B01100110,B01111110,B01100110,B01100110,B01100110};
byte E[] = {B00000000,B00111100,B00100000,B00111000,B00100000,B00100000,B00111100,B00000000};
byte L[] = {B00000000,B00100000,B00100000,B00100000,B00100000,B00100000,B00111100,B00000000};
byte R[] = {B00000000,B00111000,B00100100,B00100100,B00111000,B00100100,B00100100,B00000000};
byte N[] = {B00000000,B00100010,B00110010,B00101010,B00100110,B00100010,B00000000,B00000000};
byte O[] = {B00000000,B00111100,B01000010,B01000010,B01000010,B01000010,B00111100,B00000000};


LedControl lc=LedControl(DIN,CLK,CS,0);

void setup(){
 lc.shutdown(0,false);       //The MAX72XX is in power-saving mode on startup
 lc.setIntensity(0,15);      // Set the brightness to maximum value
 lc.clearDisplay(0);         // and clear the display
}

void loop(){ 

    printByte(E);
     
    delay(1000);

    printByte(L);
    
    delay(1000);

    printByte(E);    

    delay(1000);
   
    printByte(A);    

    delay(1000);
    printByte(N);    

    delay(1000);
    printByte(O);    

    delay(1000);
    printByte(R);    

    delay(1000);
   
    lc.clearDisplay(0);
    
    delay(1000);
}


void printByte(byte character [])
{
  int i = 0;
  for(i=0;i<8;i++)
  {
    lc.setRow(0,i,character[i]);
  }
}


Part 2: Addition of Sensor - Snake Game

Description of Project

The inspiration for the project was the Snake genre of videogames, an overview of which is given here: https://en.wikipedia.org/wiki/Snake_(video_game_genre)

The basic rules of the game consist of a player-controlled pixel with a tail that grows in length by a single pixel each time the snake consumes an "enemy" pixel. The snake cannot self-intersect or fall off the edge of the map.

The final idea ended up utilizing the IR sensor in the Elegoo kit controlling the snake using the up/down/side arrow keys on a typical Comcast TV remote.

Libraries

LinkedList: https://github.com/ivanseidel/LinkedList IRremote : given by Elegoo kit included libraries IRremoteInt: given by Elegoo kit included libraries

Working Notes / Thought Process

-Tried to use vectors, cant use in arduino. Originally wanted to use some sort of hashmap to make lookup for enemy spawning faster, problem is that we need to make sure the enemy won’t spawn on the snake. -Instead I know the longest the snake could be is 64 units so it won’t be super inefficient to store the presized array. -Will just need to track size to find head and tail. -array wont work because I need to be able to erase from the tail, so the presized nature would make that inconvenient -use a linkedlist instead -couldn’t get array to work inside linked list, will just add row, col instead as separate ints - originally intended to use joystick sensor, but this ended up seeming inconvenient as well and not as true to the function of the joystick which can record a variety of positions between x = 0 --> 1024 and y = 0 --> 1024, allowing for less restricted movement - fun idea that works better with snake would be to use IR remote - IR remote included with Elegoo kit yields inconsistent results (same button shows multiple codes) so I decided to use my TV remote which I figured would be slightly more reliable

Helpful Links and Why They Are Helpful

Pong Game: https://randomnerdtutorials.com/guide-for-8x8-dot-matrix-max7219-with-arduino-pong-game/ - this link was helpful as it showed how a single LED could be manipulated, also showed that game simulation was possible using the Arduino and 8x8 matrix

IRremote Project: https://create.arduino.cc/projecthub/ingo-lohs/first-test-super-starterkit-from-elegoo-infrared-ab4272 - this link was helpful for digging into the function and usage of the IR remote sensor included with the Elegoo kit

How to Reset Arduino in Software: https://www.instructables.com/id/two-ways-to-reset-arduino-in-software/ - this link was helpful as I wanted to be able to have the game reset itself if the player lost. It didn't really matter if it was a software or hardware fix, but the software approach was easy enough and obviously included no additional hardware

=