From 19cf0a3d82bbc6d765b8f3e553c4a80130b90edd Mon Sep 17 00:00:00 2001 From: BlitzCityDIY Date: Tue, 14 Jun 2022 10:12:16 -0400 Subject: [PATCH] adding examples for qt py s3 adding code examples for the qt py esp32-s3 guide --- Adafruit_QT_Py_ESP32-S3/analog_in/code.py | 17 ++++++++++++++ .../cap_touch_one_pin/code.py | 16 ++++++++++++++ .../cap_touch_two_pins/code.py | 19 ++++++++++++++++ Adafruit_QT_Py_ESP32-S3/digital_input/code.py | 19 ++++++++++++++++ Adafruit_QT_Py_ESP32-S3/storage/boot.py | 22 +++++++++++++++++++ 5 files changed, 93 insertions(+) create mode 100644 Adafruit_QT_Py_ESP32-S3/analog_in/code.py create mode 100644 Adafruit_QT_Py_ESP32-S3/cap_touch_one_pin/code.py create mode 100644 Adafruit_QT_Py_ESP32-S3/cap_touch_two_pins/code.py create mode 100644 Adafruit_QT_Py_ESP32-S3/digital_input/code.py create mode 100644 Adafruit_QT_Py_ESP32-S3/storage/boot.py diff --git a/Adafruit_QT_Py_ESP32-S3/analog_in/code.py b/Adafruit_QT_Py_ESP32-S3/analog_in/code.py new file mode 100644 index 000000000..442292c3b --- /dev/null +++ b/Adafruit_QT_Py_ESP32-S3/analog_in/code.py @@ -0,0 +1,17 @@ +# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries +# SPDX-License-Identifier: MIT +"""CircuitPython Analog In Voltage Example for ESP32-S3""" +import time +import board +import analogio + +analog_pin = analogio.AnalogIn(board.A0) + + +def get_voltage(pin): + return (pin.value * 3.53) / 61285 + + +while True: + print(get_voltage(analog_pin)) + time.sleep(0.1) diff --git a/Adafruit_QT_Py_ESP32-S3/cap_touch_one_pin/code.py b/Adafruit_QT_Py_ESP32-S3/cap_touch_one_pin/code.py new file mode 100644 index 000000000..49b22d8cd --- /dev/null +++ b/Adafruit_QT_Py_ESP32-S3/cap_touch_one_pin/code.py @@ -0,0 +1,16 @@ +# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries +# SPDX-License-Identifier: MIT +""" +CircuitPython Capacitive Touch Pin Example for ESP32-S3. +Print to the serial console when one pin is touched. +""" +import time +import board +import touchio + +touch = touchio.TouchIn(board.A2) + +while True: + if touch.value: + print("Pin touched!") + time.sleep(0.1) diff --git a/Adafruit_QT_Py_ESP32-S3/cap_touch_two_pins/code.py b/Adafruit_QT_Py_ESP32-S3/cap_touch_two_pins/code.py new file mode 100644 index 000000000..c8997ff60 --- /dev/null +++ b/Adafruit_QT_Py_ESP32-S3/cap_touch_two_pins/code.py @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries +# SPDX-License-Identifier: MIT +""" +CircuitPython Capacitive Two Touch Pin Example for ESP32-S3 +Print to the serial console when a pin is touched. +""" +import time +import board +import touchio + +touch_one = touchio.TouchIn(board.A2) +touch_two = touchio.TouchIn(board.TX) + +while True: + if touch_one.value: + print("Pin one touched!") + if touch_two.value: + print("Pin two touched!") + time.sleep(0.1) diff --git a/Adafruit_QT_Py_ESP32-S3/digital_input/code.py b/Adafruit_QT_Py_ESP32-S3/digital_input/code.py new file mode 100644 index 000000000..0a80763f6 --- /dev/null +++ b/Adafruit_QT_Py_ESP32-S3/digital_input/code.py @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries +# SPDX-License-Identifier: MIT +""" +CircuitPython Digital Input example - Blinking a built-in NeoPixel LED using a button switch. +""" +import board +import digitalio +import neopixel + +pixel = neopixel.NeoPixel(board.NEOPIXEL, 1) + +button = digitalio.DigitalInOut(board.BUTTON) +button.switch_to_input(pull=digitalio.Pull.UP) + +while True: + if not button.value: + pixel.fill((255, 0, 0)) + else: + pixel.fill((0, 0, 0)) diff --git a/Adafruit_QT_Py_ESP32-S3/storage/boot.py b/Adafruit_QT_Py_ESP32-S3/storage/boot.py new file mode 100644 index 000000000..0fe0ec08c --- /dev/null +++ b/Adafruit_QT_Py_ESP32-S3/storage/boot.py @@ -0,0 +1,22 @@ +# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries +# SPDX-License-Identifier: MIT +""" +CircuitPython Essentials Storage CP Filesystem boot.py file +""" +import time +import board +import digitalio +import storage +import neopixel + +pixel = neopixel.NeoPixel(board.NEOPIXEL, 1) + +button = digitalio.DigitalInOut(board.BUTTON) +button.switch_to_input(pull=digitalio.Pull.UP) + +# Turn the NeoPixel blue for one second to indicate when to press the boot button. +pixel.fill((255, 255, 255)) +time.sleep(1) + +# If the button is connected to ground, the filesystem is writable by CircuitPython +storage.remount("/", readonly=button.value)