File tree Expand file tree Collapse file tree 12 files changed +289
-0
lines changed Expand file tree Collapse file tree 12 files changed +289
-0
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: MIT
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 .A1 )
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: MIT
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 .A1 )
11+ touch_two = touchio .TouchIn (board .A2 )
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: MIT
3+ """
4+ CircuitPython Digital Input Example - Blinking an LED using a button switch.
5+ """
6+ import board
7+ import digitalio
8+
9+ led = digitalio .DigitalInOut (board .LED )
10+ led .direction = digitalio .Direction .OUTPUT
11+
12+ button = digitalio .DigitalInOut (board .A1 )
13+ button .switch_to_input (pull = digitalio .Pull .UP )
14+
15+ while True :
16+ if not button .value :
17+ led .value = True
18+ else :
19+ led .value = False
Original file line number Diff line number Diff line change 1+ # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+ # SPDX-License-Identifier: MIT
3+ """
4+ CircuitPython I2S Tone playback example.
5+ Plays a tone for one second on, one
6+ second off, in a loop.
7+ """
8+ import time
9+ import array
10+ import math
11+ import audiocore
12+ import board
13+ import audiobusio
14+
15+ audio = audiobusio .I2SOut (board .A0 , board .A1 , board .A2 )
16+
17+ tone_volume = 0.1 # Increase this to increase the volume of the tone.
18+ frequency = 440 # Set this to the Hz of the tone you want to generate.
19+ length = 8000 // frequency
20+ sine_wave = array .array ("h" , [0 ] * length )
21+ for i in range (length ):
22+ sine_wave [i ] = int ((math .sin (math .pi * 2 * i / length )) * tone_volume * (2 ** 15 - 1 ))
23+ sine_wave_sample = audiocore .RawSample (sine_wave )
24+
25+ while True :
26+ audio .play (sine_wave_sample , loop = True )
27+ time .sleep (1 )
28+ audio .stop ()
29+ time .sleep (1 )
Original file line number Diff line number Diff line change 1+ # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+ # SPDX-License-Identifier: MIT
3+ """
4+ CircuitPython I2S WAV file playback.
5+ Plays a WAV file once.
6+ """
7+ import audiocore
8+ import board
9+ import audiobusio
10+
11+ audio = audiobusio .I2SOut (board .A0 , board .A1 , board .A2 )
12+
13+ with open ("StreetChicken.wav" , "rb" ) as wave_file :
14+ wav = audiocore .WaveFile (wave_file )
15+
16+ print ("Playing wav file!" )
17+ audio .play (wav )
18+ while audio .playing :
19+ pass
20+
21+ print ("Done!" )
Original file line number Diff line number Diff line change 1+ # SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries
2+ #
3+ # SPDX-License-Identifier: MIT
4+
5+ """
6+ CircuitPython PWM Audio Out tone example
7+ Plays a tone for one second on, one
8+ second off, in a loop.
9+ """
10+ import time
11+ import array
12+ import math
13+ import board
14+ from audiocore import RawSample
15+ from audiopwmio import PWMAudioOut as AudioOut
16+
17+ audio = AudioOut (board .A0 )
18+
19+ tone_volume = 0.1 # Increase this to increase the volume of the tone.
20+ frequency = 440 # Set this to the Hz of the tone you want to generate.
21+ length = 8000 // frequency
22+ sine_wave = array .array ("H" , [0 ] * length )
23+ for i in range (length ):
24+ sine_wave [i ] = int ((1 + math .sin (math .pi * 2 * i / length )) * tone_volume * (2 ** 15 - 1 ))
25+
26+ sine_wave_sample = RawSample (sine_wave )
27+
28+ while True :
29+ audio .play (sine_wave_sample , loop = True )
30+ time .sleep (1 )
31+ audio .stop ()
32+ time .sleep (1 )
Original file line number Diff line number Diff line change 1+ # SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries
2+ #
3+ # SPDX-License-Identifier: MIT
4+
5+ """
6+ CircuitPython PWM Audio Out WAV example
7+ Play a WAV file once.
8+ """
9+ import board
10+ from audiocore import WaveFile
11+ from audiopwmio import PWMAudioOut as AudioOut
12+
13+ audio = AudioOut (board .A0 )
14+
15+ with open ("StreetChicken.wav" , "rb" ) as wave_file :
16+ wave = WaveFile (wave_file )
17+ print ("Playing wav file!" )
18+ audio .play (wave )
19+ while audio .playing :
20+ pass
21+
22+ print ("Done!" )
Original file line number Diff line number Diff line change 1+ # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+ # SPDX-License-Identifier: MIT
3+ """
4+ CircuitPython Essentials Storage CP Filesystem boot.py file
5+ """
6+ import board
7+ import digitalio
8+ import storage
9+
10+ pin = digitalio .DigitalInOut (board .A0 )
11+ pin .switch_to_input (pull = digitalio .Pull .UP )
12+
13+ # If the pin is connected to ground, the filesystem is writable by CircuitPython
14+ storage .remount ("/" , readonly = pin .value )
You can’t perform that action at this time.
0 commit comments