KB2040 code and.... other.
This commit is contained in:
parent
2a7a154286
commit
3d72895cbe
37 changed files with 232 additions and 25 deletions
15
Adafruit_KB2040/Capacitive_Touch_One_Pin/code.py
Normal file
15
Adafruit_KB2040/Capacitive_Touch_One_Pin/code.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython Capacitive Touch Pin Example - Print to the serial console when one pin is touched.
|
||||
"""
|
||||
import time
|
||||
import board
|
||||
import touchio
|
||||
|
||||
touch = touchio.TouchIn(board.D9)
|
||||
|
||||
while True:
|
||||
if touch.value:
|
||||
print("Pin touched!")
|
||||
time.sleep(0.1)
|
||||
18
Adafruit_KB2040/Capacitive_Touch_Two_pins/code.py
Normal file
18
Adafruit_KB2040/Capacitive_Touch_Two_pins/code.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython Capacitive Two Touch Pin Example - Print to the serial console when a pin is touched.
|
||||
"""
|
||||
import time
|
||||
import board
|
||||
import touchio
|
||||
|
||||
touch_one = touchio.TouchIn(board.D9)
|
||||
touch_two = touchio.TouchIn(board.D10)
|
||||
|
||||
while True:
|
||||
if touch_one.value:
|
||||
print("Pin one touched!")
|
||||
if touch_two.value:
|
||||
print("Pin two touched!")
|
||||
time.sleep(0.1)
|
||||
19
Adafruit_KB2040/NeoPixel_Blink/code.py
Normal file
19
Adafruit_KB2040/NeoPixel_Blink/code.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
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))
|
||||
14
Adafruit_KB2040/Storage/boot.py
Normal file
14
Adafruit_KB2040/Storage/boot.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython Essentials Storage CP Filesystem boot.py file
|
||||
"""
|
||||
import board
|
||||
import digitalio
|
||||
import storage
|
||||
|
||||
button = digitalio.DigitalInOut(board.BUTTON)
|
||||
button.switch_to_input(pull=digitalio.Pull.UP)
|
||||
|
||||
# If the OBJECT_NAME is connected to ground, the filesystem is writable by CircuitPython
|
||||
storage.remount("/", readonly=button.value)
|
||||
38
Adafruit_KB2040/Storage/code.py
Normal file
38
Adafruit_KB2040/Storage/code.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython Essentials Storage CP Filesystem code.py file
|
||||
"""
|
||||
import time
|
||||
import board
|
||||
import microcontroller
|
||||
import neopixel
|
||||
|
||||
pixel = neopixel.NeoPixel(board.NEOPIXEL, 1)
|
||||
|
||||
try:
|
||||
with open("/temperature.txt", "a") as temp_log:
|
||||
while True:
|
||||
# The microcontroller temperature in Celsius. Include the
|
||||
# math to do the C to F conversion here, if desired.
|
||||
temperature = microcontroller.cpu.temperature
|
||||
|
||||
# Write the temperature to the temperature.txt file every 10 seconds.
|
||||
temp_log.write('{0:.2f}\n'.format(temperature))
|
||||
temp_log.flush()
|
||||
|
||||
# Blink the NeoPixel on every write...
|
||||
pixel.fill((255, 0, 0))
|
||||
time.sleep(1) # ...for one second.
|
||||
pixel.fill((0, 0, 0)) # Then turn it off...
|
||||
time.sleep(9) # ...for the other 9 seconds.
|
||||
|
||||
except OSError as e: # When the filesystem is NOT writable by CircuitPython...
|
||||
delay = 0.5 # ...blink the NeoPixel every half second.
|
||||
if e.args[0] == 28: # If the file system is full...
|
||||
delay = 0.15 # ...blink the NeoPixel every 0.15 seconds!
|
||||
while True:
|
||||
pixel.fill((255, 0, 0))
|
||||
time.sleep(delay)
|
||||
pixel.fill((0, 0, 0))
|
||||
time.sleep(delay)
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""CircuitPython analog pin value example"""
|
||||
import time
|
||||
import board
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""CircuitPython analog voltage value example"""
|
||||
import time
|
||||
import board
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython Audio-capable pin identifying script
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""CircuitPython Blink Example - the CircuitPython 'Hello, World!'"""
|
||||
import time
|
||||
import board
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython Capacitive Touch Pad Example - Print to the serial console when one pad is touched.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython Capacitive Touch Pin Example - Print to the serial console when one pin is touched.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,32 +1,56 @@
|
|||
"""CircuitPython Touch-Compatible Pin Identification Script"""
|
||||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython Touch-Compatible Pin Identification Script
|
||||
|
||||
Depending on the order of the pins in the CircuitPython pin definition, some inaccessible pins
|
||||
may be returned in the script results. Consult the board schematic and use your best judgement.
|
||||
|
||||
In some cases, such as LED, the associated pin, such as D13, may be accessible. The LED pin
|
||||
name is first in the list in the pin definition, and is therefore printed in the results. The
|
||||
pin name "LED" will work in code, but "D13" may be more obvious. Use the schematic to verify.
|
||||
"""
|
||||
import board
|
||||
import touchio
|
||||
from microcontroller import Pin
|
||||
|
||||
|
||||
def is_touch_capable(pin_name):
|
||||
"""Attempts to create touchio.TouchIn() object on all available pins. Returns True if valid."""
|
||||
try:
|
||||
_ = touchio.TouchIn(pin_name)
|
||||
# Print the touch-capable pins that do not need, or already have, an external pulldown.
|
||||
return True
|
||||
except ValueError as e: # A ValueError is raised when a pin is invalid or needs a pulldown.
|
||||
x = getattr(e, "message", str(e)) # Obtain the message associated with the ValueError.
|
||||
if "pulldown" in x: # If the ValueError is regarding needing a pulldown...
|
||||
return True # ...the pin is valid.
|
||||
else:
|
||||
return False # Otherwise, the pins are invalid.
|
||||
except TypeError: # Error returned when checking a non-pin object in dir(board).
|
||||
return False # Invalid if non-pin objects in dir(board).
|
||||
|
||||
|
||||
def get_pin_names():
|
||||
"""Gets all unique pin names available in the board module, excluding a defined list."""
|
||||
exclude = ["NEOPIXEL", "APA102_MOSI", "APA102_SCK", "LED", "NEOPIXEL_POWER", "BUTTON",
|
||||
"BUTTON_UP", "BUTTON_DOWN", "BUTTON_SELECT", "DOTSTAR_CLOCK", "DOTSTAR_DATA",
|
||||
"IR_PROXIMITY"]
|
||||
pins = [pin for pin in [getattr(board, p) for p in dir(board) if p not in exclude]
|
||||
if isinstance(pin, Pin)]
|
||||
"""
|
||||
Gets all unique pin names available in the board module, excluding a defined list.
|
||||
This list is not exhaustive, and depending on the order of the pins in the CircuitPython
|
||||
pin definition, some of the pins in the list may still show up in the script results.
|
||||
"""
|
||||
exclude = [
|
||||
"NEOPIXEL",
|
||||
"APA102_MOSI",
|
||||
"APA102_SCK",
|
||||
"LED",
|
||||
"NEOPIXEL_POWER",
|
||||
"BUTTON",
|
||||
"BUTTON_UP",
|
||||
"BUTTON_DOWN",
|
||||
"BUTTON_SELECT",
|
||||
"DOTSTAR_CLOCK",
|
||||
"DOTSTAR_DATA",
|
||||
"IR_PROXIMITY",
|
||||
"SPEAKER_ENABLE",
|
||||
"BUTTON_A",
|
||||
"BUTTON_B",
|
||||
"POWER_SWITCH",
|
||||
"SLIDE_SWITCH",
|
||||
"TEMPERATURE",
|
||||
"ACCELEROMETER_INTERRUPT",
|
||||
"ACCELEROMETER_SDA",
|
||||
"ACCELEROMETER_SCL",
|
||||
"MICROPHONE_CLOCK",
|
||||
"MICROPHONE_DATA",
|
||||
]
|
||||
pins = [
|
||||
pin
|
||||
for pin in [getattr(board, p) for p in dir(board) if p not in exclude]
|
||||
if isinstance(pin, Pin)
|
||||
]
|
||||
pin_names = []
|
||||
for p in pins:
|
||||
if p not in pin_names:
|
||||
|
|
@ -35,5 +59,22 @@ def get_pin_names():
|
|||
|
||||
|
||||
for possible_touch_pin in get_pin_names(): # Get the pin name.
|
||||
if is_touch_capable(possible_touch_pin): # Check if the pin is touch-capable.
|
||||
print("Touch on:", str(possible_touch_pin).replace("board.", "")) # Print the valid list.
|
||||
try:
|
||||
p = touchio.TouchIn(
|
||||
possible_touch_pin
|
||||
) # Attempt to create the touch object on each pin.
|
||||
# Print the touch-capable pins that do not need, or already have, an external pulldown.
|
||||
print("Touch on:", str(possible_touch_pin).replace("board.", ""))
|
||||
except ValueError as error: # A ValueError is raised when a pin is invalid or needs a pulldown.
|
||||
# Obtain the message associated with the ValueError.
|
||||
error_message = getattr(error, "message", str(error))
|
||||
if (
|
||||
"pulldown" in error_message # If the ValueError is regarding needing a pulldown...
|
||||
):
|
||||
print(
|
||||
"Touch (no pulldown) on:", str(possible_touch_pin).replace("board.", "")
|
||||
)
|
||||
else:
|
||||
print("No touch on:", str(possible_touch_pin).replace("board.", ""))
|
||||
except TypeError: # Error returned when checking a non-pin object in dir(board).
|
||||
pass # Passes over non-pin objects in dir(board).
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython Capacitive Two Touch Pad Example - Print to the serial console when a pad is touched.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython Capacitive Two Touch Pin Example - Print to the serial console when a pin is touched.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython Touch Input Example - Blinking an LED using a capacitive touch pad.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""CircuitPython CPU temperature example in Celsius"""
|
||||
import time
|
||||
import microcontroller
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""CircuitPython CPU temperature example in Fahrenheit"""
|
||||
import time
|
||||
import microcontroller
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython Digital Input Example - Blinking an LED using a button switch.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""CircuitPython Digital Input example - Blinking a built-in NeoPixel LED using a button switch.
|
||||
|
||||
Update BUTTON_PIN to the pin to which you have connected the button (in the case of an external
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""CircuitPython I2C possible pin-pair identifying script"""
|
||||
import board
|
||||
import busio
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""CircuitPython I2C MCP9808 Temperature Sensor Example"""
|
||||
import time
|
||||
import board
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""CircuitPython I2C Device Address Scan"""
|
||||
import time
|
||||
import board
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython I2S Pin Combination Identification Script
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython I2S MP3 playback example.
|
||||
Plays an MP3 once.
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython I2S Tone playback example.
|
||||
Plays a tone for one second on, one
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython I2S WAV file playback.
|
||||
Plays a WAV file once.
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython multiple MP3 playback example.
|
||||
Plays two MP3 files consecutively, once time each.
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython single MP3 playback example.
|
||||
Plays a single MP3 once.
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython NeoPixel Blink example - blinking the built-in NeoPixel(s).
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""CircuitPython blink example for built-in NeoPixel LED"""
|
||||
import time
|
||||
import board
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""CircuitPython status NeoPixel rainbow example."""
|
||||
import time
|
||||
import board
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""CircuitPython status NeoPixel red, green, blue example."""
|
||||
import time
|
||||
import board
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython DotStar rainbow example - multiple DotStars.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython DotStar red, green, blue, brightness control example - multiple DotStars.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython Essentials Storage CP Filesystem boot.py file
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython Essentials Storage CP Filesystem code.py file
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
CircuitPython Essentials Storage CP Filesystem code.py file
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue