Skip to content

Commit 99d30da

Browse files
committed
multiple button rev tft example
The ESP32-S2 and -S3 Rev TFT have three buttons. This example demonstrates the Pull.UP vs Pull.DOWN configuration across all three as it is non-intuitive. text to serial will also show up on the TFT. Test on both ESP32-S2 and ESP32-S3 Rev TFT boards with CP 9.2.2. Works!
1 parent daa4e42 commit 99d30da

File tree

1 file changed

+41
-0
lines changed
  • CircuitPython_Templates/digital_input_built_in_led_multiple_buttons_rev_tft

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# SPDX-FileCopyrightText: 2022 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
"""
4+
CircuitPython Multiple Button Digital Input Example - Handling multiple buttons with simple logic.
5+
"""
6+
import board
7+
import digitalio
8+
import time
9+
10+
# LED setup
11+
led = digitalio.DigitalInOut(board.LED)
12+
led.direction = digitalio.Direction.OUTPUT
13+
14+
# Button setup
15+
button0 = digitalio.DigitalInOut(board.D0)
16+
button0.switch_to_input(pull=digitalio.Pull.UP)
17+
18+
button1 = digitalio.DigitalInOut(board.D1)
19+
button1.switch_to_input(pull=digitalio.Pull.DOWN)
20+
21+
button2 = digitalio.DigitalInOut(board.D2)
22+
button2.switch_to_input(pull=digitalio.Pull.DOWN)
23+
24+
while True:
25+
# Check Button D0
26+
if not button0.value: # button0 is active (Pull.UP, active LOW)
27+
print("Button D0 pressed")
28+
led.value = True
29+
# Check Button D1
30+
elif button1.value: # button1 is active (Pull.DOWN, active HIGH)
31+
print("Button D1 pressed")
32+
led.value = True
33+
# Check Button D2
34+
elif button2.value: # button2 is active (Pull.DOWN, active HIGH)
35+
print("Button D2 pressed")
36+
led.value = True
37+
else:
38+
led.value = False # No buttons are pressed, turn off the LED
39+
40+
# Small delay to debounce buttons and reduce serial output spam
41+
time.sleep(0.1)

0 commit comments

Comments
 (0)