I am rendering an image for an 8x8 matrix using Pyserial libraries. The image appears for a very short time, and then disappears. But the image of the letter L appears again, which I set in the Loop() function. Next, I provide the Arduino code first, and then the Python code.
#include "LedControl.h"
LedControl lc=LedControl(12,10,11,1);
void setup() {
lc.shutdown(0,false);
lc.setIntensity(0,1);
lc.clearDisplay(0);
Serial.begin(9600);
}
void draw(byte* matrix) {
lc.setRow(0,0,matrix[0]);
lc.setRow(0,1,matrix[1]);
lc.setRow(0,2,matrix[2]);
lc.setRow(0,3,matrix[3]);
lc.setRow(0,4,matrix[4]);
lc.setRow(0,5,matrix[5]);
lc.setRow(0,6,matrix[6]);
lc.setRow(0,7,matrix[7]);
}
void clear() {
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
}
byte data[8] = {B00000000,B00100000,B00100000,B00100000,B00100000,B00100000,B00111100,B00000000};
void loop() {
if (Serial.available() >= 8) {
for (int i = 0; i < 8; i++) {
data[i] = Serial.read();
}
} else if (Serial.available() > 0) {
Serial.flush();
}
draw(data);
Serial.println(data[2], BIN);
delay(450);
}
import serial
import time
ser = serial.Serial('COM3', 9600, timeout=1)
time.sleep(2)
ser.write(bytes([0b00001111, 0b00000111, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b00001111]))
time.sleep(5)
ser.close()
Why does the image not remain on the matrix? I am using MAX7219 driver