from machine import Pin
import time
# Define the button pins
button_toggle1 = Pin(2, Pin.IN, Pin.PULL_DOWN)
button_toggle2 = Pin(3, Pin.IN, Pin.PULL_DOWN)
button_toggle3 = Pin(4, Pin.IN, Pin.PULL_DOWN)
button_toggle4 = Pin(5, Pin.IN, Pin.PULL_DOWN)
button_toggle5 = Pin(6, Pin.IN, Pin.PULL_DOWN)
button_toggle6 = Pin(7, Pin.IN, Pin.PULL_DOWN)
button_clear = Pin(10, Pin.IN, Pin.PULL_DOWN)
button_print = Pin(17, Pin.IN, Pin.PULL_DOWN)
# Binary array representing 6-dot Braille
binary_array = [0, 0, 0, 0, 0, 0]
# Braille mapping dictionary (Braille dot patterns to alphabets)
braille_dict = {
(1, 0, 0, 0, 0, 0): 'A',
(1, 1, 0, 0, 0, 0): 'B',
(1, 0, 0, 1, 0, 0): 'C',
(1, 0, 0, 1, 1, 0): 'D',
(1, 0, 0, 0, 1, 0): 'E',
(1, 1, 0, 1, 0, 0): 'F',
(1, 1, 0, 1, 1, 0): 'G',
(1, 1, 0, 0, 1, 0): 'H',
(0, 1, 0, 1, 0, 0): 'I',
(0, 1, 0, 1, 1, 0): 'J',
(1, 0, 1, 0, 0, 0): 'K',
(1, 1, 1, 0, 0, 0): 'L',
(1, 0, 1, 1, 0, 0): 'M',
(1, 0, 1, 1, 1, 0): 'N',
(1, 0, 1, 0, 1, 0): 'O',
(1, 1, 1, 1, 0, 0): 'P',
(1, 1, 1, 1, 1, 0): 'Q',
(1, 1, 1, 0, 1, 0): 'R',
(0, 1, 1, 1, 0, 0): 'S',
(0, 1, 1, 1, 1, 0): 'T',
(1, 0, 1, 0, 0, 1): 'U',
(1, 1, 1, 0, 0, 1): 'V',
(0, 1, 0, 1, 1, 1): 'W',
(1, 0, 1, 1, 0, 1): 'X',
(1, 0, 1, 1, 1, 1): 'Y',
(1, 0, 1, 0, 1, 1): 'Z'
}
def set_value(index):
binary_array[index] = 1
time.sleep(0.2) # Debounce delay
def set_clear():
for i in range(len(binary_array)):
binary_array[i] = 0
time.sleep(0.2)
def print_braille_character():
braille_tuple = tuple(binary_array)
character = braille_dict.get(braille_tuple, '?') # '?' for undefined patterns
print("Braille Alphabet:", character)
prev_button_state = 0 # Tracks previous state of the print button
def check_buttons():
global prev_button_state
if button_toggle1.value():
set_value(0)
if button_toggle2.value():
set_value(1)
if button_toggle3.value():
set_value(2)
if button_toggle4.value():
set_value(3)
if button_toggle5.value():
set_value(4)
if button_toggle6.value():
set_value(5)
if button_clear.value():
set_clear()
# Edge detection: Print only when button goes from 0 to 1 (press event)
current_button_state = button_print.value()
if current_button_state == 1 and prev_button_state == 0:
print_braille_character()
set_clear()
time.sleep(0.3)
prev_button_state = current_button_state # Update state for next iteration
while True:
check_buttons()