File tree Expand file tree Collapse file tree 9 files changed +115
-0
lines changed
CircuitPython_Digital_Input
CircuitPython_PWM_multiMP3 Expand file tree Collapse file tree 9 files changed +115
-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 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 .D5 )
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 .D6 , board .D5 , board .D9 )
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 .D6 , board .D5 , board .D9 )
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: 2021 Kattni Rembor for Adafruit Industries
2+ # SPDX-License-Identifier: MIT
3+ """
4+ CircuitPython single MP3 playback example.
5+ Plays a single MP3 once.
6+ """
7+ import board
8+ import audiomp3
9+ import audiopwmio
10+
11+ audio = audiopwmio .PWMAudioOut (board .A0 )
12+
13+ with open ("slow.mp3" , "rb" ) as mp3_file :
14+ decoder = audiomp3 .MP3Decoder (mp3_file )
15+
16+ audio .play (decoder )
17+ while audio .playing :
18+ pass
19+
20+ print ("Done playing!" )
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 multiple MP3 playback example.
5+ Plays two MP3 files consecutively, once time each.
6+ """
7+
8+ import board
9+ import audiomp3
10+ import audiopwmio
11+
12+ audio = audiopwmio .PWMAudioOut (board .A0 )
13+
14+ mp3files = ["slow.mp3" , "happy.mp3" ]
15+
16+ with open (mp3files [0 ], "rb" ) as mp3 :
17+ decoder = audiomp3 .MP3Decoder (mp3 )
18+
19+ for filename in mp3files :
20+ with open (filename , "rb" ) as decoder .file :
21+ audio .play (decoder )
22+ print ("Playing:" , filename )
23+ while audio .playing :
24+ pass
25+
26+ print ("Done playing!" )
You can’t perform that action at this time.
0 commit comments