Configuration Variable
You can update the WAIT_TIME
variable to a different value if you want. This variable represents the amount of time in seconds between each notification sample playback. Lower times means it will play faster, higher times means it will play slower. The default is 3.0
, but feel free to experiment with different times.
WAIT_TIME = 3.0
Program Variables
These variables are used for various things in the program, they aren't intended for you to change them during the normal operation. The program will update their value when necessary.
# List that will hold indexes of notification samples to play LOOP = [] # last time that we played a sample LAST_PLAY_TIME = 0 # current index that we are on CUR_LOOP_INDEX = 0 # touch events must have at least this long between them COOLDOWN_TIME = 0.25 # seconds # last time that the display was touched # used for debouncing and cooldown enforcement LAST_PRESS_TIME = -1 # Was any icon touched last iteration. # Used for debouncing. WAS_TOUCHED = False
Icons List
This list holds tuples that represent each icon that will be shown on the screen. The tuples contain the string label, the bmp image file to show, and the wave audio file to play. If you wanted to re-purpose this project as a looping soundboard with other sounds, you could change the values here.
# list of icons to show # each entry is a tuple containing: # (Icon Label, Icon BMP image file, Notification sample wav file _icons = [ ("Outlook", "icons/outlook.bmp", "sounds/outlook.wav"), ("Phone", "icons/phone.bmp", "sounds/phone.wav"), ("Skype", "icons/skype.bmp", "sounds/skype.wav"), ("Teams", "icons/teams.bmp", "sounds/teams.wav"), ("Discord", "icons/discord.bmp", "sounds/discord.wav"), ("Apple Mail", "icons/applemail.bmp", "sounds/applemail.wav"), ("iMessage", "icons/imessage.bmp", "sounds/imessage.wav"), ("Slack", "icons/slack.bmp", "sounds/slack.wav"), ("G Calendar", "icons/gcal.bmp", "sounds/RE.wav"), ("G Chat", "icons/gchat.bmp", "sounds/gchat.wav"), ("Stop", "icons/stop.bmp", ""), ]
Helper Functions
The program contains two helper functions:
next_index()
- This function will return the next valid index for a notification sample in the LOOP
list. If the current index is the last available one, then it will wrap back around to 0
.
check_for_touch(_now)
- This function accepts a parameter whose value will be the current time as fetched from time.monotonic()
. It will check the touch screen to see if there are any touch events on icons currently, and take the appropriate action if there are. The time is used to enforce a cool-down behavior so it will not register several touch events rapidly. This will get called during the main loop, and during time that an audio sample is playing.
User Interface
The GUI is created with displayio
. It uses a GridLayout
object loaded up with IconWidgets
from a for loop that references the above icons list.
# grid to hold the icons layout = GridLayout( x=0, y=0, width=320, height=240, grid_size=(4, 3), cell_padding=20, ) # initialize the icons in the grid for i, icon in enumerate(_icons): icon_widget = IconWidget( icon[0], icon[1], x=0, y=0, on_disk=True, transparent_index=0, label_background=0x888888, )
Main Loop
The main loop contains two high level actions:
1) Check if the user has touched any icons. If they touch a notification icon, the index for the one they touched gets added to the LOOP
list. If they touch the stop icon, the LOOP
list is emptied and the CUR_LOOP_INDEX
reset to 0
.
2) Check the current time, if the WAIT_TIME
has passed then load and play the current sample from the LOOP
list. Set the index to the next one for next time. During the time that a sample is being played there is an internal loop that will carry out action 1, so that touch events during the sample playback get handled appropriately.
Further Detail
The source code is thoroughly commented to explain what the statements are doing. You can read through the code and comments to gain a deeper understanding of how it functions or modify parts of it to suit your needs.
Temporarily unable to load content:
Text editor powered by tinymce.