I am trying to print a message on NeoPixel Array using Adafruit_NeoPixel.h library. However, the data to be displayed is received by Arduino Nano via I2C. The problem is that "matrix.show()" command slows down the loop and packets that are supposed to be received on i2c are getting missed. Please help with a solution. Please find my code here:
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#include <Wire.h>
char command;
#define PIN 9
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(30, 7, PIN,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);
const uint16_t colors[] = {
matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255), matrix.Color(0, 255, 255)
} ;
int x = matrix.width();
int CurrentTime[] = {0, 0, 0, 0};
void setup() {
Serial.begin(9600);
Wire.begin(1);
Wire.onReceive(receiveEvent);
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(100);
matrix.setTextColor(colors[1]);
}
void loop() {
matrix.fillScreen(0);
matrix.setCursor(0, 0);
matrix.print(currentTimeValue[0]);
matrix.print(currentTimeValue[1]);
matrix.print(':');
matrix.print(currentTimeValue[2]);
matrix.print(currentTimeValue[3]);
x = matrix.width();
matrix.show();
}
void receiveEvent(int numBytes)
{
command = Wire.read();
if(command>0){
Serial.println(command);
}
This is not the complete code. But even this code, loses data packets on I2c.
Any help will be apprecaited on this topic.
Thanks
Vishal Mehta