// Pin configuration for 1st decoder (Module selection)
const int MOD_0 = 6; // A0, A1, A2 of the 1st decoder
const int MOD_1 = 7;
const int MOD_2 = 8;
// Pin configuration for 2nd decoder (Pin selection)
const int PIN_0 = 9; // A0, A1, A2 of the 2nd decoder
const int PIN_1 = 10;
const int PIN_2 = 11;
// Control pins for SET and RESET
const int RESET = 5; // Reset pin of the 1st decoder
const int SET = 4; // Set pin of the 1st decoder
void setup() {
// Initialize Serial communication for receiving numbers
Serial.begin(9600);
// Configure all 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);
// Ensure all pins are initially OFF
pinOff();
}
void loop() {
// Check if data is available in the Serial Monitor
if (Serial.available() > 0) {
int number = Serial.parseInt(); // Read the input number (1–10)
// Validate the input and activate the corresponding Braille pattern
if (number >= 1 && number <= 10) {
activateBraille(number);
} else {
Serial.println("Invalid input! Please enter a number between 1 and 10.");
}
}
}
void activateBraille(int number) {
// Turn off all dots before activating new pattern
pinOff();
// Define Braille patterns for numbers 1 to 10
// Each array represents dots 1 to 6: {Dot1, Dot2, Dot3, Dot4, Dot5, Dot6}
int brailleDots[10][6] = {
{1, 0, 0, 0, 0, 0}, // Number 1
{1, 1, 0, 0, 0, 0}, // Number 2
{1, 0, 0, 1, 0, 0}, // Number 3
{1, 0, 0, 1, 1, 0}, // Number 4
{1, 0, 0, 0, 1, 0}, // Number 5
{1, 1, 0, 1, 0, 0}, // Number 6
{1, 1, 0, 1, 1, 0}, // Number 7
{1, 1, 0, 0, 1, 0}, // Number 8
{1, 0, 0, 1, 0, 1}, // Number 9
{1, 0, 0, 1, 1, 1} // Number 10
};
// Select dots based on the number's Braille pattern
for (int i = 0; i < 6; i++) {
if (brailleDots[number - 1][i] == 1) {
selectDot(i + 1); // Activate the corresponding dot (1 to 6)
pinSet();
}
}
// Print feedback to Serial Monitor
Serial.print("Activated Braille pattern for number: ");
Serial.println(number);
}
void selectDot(int dot) {
// Select the appropriate module (decoder 1) and pin (decoder 2) for the given dot
moduleSelect(1); // Assuming all dots are in module 1
pinSelect(dot);
}
void moduleSelect(int decimalValue) {
// Select the module by setting MOD_* pins
decimalValue--; // Adjust for 0-based indexing
digitalWrite(MOD_0, (decimalValue >> 0) & 0x01);
digitalWrite(MOD_1, (decimalValue >> 1) & 0x01);
digitalWrite(MOD_2, (decimalValue >> 2) & 0x01);
}
void pinSelect(int decimalValue) {
// Select the pin by setting PIN_* pins
decimalValue--; // Adjust for 0-based indexing
digitalWrite(PIN_0, (decimalValue >> 0) & 0x01);
digitalWrite(PIN_1, (decimalValue >> 1) & 0x01);
digitalWrite(PIN_2, (decimalValue >> 2) & 0x01);
}
void pinSet() {
// Activate the selected pin
digitalWrite(SET, HIGH);
digitalWrite(RESET, LOW);
}
void pinOff() {
// Deactivate all pins
digitalWrite(SET, LOW);
digitalWrite(RESET, LOW);
}