I don't know if the code is what is breaking my behaviour but I have already bricked one arduino beetle (? not sure if that is the correct name but it's a 32u4) (PC does not recognize anything being connected even) and may be about to do the same with a pro micro.
I am far from done with my code and still working out some issues with behaviour in particular situations but after uploading the code multiple times with minor changes I was unable to upload any further. The "Uploading...." bar gets filled until the end but gets stuck in that state until it times out. If I try to upload again I get an error that the port is busy, only if I reset the Arduino or reconnect it I don't get the busy port error message.
A "solution" I found online is to reset the arduino and hit the upload button at a very specific moment where timing is key, so it took me about 10 times usually. That only fixed the problem temporarily as the same issue started recurring over and over again until The computer just didnt recognize the arduino anymore and there was no light on it when i connected it.
So I bought a new one and now I am facing the same issue. Is it my program that is creating a problem or is it something else? How can I fix this?
Here is my code:
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
//Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(8, 8, 9, NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE, NEO_RGB + NEO_KHZ800);
//Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(matrixWidth, matrixHeight, tilesX, tilesY, pin, matrixType, ledType);
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(8, 8, 4, 1, 9, NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE + NEO_TILE_TOP + NEO_TILE_LEFT + NEO_TILE_ROWS + NEO_TILE_PROGRESSIVE, NEO_GRB + NEO_KHZ800);
static uint16_t d[32][8];
static uint16_t r[32][8];
static byte h[64];
static byte rec = 0;
//((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
matrix.begin();
matrix.setBrightness(5);
matrix.show();
matrix.show();
Serial.write((byte) B0);
clean();
}
void loop() {
/*for (int n=0; n<256; n++) {
matrix.setPixelColor(n, 255,0,0);
matrix.show();
//delay(100);
}*/
/*int test = matrix.getPixelColor(remap(20, 6));
matrix.drawPixel (2,2, matrix.Color((test%512)-256, (test%768)-512, (test%1024)-768 ));
*/
//matrix.drawPixel (6, 6, matrix.Color(0, 0, 0));
//matrix.drawPixel (5, 6, matrix.Color(0,0,0));
//delay(1000);
d[1][5] = (31 << 11);
d[0][6] = (63 << 5);
displ();
delay(100);
transition();
//matrix.drawPixel(0,0, 0xF800);
//matrix.show();
//receive();
//delay(1000);
//byte t[64];
//for (int i=0; i<64; i++) t[i] = 0;
//Serial.write(t, 64);
//transition();
}
void receive() {
matrix.drawPixel (5, 6, matrix.Color(255, 0, 0));
matrix.show();
if (Serial.peek() == B00000000) {
for (rec = 0; rec < 16; rec++) {
Serial.readBytes(h, 64);
for (byte i = 0; i < 16; i++) {
r[(i / 8) + 2 * rec][i % 8] = ((uint32_t)h[i + 1] << 16) | ((uint32_t)h[i + 2] << 8) | h[i + 3];
}
}
}
matrix.drawPixel (6, 6, matrix.Color(255, 0, 0));
matrix.show();
}
void transition() {
for (int i = 0; i < 64; i++) {
for (int x = 30; x >= 0; x--) { //last pixel is 31 but the last one is not important
for (int y = 0; y < 8; y++) {
matrix.drawPixel (x + 1 + i, y, d[x][y]);
}
}
for (int z = 0; z<8; z++) {
d[0][z] = r[31][z];
}
/*for (int x = 30; x >= 0; x--) { //last pixel is 31 but the last one is not important
for (int y = 0; y < 8; y++) {
matrix.drawPixel (x + 1 + i, y, d[x][y]);
}
}*/
delay(10);
displ();
}
//updat();
}
void displ() {
for (int x = 0; x < 32; x++) {
for (int y = 0; y < 8; y++) {
matrix.drawPixel (x, y, d[x][y]);
}
}
matrix.show();
}
/*void updat(){
for (int x = 0; x < 32; x++) { //last pixel is 31 but the last one is not important
for (int y; y < 8; y++) {
d[x1]
}
}
}*/
void clean() {
for (int x = 0; x < 32; x++) {
for (int y = 0; y < 8; y++) {
d[x][y] = 0;
r[x][y] = 0;
}
}
}
I did have a for loop with a missing assignment to the running variable at one point: for (int y; y < 8; y++) insted of for (int y = 0; y < 8; y++)
is that a problem? I saw it after I uploaded the program and fixed it and I don't know if that could cause such an issue...