File tree Expand file tree Collapse file tree 10 files changed +171
-1
lines changed
Capacitive_Touch_Two_Pins Expand file tree Collapse file tree 10 files changed +171
-1
lines changed Original file line number Diff line number Diff line change 1+ # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+ # SPDX-License-Identifier: Unlicense
3+ """
4+ CircuitPython analog voltage value example
5+ """
6+ import time
7+ import board
8+ import analogio
9+
10+ analog_pin = analogio .AnalogIn (board .A0 )
11+
12+
13+ def get_voltage (pin ):
14+ return (pin .value * 2.6 ) / 51653
15+
16+
17+ while True :
18+ print (get_voltage (analog_pin ))
19+ time .sleep (0.1 )
Original file line number Diff line number Diff line change 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 .A2 )
11+
12+ while True :
13+ if touch .value :
14+ print ("Pin touched!" )
15+ time .sleep (0.1 )
Original file line number Diff line number Diff line change 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 .A2 )
11+ touch_two = touchio .TouchIn (board .TX )
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 )
Original file line number Diff line number Diff line change 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 ))
Original file line number Diff line number Diff line change 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 time
7+ import board
8+ import digitalio
9+ import storage
10+ import neopixel
11+
12+ pixel = neopixel .NeoPixel (board .NEOPIXEL , 1 )
13+
14+ button = digitalio .DigitalInOut (board .BUTTON )
15+ button .switch_to_input (pull = digitalio .Pull .UP )
16+
17+ # Turn the NeoPixel blue for one second to indicate when to press the boot button.
18+ pixel .fill ((255 , 255 , 255 ))
19+ time .sleep (1 )
20+
21+ # If the button is connected to ground, the filesystem is writable by CircuitPython
22+ storage .remount ("/" , readonly = button .value )
Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff line change 77Update TOUCH_PIN_TWO to the pin name for the second touch-capable pin.
88
99For example:
10- If you are using A0 and A1 on a Feather RP2040, update TOUCH_PIN_ONE to A0 and TOUCH_PIN_TWO to A2 .
10+ If you are using A0 and A1 on a Feather RP2040, update TOUCH_PIN_ONE to A0 and TOUCH_PIN_TWO to A1 .
1111"""
1212import time
1313import board
Original file line number Diff line number Diff line change 66import adafruit_mcp9808
77
88i2c = board .I2C () # uses board.SCL and board.SDA
9+ # import busio
10+ # i2c = busio.I2C(board.SCL1, board.SDA1) # For QT Py RP2040, QT Py ESP32-S2
911mcp9808 = adafruit_mcp9808 .MCP9808 (i2c )
1012
1113while True :
Original file line number Diff line number Diff line change 33"""
44CircuitPython Essentials Storage CP Filesystem boot.py file
55
6+ REMOVE THIS LINE AND ALL TEXT BELOW BEFORE SUBMITTING TO GITHUB.
67There are three things to be updated in this file to match your board:
78* Update OBJECT_NAME to match the physical thing you are using, e.g. button or pin.
89* Update OBJECT_PIN to match the pin name to which the button or pin is attached.
Original file line number Diff line number Diff line change 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+ REMOVE THIS LINE AND ALL TEXT BELOW BEFORE SUBMITTING TO GITHUB.
7+ This file is specific to boards like ESP32-S2 where the boot button is used for bootloader and
8+ safe mode, and therefore the button must be pressed at the right time to get into readonly mode.
9+
10+ There are two things to be updated in this file to match your board:
11+ * Update OBJECT_PIN to match the pin name to which the button or pin is attached.
12+ * Update UP_OR_DOWN to match the Pull necessary for the chosen pin.
13+
14+ For example:
15+ If using the boot button on a QT Py ESP32-S2, OBJECT_PIN to BUTTON.
16+
17+ For example:
18+ If using the boot button on a QT Py ESP32-S2, update UP_OR_DOWN to UP.
19+ """
20+ import time
21+ import board
22+ import digitalio
23+ import storage
24+ import neopixel
25+
26+ pixel = neopixel .NeoPixel (board .NEOPIXEL , 1 )
27+
28+ button = digitalio .DigitalInOut (board .OBJECT_PIN )
29+ button .switch_to_input (pull = digitalio .Pull .UP_OR_DOWN )
30+
31+ # Turn the NeoPixel blue for one second to indicate when to press the boot button.
32+ pixel .fill ((255 , 255 , 255 ))
33+ time .sleep (1 )
34+
35+ # If the button is connected to ground, the filesystem is writable by CircuitPython
36+ storage .remount ("/" , readonly = button .value )
You can’t perform that action at this time.
0 commit comments