Skip to content

Commit 5f20c50

Browse files
authored
Merge pull request #1938 from kattni/kb2040
KB2040 code and.... other.
2 parents 5590e23 + 927bda5 commit 5f20c50

37 files changed

Lines changed: 235 additions & 28 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: Unlicense
3+
"""
4+
CircuitPython Capacitive Touch Pin Example - Print to the serial console when one pin is touched.
5+
"""
6+
import time
7+
import board
8+
import touchio
9+
10+
touch = touchio.TouchIn(board.D9)
11+
12+
while True:
13+
if touch.value:
14+
print("Pin touched!")
15+
time.sleep(0.1)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: Unlicense
3+
"""
4+
CircuitPython Capacitive Two Touch Pin Example - Print to the serial console when a pin is touched.
5+
"""
6+
import time
7+
import board
8+
import touchio
9+
10+
touch_one = touchio.TouchIn(board.D9)
11+
touch_two = touchio.TouchIn(board.D10)
12+
13+
while True:
14+
if touch_one.value:
15+
print("Pin one touched!")
16+
if touch_two.value:
17+
print("Pin two touched!")
18+
time.sleep(0.1)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: Unlicense
3+
"""
4+
CircuitPython Digital Input example - Blinking a built-in NeoPixel LED using a button switch.
5+
"""
6+
import board
7+
import digitalio
8+
import neopixel
9+
10+
pixel = neopixel.NeoPixel(board.NEOPIXEL, 1)
11+
12+
button = digitalio.DigitalInOut(board.BUTTON)
13+
button.switch_to_input(pull=digitalio.Pull.UP)
14+
15+
while True:
16+
if not button.value:
17+
pixel.fill((255, 0, 0))
18+
else:
19+
pixel.fill((0, 0, 0))

Adafruit_KB2040/Storage/boot.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: Unlicense
3+
"""
4+
CircuitPython Essentials Storage CP Filesystem boot.py file
5+
"""
6+
import board
7+
import digitalio
8+
import storage
9+
10+
button = digitalio.DigitalInOut(board.BUTTON)
11+
button.switch_to_input(pull=digitalio.Pull.UP)
12+
13+
# If the OBJECT_NAME is connected to ground, the filesystem is writable by CircuitPython
14+
storage.remount("/", readonly=button.value)

Adafruit_KB2040/Storage/code.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: Unlicense
3+
"""
4+
CircuitPython Essentials Storage CP Filesystem code.py file
5+
"""
6+
import time
7+
import board
8+
import microcontroller
9+
import neopixel
10+
11+
pixel = neopixel.NeoPixel(board.NEOPIXEL, 1)
12+
13+
try:
14+
with open("/temperature.txt", "a") as temp_log:
15+
while True:
16+
# The microcontroller temperature in Celsius. Include the
17+
# math to do the C to F conversion here, if desired.
18+
temperature = microcontroller.cpu.temperature
19+
20+
# Write the temperature to the temperature.txt file every 10 seconds.
21+
temp_log.write('{0:.2f}\n'.format(temperature))
22+
temp_log.flush()
23+
24+
# Blink the NeoPixel on every write...
25+
pixel.fill((255, 0, 0))
26+
time.sleep(1) # ...for one second.
27+
pixel.fill((0, 0, 0)) # Then turn it off...
28+
time.sleep(9) # ...for the other 9 seconds.
29+
30+
except OSError as e: # When the filesystem is NOT writable by CircuitPython...
31+
delay = 0.5 # ...blink the NeoPixel every half second.
32+
if e.args[0] == 28: # If the file system is full...
33+
delay = 0.15 # ...blink the NeoPixel every 0.15 seconds!
34+
while True:
35+
pixel.fill((255, 0, 0))
36+
time.sleep(delay)
37+
pixel.fill((0, 0, 0))
38+
time.sleep(delay)

CircuitPython_Templates/analog_pin_values/code.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: Unlicense
13
"""CircuitPython analog pin value example"""
24
import time
35
import board

CircuitPython_Templates/analog_voltage_values/code.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: Unlicense
13
"""CircuitPython analog voltage value example"""
24
import time
35
import board

CircuitPython_Templates/audio_find_pins/code.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: Unlicense
13
"""
24
CircuitPython Audio-capable pin identifying script
35
"""

CircuitPython_Templates/blink/code.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: Unlicense
13
"""CircuitPython Blink Example - the CircuitPython 'Hello, World!'"""
24
import time
35
import board

CircuitPython_Templates/cap_touch_one_pad/code.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: Unlicense
13
"""
24
CircuitPython Capacitive Touch Pad Example - Print to the serial console when one pad is touched.
35

0 commit comments

Comments
 (0)