Code: Select all
#include <Adafruit_GFX.h>
#include <RGBmatrixPanel.h>
#include <avr/pgmspace.h>
#define F2(progmem_ptr) (const __FlashStringHelper *)progmem_ptr
#define CLK 8
#define LAT A3
#define OE 9
#define A A0
#define B A1
#define C A2
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);
int potRP = 4;
int potLP = 5;
int potVR = 0;
int potVL = 0;
int x = 0;
int y = 0;
int lX = 0;
int lY = 0;
int onOff[16][32];
void setup() {
matrix.begin();
pinMode(potRP, INPUT);
pinMode(potLP, INPUT);
//matrix.fillScreen(0);
Serial.begin(9600);
start();
delay(1000);
Serial.print("To Loop");
}
void loop() {
matrix.fillScreen(0);
delay(100);
//Serial.println("in Loop");
potVR = analogRead(A4);
potVL = analogRead(A5);
x = (int)(potVR / 32);
y = (int)(potVL / 64);
if (x != lX || y != lY) {
Serial.println("Changed");
onOff[x][y] = 1;
lX = x;
lY = y;
updateMatrix();
}
matrix.swapBuffers(false);
}
void start() {
for (int r = 0; r < 16; r++) {
for (int c = 0; c < 32; c++) {
onOff[r][c] = 0;
/*
Serial.print(r);
Serial.print(", ");
Serial.print(c);
Serial.print(" Filled with ");
Serial.print(": ");
Serial.println(onOff[r][c]);
Serial.println("");
//delay(10);
*/
}
}
Serial.println("Done");
//matrix.fillRect(0, 0, 31, 15, matrix.Color333(0, 7, 0));
}
/*
LOOK HERE!!!!!!
*/
void updateMatrix() {
Serial.println("Updating");
for (int r = 0; r < 16; r++) {
for (int c = 0; c < 32; c++) {
if (onOff[r][c] == 1) {
Serial.print( "1 ");
//delay(100);
// matrix.drawPixel(c,r, matrix.Color333(7, 7, 7));
/*
Serial.print(r);
Serial.print(", ");
Serial.print(c);
Serial.print(" is On");
Serial.println("");
matrix.swapBuffers(false);
Serial.print("Updated");
Serial.println("");
*/
} else {
Serial.print("0 ");
//delay(100);
//matrix.drawPixel(c,r, matrix.Color333(0, 0, 0));
/*
Serial.print(r);
Serial.print(", ");
Serial.print(c);
Serial.print(" is Off");
Serial.println("");
matrix.swapBuffers(false);
Serial.print("Updated");
Serial.println("");
*/
}
}
Serial.println("");
}
}
There are some areas commented out just for my debugging attempts. I've found that whenever it tries to call "matrix.drawPixel" is when it goes wrong. It also doesn't clear the matrix with "matrix.fillScreen" for some reason. Please help!