1919group = displayio .Group ()
2020
2121# Create background rectangles like your example
22- background_rect = Rect (0 , 0 , display .width , display .height , fill = 000000 )
22+ background_rect = Rect (0 , 0 , display .width , display .height , fill = 0x000000 )
2323group .append (background_rect )
2424
2525# Set up a button on pin D0/BOOT
@@ -100,10 +100,12 @@ def get_sender_color(rx_message):
100100# Show the display
101101display .root_group = group
102102
103- # Button debouncing
103+ # Button debouncing and status tracking
104104last_button_time = 0
105105button_debounce = 0.2 # 200ms debounce
106106message_count = 0
107+ status_reset_time = 0
108+ status_needs_reset = False
107109
108110while True :
109111 current_time = time .monotonic ()
@@ -123,18 +125,23 @@ def get_sender_color(rx_message):
123125 sent_label .text = "TX'd: " # Keep this tomato colored
124126 sent_counter_label .text = str (message_count ) # Color with sender color
125127 sent_counter_label .color = SENDER_COLORS .get (DEVICE_ID , WHITE )
128+ status_reset_time = current_time + 0.5 # Reset after 0.5 seconds
129+ status_needs_reset = True
126130
127131 except Exception as ex : # pylint: disable=broad-except
128132 print (f"Send failed: { ex } " )
129133 status_label .text = "xxx"
130134 status_label .color = RED
135+ status_reset_time = current_time + 2.0 # Show error for 2 seconds
136+ status_needs_reset = True
131137
132138 last_button_time = current_time
133139
134- # Reset status after a moment
135- if current_time - last_button_time > 0.2 :
140+ # Reset status only when needed and after appropriate delay
141+ if status_needs_reset and current_time >= status_reset_time :
136142 status_label .text = "press D0 to send"
137143 status_label .color = TOMATO
144+ status_needs_reset = False
138145
139146 # Check for incoming packets
140147 if e :
@@ -153,5 +160,7 @@ def get_sender_color(rx_message):
153160 received_label .text = "RX'd: " # Keep this tomato colored
154161 received_message_label .text = message [- 12 :] # Color just the message
155162 received_message_label .color = sender_color
163+ status_reset_time = current_time + 0.5 # Reset after 0.5 seconds
164+ status_needs_reset = True
156165
157166 time .sleep (0.05 ) # Light polling
0 commit comments