19
19
group = displayio .Group ()
20
20
21
21
# 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 )
23
23
group .append (background_rect )
24
24
25
25
# Set up a button on pin D0/BOOT
@@ -100,10 +100,12 @@ def get_sender_color(rx_message):
100
100
# Show the display
101
101
display .root_group = group
102
102
103
- # Button debouncing
103
+ # Button debouncing and status tracking
104
104
last_button_time = 0
105
105
button_debounce = 0.2 # 200ms debounce
106
106
message_count = 0
107
+ status_reset_time = 0
108
+ status_needs_reset = False
107
109
108
110
while True :
109
111
current_time = time .monotonic ()
@@ -123,18 +125,23 @@ def get_sender_color(rx_message):
123
125
sent_label .text = "TX'd: " # Keep this tomato colored
124
126
sent_counter_label .text = str (message_count ) # Color with sender color
125
127
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
126
130
127
131
except Exception as ex : # pylint: disable=broad-except
128
132
print (f"Send failed: { ex } " )
129
133
status_label .text = "xxx"
130
134
status_label .color = RED
135
+ status_reset_time = current_time + 2.0 # Show error for 2 seconds
136
+ status_needs_reset = True
131
137
132
138
last_button_time = current_time
133
139
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 :
136
142
status_label .text = "press D0 to send"
137
143
status_label .color = TOMATO
144
+ status_needs_reset = False
138
145
139
146
# Check for incoming packets
140
147
if e :
@@ -153,5 +160,7 @@ def get_sender_color(rx_message):
153
160
received_label .text = "RX'd: " # Keep this tomato colored
154
161
received_message_label .text = message [- 12 :] # Color just the message
155
162
received_message_label .color = sender_color
163
+ status_reset_time = current_time + 0.5 # Reset after 0.5 seconds
164
+ status_needs_reset = True
156
165
157
166
time .sleep (0.05 ) # Light polling
0 commit comments