//JUST FOR TESTING IN SIMULATOR:
#include "LedControl.h" // https://github.com/wayoda/LedControl
int size = 12;
// DIN, CLK, CS
LedControl ledControls[] = {
LedControl(18, 21, 19, size),
LedControl(15, 4, 2, size),
};
// END OF STUFF FOR SIMULATION
//could use 1/8th the memory if these were kept in groups of 8 bits as a byte in an array
//12 columns and 8 rows
//but you'd need to figure out how to modify the byte in the right column when you want to make a change
//check these out
//https://web.archive.org/web/20170627135321/https://www.avrfreaks.net/comment/26024
//edit macros to accept one position number, use it to pick byte in array and bit in the byte
//#define bit_get(p,m) ((p) & (m))
#define bit_get(a,r,p) ((a[r][p / 8]) & BIT(p % 8))
#define bit_set(a,r,p) ((a[r][p / 8]) |= BIT(p % 8))
#define bit_clear(a,r,p) ((a[r][p / 8]) &= ~(BIT(p % 8)))
#define bit_flip(a,r,p) ((a[r][p / 8]) ^= (BIT(p % 8)))
//#define bit_write(c,p,m) (c ? bit_set(p,m) : bit_clear(p,m))
#define BIT(x) (0x01 << (x))
//#define LONGBIT(x) ((unsigned long)0x00000001 << (x))
#define nRow 16 //16
#define nCol 96 //96
byte buffer[nRow][nCol / 8];
void setup() {
// put your setup code here, to run once:
//Serial.begin(115200);
//Serial.println("Hello, ESP32!");
for (int nr = 0; nr < nRow; nr++) {
for (int nc = 0; nc < nCol; nc++) {
if ( (nr + nc) % 1 == 0) {
bit_set(buffer, nr, nc);
}
}
}
}
void loop() {
//ledControls[0].setLed(0, 7, 0, true);
//ledControls[1].setLed(1, 7, 0, false);
//delay(300);
//ledControls[0].setLed(0, 7, 0, false);
//ledControls[1].setLed(1, 7, 0, true);
//delay(100);
//output to serial port for testing
//for (int nr = 0; nr < nRow; nr++) {
// for (int nc = 0; nc < nCol; nc++) {
// Serial.print( (bit_get(buffer, nr, nc)) ? "X" : " ");
// }
// Serial.println("");
//}
//Serial.println("");
//Serial.println("");
//OUTPUT TO DOT MATRIX THING FOR TESTING IN SIM
//int shift = (side - (qrcode.size * scale)) / 2;
int shift = 0;
for (int y = shift; y < nRow; y++) {
for (int x = shift; x < nCol; x++) {
int index = y / 8;
//int address = size - 1 - (x / 8);
int address = x / 8;
int row = 7 - (y % 8);
int column = x % 8;
// Turn out of bounds dots off to make sure they don't stay on
//bool state = false;
//if (x >= shift && x < shift + (qrcode.size * scale) && y >= shift && y < shift + (qrcode.size * scale)) {
// state = qrcode_getModule(&qrcode, (x - shift) / scale, (y - shift) / scale);
//}
//delayMicroseconds(10000);
ledControls[index].setLed(address, row, column, (bit_get(buffer,y,x))); //(bit_get(buffer,x,y))*255
//delayMicroseconds(200);
}
}
// END TESTING OUTPUT
for (int nr = 0; nr < nRow; nr++) {
for (int nc = 0; nc < (nCol / 8); nc++) {
buffer[nr][nc] = 0xff - buffer[nr][nc];
}
}
//myArray[2] ^= B00010000; //xor alternates the 4th item of the 2nd row
//myArray[3] ^= B01010010; //xor alternates all but the 4th item of the 3nd row
//myArray[1] = 0xff - myArray[1];
//delay(1000); // this speeds up the simulation
//Serial.println(sizeof(myArray));
//delay(10);
}