I am trying to control a 32x32 led matrix display using Processing. My Arduino code works fine, as far as i can tell. It can interact with my display and if i send text using the Arduino IDEs serial monitor, the LEDs light up in a deterministic fashion. I can also see the Arduinos Rx indicator LED light up. If, however, i send any data from my processing script, the Rx LED flashes, meaning that the Arduino received something, but i do not see any output on my display.
What did i do wrong?
here is my arduino and processing code:
#include "GyverMAX7219.h"
MAX7219< 4, 4, 9 > mtrx;
bool bits[1024];
void setup() {
Serial.begin(9600);
mtrx.setType(GM_SERIES);
mtrx.begin(); // run
mtrx.setBright(0); // brightness 0..15
}
void loop() {
loadData();
renderData();
}
void loadData() {
int n = 0; //location in bits[] to write to
if (Serial.available()) {
for (int i = 0; i < Serial.available(); i++) { //for each UART byte
byte currentByte = Serial.read(); //store the current UART byte
for (int j = 0; j < 8; j++) { //for each bit in the current UART byte
bits[n] = bitRead(currentByte, 7 - j); //add the current bit to bits[]
n++;
}
}
}
}
void renderData() {
for (int x = 0; x < 32; x++) {
for (int y = 0; y < 32; y++) {
mtrx.dot(x, y, bits[x * 32 + y]);
}
}
mtrx.update(); //update the display
}
Serial display;
void setup() {
println("Available ports:");
printArray(Serial.list());
display = new Serial(this, Serial.list()[0], 9600);
}
void draw() {
display.write((int)random(10));
delay(100);
}