Go Down

Topic: Snake on an 8x8 LED matrix (Read 434 times)previous topic - next topic

Snailbob12765

Jun 20, 2018, 12:15 am
For a county fair project, I want to make a console using an Arduino, 2 buttons, and a dot matrix. So far I have a home screen where you can select what game you want, a flappy bird/temple run-type game (called pipes in the code), and pong. I want to implement snake, but have no clue how to approach it. The ways I've tried have failed. Could someone help? I'm just looking for the abstract, not the code

Specifications for how I programmed this:

I did this on an Uno, using 16 of the 18 available pins to control the matrix, and the 2 remaining for buttons.

For my scanning method, you encode each binary line in decimal form in an array called "dataInt[]". To draw a smiley face, you'd do this:
Code: [Select]
`    dataInt[0] = 0;  //00000000    dataInt[1] = 36; //00100100    dataInt[2] = 36; //00100100    dataInt[3] = 36; //00100100    dataInt[4] = 0;  //00000000    dataInt[5] = 66; //01000010    dataInt[6] = 60; //00111100    dataInt[7] = 0;  //00000000`
On that topic, I should probably show you the full code for a simple display of alternating smile and frown.
Code: [Select]
`int ledH[] = {2,3,4,5,6,7,8,9};int ledV[] = {10,11,12,13,A0,A1,A2,A3};int dataInt[] = {0,0,0,0,0,0,0,0};int counter = 0;void setup() {  for(int i = 0; i < 8; i++) {    pinMode(ledV[i], OUTPUT);    pinMode(ledH[i], OUTPUT);  }}void loop() {  for(int j = 0; j < 1700; j++) {    counter = 0;    dataInt[0] = 0;  //00000000    dataInt[1] = 36; //00100100    dataInt[2] = 36; //00100100    dataInt[3] = 36; //00100100    dataInt[4] = 0;  //00000000    dataInt[5] = 66; //01000010    dataInt[6] = 60; //00111100    dataInt[7] = 0;  //00000000    for(int a = 0; a < 8; a++) {      display();    }  }  for(int j = 0; j < 1700; j++) {    counter = 0;    dataInt[0] = 0;  //00000000    dataInt[1] = 36; //00100100    dataInt[2] = 36; //00100100    dataInt[3] = 36; //00100100    dataInt[4] = 0;  //00000000    dataInt[5] = 60; //00111100    dataInt[6] = 66; //01000010    dataInt[7] = 0;  //00000000    for(int a = 0; a < 8; a++) {      display();    }  }}void display() {  for(int i = 0; i < 8; i++) {    if(bitRead(dataInt[counter], i) == 0) {      digitalWrite(ledV[i], HIGH);    } else {      digitalWrite(ledV[i], LOW);    }  }  digitalWrite(ledH[counter], HIGH);  digitalWrite(ledH[counter], LOW);  counter = counter + 1;}`
If you looked at that, you'd notice it scans top down, but the dataInts go from low to high, so the Y for X,Y is inverted, if that makes sense. For better understanding, if I encoded the X,Y pos for a point, like a pong ball, then I'd -1 to Y to go up and +1 to go down (I did this). Speaking of which, I should show you the code for my console so far.