Hallo Zusammen.
geht mal wieder um das Bier Pong Projekt
Ich bin wieder einmal an die Grenzen meiner Programmierkünste gestoßen.
Ich möchte in meiner nxm Matrix einen Array mit allen Randpixeln erstellen. Die Reihenfolge ist wichtig (im Uhrzeigersinn)
Ziel ist, den Array anschließend durchzulaufen und eine LED nach der anderen anzuschalten.
Mit einem hardgescriptetem Array wie bspw. dieser klappt das:
Code
uint8_t tmpArray[28] = {0,1,2,3,4,5,6,7,8,23,24,39,40,55,56,57,58,59,60,61,62,63,48,47,32,31,16,15};
Grund für diese seltsame Nummerierung ist das Serpentinen Layout des Strips.
Ich habe eine Schleife geschrieben um den Array zu initialisieren, diese hängt sich aber irgendwie immer auf. Ich finde den Fehler einfach nicht:
Code
const uint8_t boarderPixelCount = 28;
void initBoarderArray()
// initialise the boarder LEDS clockwise as own Array for easier acess
{
uint8_t tmpArray[boarderPixelCount];
uint8_t xPos = 0;
uint8_t yPos = 0;
// Start Position 0,0
uint8_t xAction = 1;
uint8_t yAction = 0;
// 1 = run right
// 2 = run left
// 0 = pause
if(xAction == 1 && yAction == 0){
for(uint8_t i = 0; i < xMatrix; i++){
tmpArray[i] = XYsafe(i, yPos);
}
xAction = 0;
yAction = 1;
xPos = xMatrix-1;
}
if(xAction == 0 && yAction == 1){
for(uint8_t i = 0; i < yMatrix; i++){
tmpArray[(xMatrix-1+i)] = XYsafe(xPos, i);
}
xAction = 2;
yAction = 0;
yPos = yMatrix-1;
}
if(xAction == 2 && yAction == 0){
for(uint8_t i = (xMatrix-1); i >= 0; i--){
tmpArray[(xMatrix-1+yMatrix-1)] = XYsafe(i, yPos);
}
xAction = 0;
yAction = 2;
xPos = 0;
}
if(xAction == 0 && yAction == 2){
for(uint8_t i = (yMatrix-1); i > 0; i--){
tmpArray[(xMatrix-1+yMatrix-1+xMatrix-1)] = XYsafe(xPos, i);
}
yAction = 0;
xAction = 0;
yPos = 0;
}
return tmpArray;
}
// XYsafe(x,y) takes x and y coordinates and returns an LED index number,
// for use like this: leds[ XY(x,y) ] == CRGB::Red;
// Error checking IS performed on the ranges of x and y, and an
// index of "-1" is returned. Special instructions below
// explain how to use this without having to do your own error
// checking every time you use this function.
// This is a slightly more advanced technique, and
// it REQUIRES SPECIAL ADDITIONAL setup, described below.
Alles anzeigen
Vielleicht findet ja einer von euch den Grund, warum die Funktion dazu führt, dass der Nano sich aufhängt.