// pins
int clockPin = 2;
int latchPin = 3;
int dataPin = 4;
const byte MAP[][8] = {
{ B00111100,
B01000010,
B10100101,
B10000001,
B10100101,
B10011001,
B01000010,
B00111100
}
};
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
// outputLocation(3, 5);
testMatrix();
// outputMatrix(B11010101, B00101010);
}
void loop() {
}
void outputLocation(int x, int y) {
unsigned char rowByte = 0;
unsigned char colByte = 0;
for ( int i = 0; i < 8; i++ ) {
if (i == x - 1) {
rowByte |= (1 << i);
} else {
rowByte |= (0 << i);
}
}
for ( int i = 0; i < 8; i++ ) {
if (i == y - 1) {
colByte |= (1 << i);
} else {
colByte |= (0 << i);
}
}
Serial.println();
Serial.print("Row Byte value: ");
Serial.println((int)rowByte);
Serial.print("Row Binary representation: ");
for (int i = 7; i >= 0; i--) {
Serial.print(((rowByte >> i) & 1));
}
Serial.println();
Serial.print("Col Byte value: ");
Serial.println((int)colByte);
Serial.print("Col Binary representation: ");
for (int i = 7; i >= 0; i--) {
Serial.print(((colByte >> i) & 1));
}
Serial.println();
outputMatrix(colByte, ~rowByte);
}
void testMatrix() {
Serial.println("Test Matrix");
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
outputLocation(i + 1, j + 1);
Serial.print("Test: [");
Serial.print(i + 1);
Serial.print("][");
Serial.print(j + 1);
Serial.println("]");
delay(50);
}
}
Serial.println("Test Matrix Ended");
resetMatrix();
}
void resetMatrix() {
outputMatrix(0, 0);
}
void outputMatrix(byte col, byte row) {
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, col);
shiftOut(dataPin, clockPin, MSBFIRST, row);
digitalWrite(latchPin, HIGH);
}