Final Preparation
We have covered all the function blocks in the previous post.
This post will be a short one to cover a few things we need before entering the main program loop.
- Assign function to buttons
- Voice practice
- Start video capturing
### Assign events to buttons
GPIO.add_event_detect(Button_1, GPIO.BOTH, callback=button1_callback)
GPIO.add_event_detect(Button_2, GPIO.FALLING, callback=button2_callback, bouncetime=300)
GPIO.add_event_detect(Button_3, GPIO.FALLING, callback=button3_callback, bouncetime=300)
GPIO.add_event_detect(Button_4, GPIO.FALLING, callback=button4_callback, bouncetime=300)
GPIO.add_event_detect(Button_5, GPIO.FALLING, callback=button5_callback, bouncetime=300)
### Voice Practice
lcd.lcd_display_string('Voice Practice'.ljust(16), 1, 0)
print('[INFO] Voice Practice...')
PicoSpeech('hh Audio ready.')
### Prepare camera 0 for video capturing
cap = cv2.VideoCapture(0)
### Ready to enter main program loop
lcd.lcd_display_string('Program Ready'.ljust(16), 1, 0)
print('[INFO] Program Ready')
sleep(1)
lcd.lcd_clear()
Line 2-6: Assign call back function for each button
Line 9: Showing “Voice Practice” on the LCD screen
Line 11: Audio out “hh Audio ready.” (“hh” at the start to cover the initial lag audio device might have)
Line 14: Make the camera ready for video capturing
Line 17-20: Show “Program Ready” on the LCD screen for a second
What’s Next?
We are now ready to enter the main program loop in the next post.