#include <Arduino.h>
// Pin connections for the rows and columns of the 8x8 LED matrix
const int rowPins[] = {22, 23, 24, 25, 26, 27, 28, 29};
const int colPins[] = {30, 31, 32, 33, 34, 35, 36, 37};
// Pin connections for the 4-bit DIP switch
const int DIP_PINS[] = {38, 39, 40, 41};
// Character bitmaps
byte characters[][8] = {
{0x3C, 0x42, 0x46, 0x4A, 0x52, 0x62, 0x42, 0x3C}, // 0
{0x10, 0x30, 0x50, 0x10, 0x10, 0x10, 0x10, 0x3C}, // 1
{0x3C, 0x42, 0x42, 0x0C, 0x30, 0x40, 0x40, 0x7E}, // 2
{0x3C, 0x42, 0x02, 0x1C, 0x02, 0x42, 0x42, 0x3C}, // 3
{0x0C, 0x14, 0x24, 0x44, 0x7E, 0x04, 0x04, 0x04}, // 4
{0x7E, 0x40, 0x40, 0x7C, 0x02, 0x02, 0x42, 0x3C}, // 5
{0x3C, 0x42, 0x40, 0x7C, 0x42, 0x42, 0x42, 0x3C}, // 6
{0x7E, 0x02, 0x04, 0x08, 0x10, 0x20, 0x20, 0x20}, // 7
{0x3C, 0x42, 0x42, 0x3C, 0x42, 0x42, 0x42, 0x3C}, // 8
{0x3C, 0x42, 0x42, 0x42, 0x3E, 0x02, 0x42, 0x3C}, // 9
{0x24, 0x24, 0x24, 0x3C, 0x3C, 0x24, 0x24, 0x24}, // A
{0x38, 0x28, 0x28, 0x38, 0x28, 0x28, 0x28, 0x38}, // B
{0x1C, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x1C}, // C
{0x38, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x38}, // D
{0x3E, 0x20, 0x20, 0x3C, 0x20, 0x20, 0x20, 0x3E}, // E
{0x3E, 0x20, 0x20, 0x3C, 0x20, 0x20, 0x20, 0x20} // F
};
void setup() {
for (int i = 0; i < 8; i++) {
pinMode(rowPins[i], OUTPUT);
pinMode(colPins[i], OUTPUT);
}
for (int i = 0; i < 4; i++) {
pinMode(DIP_PINS[i], INPUT_PULLUP);
}
}
void displayCharacter(byte character[8]) {
for (int row = 0; row < 8; row++) {
for (int col = 0; col < 8; col++) {
digitalWrite(rowPins[row], !(character[row] & (1 << col)));
digitalWrite(colPins[col], HIGH);
delayMicroseconds(800);
digitalWrite(colPins[col], LOW);
}
}
}
int readDipSwitch() {
int value = 0;
for (int i = 0; i < 4; i++) {
value |= (!digitalRead(DIP_PINS[i])) << i;
}
return value;
}
void loop() {
int dipValue = readDipSwitch();
displayCharacter(characters[dipValue]);
}