I set up a little 2x2 matrix of LEDs that I control by "Row Column Scanning".
Works great so far (in fact I'm very proud since I'm completely new to electronics and C programming)
As a next step I want to control the LED by sending a serial 4 byte string ("1111" to turn them on, "0001" turn off all but the last one etc)
if (Serial.available() > 0) {
while (pointer < 4) {
buffer[pointer] = Serial.read();
pointer++;
}
What if "Serial.available" returns "1"?
You read that single character from the buffer, and the next time you call "Serial.read" the buffer is empty, so you get "-1". (the odd ÿ characters)
Now, at 9600 bps, 1 character takes just over 1ms to transmit.
Your delay allows you time to receive the next character before calling "Serial.read".
I wouldn't rely on this (it won't work if you decide to reduce the line speed), so you need to fix the logic of reading available characters.
So, no, not solved, sorry.
Without the delay, its becoming corrupted probably because of a timing issue. Your code doesn't include what speed serial you're using. It would probably work without the delay if you slowed it down.
I don't know what Serial.available() returns. If I do a Serial.println(Serial.available()) only a blank line is shown (should'nt it be 4 when I enter 4 chars, e.g. "1010"?)
so you need to fix the logic of reading available characters