#include <ctype.h>
const int SR_DATA_PIN = PA0;
const int SR_LATCH_PIN = PA1;
const int SR_CLOCK_PIN = PA2;
const int BTN_NEXT = PB10;
const int BTN_PREV = PB11;
const int NUM_CELLS = 6;
String fileContent = "BRAILLE TEST";
int currentIndex = 0;
const uint8_t brailleLUT[26] = {
0b000001, 0b000011, 0b001001, 0b011001, 0b010001, 0b001011, 0b011011, 0b010011,
0b001010, 0b011010, 0b000101, 0b000111, 0b001101, 0b011101, 0b010101,
0b001111, 0b011111, 0b010111, 0b001110, 0b011110, 0b100101, 0b100111,
0b111010, 0b101101, 0b111101, 0b110101
};
uint8_t charToBraille(char c) {
c = tolower(c);
if (c >= 'a' && c <= 'z') return brailleLUT[c - 'a'];
return 0x00;
}
void updateDisplay() {
digitalWrite(SR_LATCH_PIN, LOW);
for (int i = 5; i >= 0; i--) {
int charIdx = currentIndex + i;
char c = (charIdx < fileContent.length()) ? fileContent[charIdx] : ' ';
shiftOut(SR_DATA_PIN, SR_CLOCK_PIN, MSBFIRST, charToBraille(c));
}
digitalWrite(SR_LATCH_PIN, HIGH);
}
void setup() {
pinMode(SR_DATA_PIN, OUTPUT);
pinMode(SR_LATCH_PIN, OUTPUT);
pinMode(SR_CLOCK_PIN, OUTPUT);
pinMode(BTN_NEXT, INPUT_PULLUP);
pinMode(BTN_PREV, INPUT_PULLUP);
updateDisplay();
}
void loop() {
if (digitalRead(BTN_NEXT) == LOW) {
delay(200);
if (currentIndex + 6 < fileContent.length()) currentIndex += 6;
updateDisplay();
while(digitalRead(BTN_NEXT) == LOW);
}
if (digitalRead(BTN_PREV) == LOW) {
delay(200);
if (currentIndex - 6 >= 0) currentIndex -= 6;
else currentIndex = 0;
updateDisplay();
while(digitalRead(BTN_PREV) == LOW);
}
}