print("\n\tCommunication Device for Deaf Students")
print("\twith OLED, Buzzer and LED Feedback")
print("\t20/11/2024")
print("\tSYAHIR SYAHIRAN BIN ZULKURNAI")
print("\t51221224089\n")
# Import modules/libraries
import oled_lib
from machine import Pin, SoftI2C, PWM
from utime import sleep
# Pin Declaration
led_r = Pin(2, Pin.OUT)
buzzer_pin = PWM(Pin(23))
oled_pin = SoftI2C(scl=Pin(22), sda=Pin(21))
# Pins for seven-segment display
pins = [Pin(32, Pin.OUT), Pin(33, Pin.OUT), Pin(5, Pin.OUT),
Pin(18, Pin.OUT), Pin(19, Pin.OUT), Pin(25, Pin.OUT), Pin(26, Pin.OUT)]
# Buttons
button1 = Pin(13, Pin.IN, Pin.PULL_UP)
button2 = Pin(14, Pin.IN, Pin.PULL_UP)
button3 = Pin(27, Pin.IN, Pin.PULL_UP)
button4 = Pin(12, Pin.IN, Pin.PULL_UP)
button5 = Pin(4, Pin.IN, Pin.PULL_UP)
#Parameter
# Seven-segment display digit patterns
digits = [
[0, 0, 0, 0, 0, 0, 1], # 0
[1, 0, 0, 1, 1, 1, 1], # 1
[0, 0, 1, 0, 0, 1, 0], # 2
[0, 0, 0, 0, 1, 1, 0], # 3
[1, 0, 0, 1, 1, 0, 0], # 4
[0, 1, 0, 0, 1, 0, 0], # 5
[0, 1, 0, 0, 0, 0, 0], # 6
[0, 0, 0, 1, 1, 1, 1], # 7
[0, 0, 0, 0, 0, 0, 0], # 8
[0, 0, 0, 1, 1, 0, 0] # 9
]
# Predefined messages
messages = [
"I need help",
"Toilet, please",
"I am finished",
"I need a break",
"Please repeat"
]
# OLED initialization
oled = oled_lib.SSD1306_I2C(width=128, height=64, i2c=oled_pin)
# Function to display a digit on the seven-segment display
def display_digit(index):
for j in range(7):
pins[j].value(digits[index][j])
# Function to start a 9-second timer
def countdown_timer():
for i in range(9, -1, -1): # Countdown from 9 to 0
display_digit(i) # Update the seven-segment display
sleep(1) # Wait for 1 second
# Turn off LED, OLED, and buzzer when the timer reaches 0
def off_all():
led_r.off() # Turn off LED
buzzer_pin.init(freq=400, duty=0) # Turn off buzzer
oled.fill(0) # Clear OLED display
oled.show() # Update OLED display
#FOR RUN PROGRAM
def indicate():
oled.fill(1) # Clear the display
oled.text(message, 5, 25, 0) # Display the message
oled.show() # Update the OLED display
for i in range(3): # Blink LED 3 times
led_r.on() # Turn on LED
sleep(0.2) # LED on for 200 ms
led_r.off() # Turn off LED
sleep(0.2) # LED off for 200 ms
buzzer_pin.init(freq=400 , duty=70)
sleep(0.5)
buzzer_pin.init(freq=400 , duty=0)
sleep(0.5) # Turn off buzzer
countdown_timer()
off_all()
# Main program
while True:
if not button1.value(): # Button 1 pressed
message = messages[0]
indicate()
elif not button2.value(): # Button 2 pressed
message = messages[1]
indicate()
elif not button3.value(): # Button 3 pressed
message = messages[2]
indicate()
elif not button4.value(): # Button 4 pressed
message = messages[3]
indicate()
elif not button5.value(): # Button 5 pressed
message = messages[4]
indicate()
else:
message = None # No button pressed
off_all()