#include <Arduino.h>
// Define the analog input pin for the potentiometer
const int potPin = 35;
// Define the GPIO pins for the 3x3 LED matrix
const int ledPins[3][3] = {
{4, 2, 15},
{19, 18, 5},
{12, 14, 27}
};
// Character patterns for 'A' to 'Z'
const byte charPatterns[26][3] = {
// A
{ B111, B101, B111 },
// B
{ B110, B101, B110 },
// C
{ B111, B100, B111 },
// D
{ B110, B101, B110 },
// E
{ B111, B100, B111 },
// F
{ B111, B100, B100 },
// G
{ B111, B101, B111 },
// H
{ B101, B101, B111 },
// I
{ B010, B010, B010 },
// J
{ B001, B001, B010 },
// K
{ B101, B110, B101 },
// L
{ B100, B100, B111 },
// M
{ B101, B111, B101 },
// N
{ B101, B111, B111 },
// O
{ B111, B111, B111 },
// P
{ B111, B101, B100 },
// Q
{ B111, B111, B101 },
// R
{ B110, B101, B100 },
// S
{ B011, B100, B110 },
// T
{ B111, B010, B010 },
// U
{ B101, B101, B111 },
// V
{ B101, B101, B010 },
// W
{ B101, B111, B111 },
// X
{ B101, B010, B101 },
// Y
{ B101, B010, B010 },
// Z
{ B111, B001, B111 }
};
// Function to display a character pattern on the LED matrix
void displayChar(const byte charPattern[]) {
for (int row = 0; row < 3; row++) {
for (int col = 0; col < 3; col++) {
if (charPattern[row] & (1 << col)) {
digitalWrite(ledPins[row][col], HIGH);
} else {
digitalWrite(ledPins[row][col], LOW);
}
}
}
}
void setup() {
// Initialize LED matrix pins as outputs
for (int row = 0; row < 3; row++) {
for (int col = 0; col < 3; col++) {
pinMode(ledPins[row][col], OUTPUT);
}
}
// Initialize the potentiometer pin as an input
pinMode(potPin, INPUT);
Serial.begin(115200);
Serial.println("Esp32 - Ready !!!");
}
void loop() {
// Read the potentiometer value
int potValue = analogRead(potPin);
// Map the potentiometer value to the range 0-25 (for 'A' to 'Z')
int letterIndex = map(potValue, 0, 4095, 0, 25);
// Ensure the letter index is within the valid range
letterIndex = constrain(letterIndex, 0, 25);
// Display the character on the LED matrix
displayChar(charPatterns[letterIndex]);
// Print the displayed character to the serial monitor
char charToDisplay = 'A' + letterIndex;
Serial.print("Displayed Character: ");
Serial.println(charToDisplay);
// Delay for some time before updating again (adjust as needed)
delay(500);
}