Professional Documents
Culture Documents
org/en/projects/introduction-to-the-pico/print
1 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
Ω Ω Ω
2 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
3 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
4 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
5 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
6 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
print('Hello World!')
7 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
8 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
9 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
10 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
11 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
12 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
13 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
14 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
15 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
16 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
17 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
18 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
pico_led.on()
19 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
20 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
22 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
Ω
Ω Ω
23 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
24 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
25 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
−
Needed Resistance =
( , )
. − .
Needed Resistance = .
26 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
27 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
28 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
29 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
30 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
31 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
32 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
led LED(13)
led_1 LED(13)
led_2 LED(8)
led_3 LED(5)
red_led LED(13)
green_led LED(8)
pink_led LED(5)
yellow LED(13)
yellow.on()
sleep(2)
yellow.off()
sleep(6)
led.off()
33 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
led.pulse(fade_in_time 2, fade_out_time 1, n 4, wait True) # take 2 seconds to brighten and 1 second to dim
print("Finished pulsing") # Runs after 4 pulses
led.blink(on_time 1, off_time 1, fade_in_time 1, fade_out_time 1) # On for 1 second, off for 1 second, fade between
print("Fancy") # Runs immediately
34 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
35 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
36 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
37 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
38 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
39 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
40 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
41 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
42 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
43 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
44 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
45 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
while True:
rgb.color (255, 0, 0)
sleep(0.5)
rgb.color (0, 255, 0)
sleep(0.5)
rgb.color (0, 0, 255)
sleep(0.5)
46 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
rgb.blink() # red for 1 second, green for 1 second, blue for 1 second
print("Blinking") # Runs immediately
sleep(6)
rgb.off()
rgb.pulse() # pulse red for 1 second, green for 1 second, blue for 1 second
print("Pulsing") # Runs immediately
# 2 second to fade from purple to off, 0.5 seconds to change from off to purple
rgb.pulse(fade_times (2, 0.5), colors ((255, 0, 255), (0, 0, 0)), wait True, n 3)
print("Finished pulsing") # Runs after 3 pulses
rgb.cycle() # Gradually colour cycle through colours between red and green, green and blue then blue and red
print("Cycle") # Runs immediately
47 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
48 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
49 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
50 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
speaker Speaker(5)
speaker_1 Speaker(5)
speaker_2 Speaker(10)
51 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
52 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
53 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
BEAT 1 # a constant
my_tune [ ['d5', 1], ['d#5', 0.5], ['f5', 1.2]] # the notes, along with the length of each note
54 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
55 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
def c_note():
speaker.play('c4', 0.5) # play the middle c for half a second
56 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
BEAT 0.4
liten_mus [ ['d5', BEAT 2], ['d#5', BEAT 2], ['f5', BEAT], ['d6', BEAT], ['a#5', BEAT], ['d5', BEAT],
['f5', BEAT], ['d#5', BEAT], ['d#5', BEAT], ['c5', BEAT 2],['d5', BEAT 2], ['d#5', BEAT],
['c6', BEAT], ['a5', BEAT], ['d5', BEAT], ['g5', BEAT], ['f5', BEAT], ['f5', BEAT], ['d5', BEAT 2],
['d#5', BEAT 2], ['f5', BEAT], ['g5', BEAT], ['a5', BEAT], ['a#5', BEAT], ['a5', BEAT], ['g5', BEAT],
['g5', BEAT], ['', BEAT 2], ['a#5', BEAT 2], ['c6', BEAT 2], ['d6', BEAT 2], ['c6', BEAT 2],
['a#5', BEAT 2], ['a5', BEAT 2], ['g5', BEAT 2], ['a5', BEAT 2], ['a#5', BEAT 2], ['c6',
BEAT],
['f5', BEAT], ['f5', BEAT], ['f5', BEAT 2], ['d#5', BEAT 2], ['d5', BEAT], ['f5', BEAT], ['d6',
BEAT],
['d6', BEAT 2], ['c6', BEAT 2], ['b5', BEAT], ['g5', BEAT], ['g5', BEAT], ['c6', BEAT 2],
['a#5', BEAT 2], ['a5', BEAT], ['f5', BEAT], ['d6', BEAT], ['a5', BEAT], ['a#5', BEAT 1.5] ]
def play_liten_mus():
speaker.play(liten_mus)
BEAT 0.4
liten_mus [ ['d5', BEAT 2], ['d#5', BEAT 2], ['f5', BEAT], ['d6', BEAT], ['a#5', BEAT], ['d5', BEAT],
['f5', BEAT], ['d#5', BEAT], ['d#5', BEAT], ['c5', BEAT 2],['d5', BEAT 2], ['d#5', BEAT],
['c6', BEAT], ['a5', BEAT], ['d5', BEAT], ['g5', BEAT], ['f5', BEAT], ['f5', BEAT], ['d5', BEAT 2],
['d#5', BEAT 2], ['f5', BEAT], ['g5', BEAT], ['a5', BEAT], ['a#5', BEAT], ['a5', BEAT], ['g5', BEAT],
['g5', BEAT], ['', BEAT 2], ['a#5', BEAT 2], ['c6', BEAT 2], ['d6', BEAT 2], ['c6', BEAT 2],
['a#5', BEAT 2], ['a5', BEAT 2], ['g5', BEAT 2], ['a5', BEAT 2], ['a#5', BEAT 2], ['c6',
BEAT],
['f5', BEAT], ['f5', BEAT], ['f5', BEAT 2], ['d#5', BEAT 2], ['d5', BEAT], ['f5', BEAT], ['d6',
BEAT],
['d6', BEAT 2], ['c6', BEAT 2], ['b5', BEAT], ['g5', BEAT], ['g5', BEAT], ['c6', BEAT 2],
['a#5', BEAT 2], ['a5', BEAT], ['f5', BEAT], ['d6', BEAT], ['a5', BEAT], ['a#5', BEAT 1.5] ]
57 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
speaker Speaker(5)
for i in range(100):
speaker.play(randint(500, 5000), duration None)
sleep(0.001)
speaker.stop()
sleep(0.5)
BEAT 0.4
liten_mus [ ['d5', BEAT 2], ['d#5', BEAT 2], ['f5', BEAT], ['d6', BEAT], ['a#5', BEAT], ['d5', BEAT],
['f5', BEAT], ['d#5', BEAT], ['d#5', BEAT], ['c5', BEAT 2],['d5', BEAT 2], ['d#5', BEAT],
['c6', BEAT], ['a5', BEAT], ['d5', BEAT], ['g5', BEAT], ['f5', BEAT], ['f5', BEAT], ['d5', BEAT 2],
['d#5', BEAT 2], ['f5', BEAT], ['g5', BEAT], ['a5', BEAT], ['a#5', BEAT], ['a5', BEAT], ['g5', BEAT],
['g5', BEAT], ['', BEAT 2], ['a#5', BEAT 2], ['c6', BEAT 2], ['d6', BEAT 2], ['c6', BEAT 2],
['a#5', BEAT 2], ['a5', BEAT 2], ['g5', BEAT 2], ['a5', BEAT 2], ['a#5', BEAT 2], ['c6',
BEAT],
['f5', BEAT], ['f5', BEAT], ['f5', BEAT 2], ['d#5', BEAT 2], ['d5', BEAT], ['f5', BEAT], ['d6',
BEAT],
['d6', BEAT 2], ['c6', BEAT 2], ['b5', BEAT], ['g5', BEAT], ['g5', BEAT], ['c6', BEAT 2],
['a#5', BEAT 2], ['a5', BEAT], ['f5', BEAT], ['d6', BEAT], ['a5', BEAT], ['a#5', BEAT 1.5] ]
def annoying_sound():
speaker2.play(sound, wait False) # don't delay the main code
button.when_pressed annoying_sound
try:
speaker.play(liten_mus)
finally:
speaker.off() # turns speaker off when code is stopped by user
speaker2.off() # turns speaker2 off when code is stopped by user
58 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
59 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
60 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
61 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
62 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
63 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
64 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
65 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
66 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
67 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
button Button(18)
button_1 Button(18)
button_2 Button(22)
button_3 Button(28)
switch Switch(18)
68 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
switch_1 Switch(18)
switch_2 Switch(22)
switch_3 Switch(28)
button_1.when_pressed function_1
button_2.when_pressed function_2
button_3.when_pressed function_3
def choice(): # call the next function and update the option
global option
if option 0:
rgb.color (255, 0, 0)
elif option 1:
rgb.color (0, 255, 0)
elif option 2:
rgb.color (0, 0, 255)
elif option 3:
rgb.off()
button.when_pressed choice # Call the choice function when the button is pressed
69 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
70 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
71 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
while True:
function_to_call dial.percent
print(function_to_call)
if function_to_call 20:
function_1()
elif function_to_call 40:
function_2()
elif function_to_call 60:
function_3()
elif function_to_call 80:
function_4()
else:
function_5()
sleep(0.1)
72 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
BEAT 0.4
liten_mus [ ['d5', BEAT 2], ['d#5', BEAT 2], ['f5', BEAT], ['d6', BEAT], ['a#5', BEAT], ['d5', BEAT],
['f5', BEAT], ['d#5', BEAT], ['d#5', BEAT], ['c5', BEAT 2],['d5', BEAT 2], ['d#5', BEAT],
['c6', BEAT], ['a5', BEAT], ['d5', BEAT], ['g5', BEAT], ['f5', BEAT], ['f5', BEAT], ['d5', BEAT 2],
['d#5', BEAT 2], ['f5', BEAT], ['g5', BEAT], ['a5', BEAT], ['a#5', BEAT], ['a5', BEAT], ['g5', BEAT],
['g5', BEAT], ['', BEAT 2], ['a#5', BEAT 2], ['c6', BEAT 2], ['d6', BEAT 2], ['c6', BEAT 2],
['a#5', BEAT 2], ['a5', BEAT 2], ['g5', BEAT 2], ['a5', BEAT 2], ['a#5', BEAT 2], ['c6',
BEAT],
['f5', BEAT], ['f5', BEAT], ['f5', BEAT 2], ['d#5', BEAT 2], ['d5', BEAT], ['f5', BEAT], ['d6',
BEAT],
['d6', BEAT 2], ['c6', BEAT 2], ['b5', BEAT], ['g5', BEAT], ['g5', BEAT], ['c6', BEAT 2],
['a#5', BEAT 2], ['a5', BEAT], ['f5', BEAT], ['d6', BEAT], ['a5', BEAT], ['a#5', BEAT 1.5]]
73 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
74 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
75 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
76 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
77 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
78 of 79 2023-07-26, 05:27 pm
Introduction to Raspberry Pi Pico guide https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/print
79 of 79 2023-07-26, 05:27 pm