Skip to content

fixed status_label looping and error message timing #3097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions ESP-NOW_basics/espnow_transceiver.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
group = displayio.Group()

# Create background rectangles like your example
background_rect = Rect(0, 0, display.width, display.height, fill=000000)
background_rect = Rect(0, 0, display.width, display.height, fill=0x000000)
group.append(background_rect)

# Set up a button on pin D0/BOOT
Expand Down Expand Up @@ -100,10 +100,12 @@ def get_sender_color(rx_message):
# Show the display
display.root_group = group

# Button debouncing
# Button debouncing and status tracking
last_button_time = 0
button_debounce = 0.2 # 200ms debounce
message_count = 0
status_reset_time = 0
status_needs_reset = False

while True:
current_time = time.monotonic()
Expand All @@ -123,18 +125,23 @@ def get_sender_color(rx_message):
sent_label.text = "TX'd: " # Keep this tomato colored
sent_counter_label.text = str(message_count) # Color with sender color
sent_counter_label.color = SENDER_COLORS.get(DEVICE_ID, WHITE)
status_reset_time = current_time + 0.5 # Reset after 0.5 seconds
status_needs_reset = True

except Exception as ex: # pylint: disable=broad-except
print(f"Send failed: {ex}")
status_label.text = "xxx"
status_label.color = RED
status_reset_time = current_time + 2.0 # Show error for 2 seconds
status_needs_reset = True

last_button_time = current_time

# Reset status after a moment
if current_time - last_button_time > 0.2:
# Reset status only when needed and after appropriate delay
if status_needs_reset and current_time >= status_reset_time:
status_label.text = "press D0 to send"
status_label.color = TOMATO
status_needs_reset = False

# Check for incoming packets
if e:
Expand All @@ -153,5 +160,7 @@ def get_sender_color(rx_message):
received_label.text = "RX'd: " # Keep this tomato colored
received_message_label.text = message[-12:] # Color just the message
received_message_label.color = sender_color
status_reset_time = current_time + 0.5 # Reset after 0.5 seconds
status_needs_reset = True

time.sleep(0.05) # Light polling