AGGIORNAMENTO:
Il codice che metterò qua di seguito l'ho trovato su internet e permetteva di giocare a snake con una matrice 8x8, dichiarata da voi diversa dalle strip led ws2812 che però, almeno teoricamente, in base alla mia scoperta, risultano uguali e identiche.
Fatto sta che, comunque, ho modificato il codice qua di seguito per farlo funzionare con una matrice 10x10.. Ma ora funziona perfettamente solo con una 8x8, lasciando quindi gli altri led spenti.
Idee?
#include <Adafruit_NeoPixel.h>
#define PIN 2 //Output Pin
#define MAX_LED 100 //Quantity of bead
uint32_t c;
int a = 0 , number;
unsigned char huan = 0, ci = 0;
unsigned char u = 40; //The font size of word group
unsigned char x = 0;
unsigned char Colour[3];
unsigned char go[] = {2, 3, 4, 5, 9, 14, 17, 20, 22, 26, 27, 29, 34, 35, 36, 37, 41, 46, 49, 54, 58, 59, 60, 61}; //24
unsigned char light[10][10] = {
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
{19, 18, 17, 16, 15, 14, 13, 12, 11, 10},
{20, 21, 22, 23, 24, 25, 26, 27, 28, 29},
{39, 38, 37, 36, 35, 34, 33, 32, 31, 30},
{40, 41, 42, 43, 44, 45, 46, 47, 48, 49},
{59, 58, 57, 56, 55, 54, 53, 52, 51, 50},
{60, 61, 62, 63, 64, 65, 66, 67, 68, 69},
{79, 78, 77, 76, 75, 74, 73, 72, 71, 70},
{80, 81, 82, 83, 84, 85, 86, 87, 88, 89},
{99, 98, 97, 96, 95, 94, 93, 92, 91, 90},
};
unsigned char character[][10] = //Set the word to be sent
{
{0, 1, 1, 1, 1, 1, 0, 0, 0, 0},
{0, 1, 0, 0, 0, 1, 0, 0, 0, 0}, // 0
{0, 1, 1, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 1
{0, 1, 1, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0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},
};
unsigned char displayscore [10][10];
int speedS = 400; // Initial speed of snake
int score; // Game score
int xValue; // JoyStick-X
int yValue; // JoyStick-Y
int zValue; // JoyStick-Z
int FX, FY; // Coordinate of food
int SX, SY; // Coordinate of snake head
int KEY, K;
int Enabled; // Enable to restart game
char sx[100] ; //Coordinate of snake body
char sy[100];
Adafruit_NeoPixel strip = Adafruit_NeoPixel( MAX_LED, PIN, NEO_RGB + NEO_KHZ800 );
void RANDOM() {
A:
FX = random(0, 9);
FY = random(0, 9);
for (int i = 0; i < 3 + score; i++) //Prevent food display on snake body
{
if ( FX == sx[i] && FY == sy[i])
goto A;
}
}
void myDelay( unsigned int Time) { // During the delay period of snake movement, we have to do something like food glitter and read the direction of Joystick
for (int t = 1; t <= Time; t++)
{
joyStick();
delay(1); //Read the direction of Joystick
}
}
void joyStick() {
xValue = analogRead(A0); // JoyStick-X The leftmost value is 0, the rightmost value is 1023, and the middle value is 515.
yValue = analogRead(A1); // JoyStick-Y The bottom value is 0, the top value is 1023, the middle value is 510.
if (yValue > 950 && KEY != 5) {
K = 8;
}
else if (yValue < 50 && KEY != 8) {
K = 5;
}
else if (xValue < 50 && KEY != 6 && K != 0) { // Before operate Joystic for the first time, you can't move snake to the left direction.
K = 4;
}
else if (xValue > 950 && KEY != 4) {
K = 6;
}
}
// Here you can compare whether the direction of keypad is opposite to the snake move direction. If it is opposite, then give up the keypad.
/***************************************************************************************************************************************************************************************************************/
void gameover() { // Once Gameover program stopped, press the central button to restart the game.
unsigned char value, y;
Colour[0] = random(3 , 18); // Set color.Parameter is R G B, range 0-255.
Colour[1] = random(3, 18);
Colour[2] = random(3, 18);
c = strip.Color(Colour[1], Colour[0], Colour[2]);
value = score / 10;
value = value * 4;
y = 0;
for (number = value; number < value + 4; number++)
{
for (unsigned char vertical = 0; vertical < 10; vertical++)
{
displayscore[y][vertical] = character[number][vertical];
}
y++;
}
value = score % 10;
value = value * 4;
for (number = value; number < value + 4; number++)
{
for (unsigned char vertical = 0; vertical < 10; vertical++)
{
displayscore[y][vertical] = character[number][vertical];
}
y++;
}
for (unsigned char horizontal = 0; horizontal < 10; horizontal++)
{
for (unsigned char vertical = 0; vertical < 10; vertical++)
{
if (displayscore[horizontal][vertical] == 1) //Judge whether the light is on.
{
strip.setPixelColor(light[horizontal][vertical], c);
}
else
strip.setPixelColor(light[horizontal][vertical], 0);
}
}
strip.show();//Send data
delay(5000);
K = 0; // Reset Joystick direction
sx[0] = 2;
sx[1] = 1;
sx[2] = 0;
sy[0] = 1;
sy[1] = 1;
sy[2] = 1; // Reset snake coordinate
score = 0; // Reset game score
speedS = 400; // The initial speed of snake
Tra 5 minuti posto l'altro pezzo di codice, in quanto avevo superato i 9000 caratteri