// code 1
// Pin configuration for decoders
const int MOD_0 = 6; // A0, A1, A2 of the 1st decoder
const int MOD_1 = 7;
const int MOD_2 = 8;
const int PIN_0 = 9; // A0, A1, A2 of the 2nd decoder
const int PIN_1 = 10;
const int PIN_2 = 11;
const int RESET = 5; // Reset pin for decoder
const int SET = 4; // Set pin for decoder
void setup() {
// Initialize Serial communication
Serial.begin(9600);
// Configure decoder pins as OUTPUT
pinMode(MOD_0, OUTPUT);
pinMode(MOD_1, OUTPUT);
pinMode(MOD_2, OUTPUT);
pinMode(PIN_0, OUTPUT);
pinMode(PIN_1, OUTPUT);
pinMode(PIN_2, OUTPUT);
pinMode(SET, OUTPUT);
pinMode(RESET, OUTPUT);
// Initialize all outputs to LOW
clearAllDots();
}
void loop() {
// Check for input from the Serial Monitor
if (Serial.available() > 0) {
int number = Serial.parseInt(); // Read the number (1–10)
// Validate input
if (number >= 1 && number <= 10) {
activateBraille(number); // Activate the corresponding Braille dots
} else {
Serial.println("Invalid input! Please enter a number between 1 and 10.");
}
}
}
void activateBraille(int number) {
clearAllDots(); // Turn off all dots first
// Braille dot patterns for numbers 1–10
// Each bit in the number corresponds to a Braille dot (1 to 6)
// Example: 0b001001 = Dot 1 and Dot 4 (number 3)
const byte braillePatterns[10] = {
0b000001, // 1 -> Dot 1
0b000011, // 2 -> Dot 1, Dot 2
0b001001, // 3 -> Dot 1, Dot 4
0b011001, // 4 -> Dot 1, Dot 4, Dot 5
0b010001, // 5 -> Dot 1, Dot 5
0b001011, // 6 -> Dot 1, Dot 2, Dot 4
0b011011, // 7 -> Dot 1, Dot 2, Dot 4, Dot 5
0b010011, // 8 -> Dot 1, Dot 2, Dot 5
0b001101, // 9 -> Dot 1, Dot 4, Dot 6
0b011101 // 10 -> Dot 1, Dot 4, Dot 5, Dot 6
};
// Retrieve the pattern for the given number
byte pattern = braillePatterns[number - 1];
// Activate dots based on the pattern
for (int i = 0; i < 6; i++) {
if (pattern & (1 << i)) {
selectDot(i + 1); // Activate the dot (1-based index)
pinSet(); // Set the selected dot
delay(10); // Small delay for stability
}
}
Serial.print("Braille dots activated for number ");
Serial.println(number);
}
void selectDot(int dot) {
// Ensure the input is valid (1 to 6)
if (dot < 1 || dot > 6) return;
dot--; // Convert to 0-based index for binary calculations
// Select the dot using the second decoder
digitalWrite(PIN_0, (dot >> 0) & 0x01);
digitalWrite(PIN_1, (dot >> 1) & 0x01);
digitalWrite(PIN_2, (dot >> 2) & 0x01);
}
void pinSet() {
digitalWrite(SET, HIGH);
digitalWrite(RESET, LOW);
}
void pinReset() {
digitalWrite(SET, LOW);
digitalWrite(RESET, HIGH);
}
void clearAllDots() {
digitalWrite(SET, LOW);
digitalWrite(RESET, LOW);
delay(10); // Ensure all are off
}
Loading
esp32-s2-devkitm-1
esp32-s2-devkitm-1