Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Physical computing with Scratch and Python
Search
Ben Nuttall
March 21, 2016
Education
0
280
Physical computing with Scratch and Python
Physical computing with Raspberry Pi using Scratch and Python with GPIO Zero
Ben Nuttall
March 21, 2016
Tweet
Share
More Decks by Ben Nuttall
See All by Ben Nuttall
Numeronyms are obnoxious
bennuttall
0
220
Live Highlights in BBC iPlayer
bennuttall
0
63
Rapid prototyping in BBC News with Python and AWS
bennuttall
0
130
Rapid prototyping in BBC News with Python and AWS
bennuttall
0
79
Running a Python Package Index for Raspberry Pi
bennuttall
0
96
From Acorns to Raspberries
bennuttall
0
76
Innovation in the newsroom
bennuttall
0
91
Innovation in the newsroom - MOS Running Order Manager
bennuttall
0
150
How to market your open source project
bennuttall
0
200
Other Decks in Education
See All in Education
書を持って、自転車で町へ出よう
yuritaco
0
140
Казармы и гарнизоны
pnuslide
0
170
Ilman kirjautumista toimivia sovelluksia
matleenalaakso
1
20k
Sanapilvet opetuksessa
matleenalaakso
0
31k
Information Architectures - Lecture 2 - Next Generation User Interfaces (4018166FNR)
signer
PRO
0
1.4k
とある EM の初めての育休からの学び
clown0082
1
1.2k
オンラインゆっくり相談室ってなに?
ytapples613
PRO
0
150
Introduction - Lecture 1 - Information Visualisation (4019538FNR)
signer
PRO
0
4.3k
ThingLink
matleenalaakso
28
3.9k
Info Session MSc Computer Science & MSc Applied Informatics
signer
PRO
0
100
Unraveling JavaScript Prototypes
debug_mode
0
140
SAT Bootcamp and Course
syedmahadd
0
150
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
328
24k
Raft: Consensus for Rubyists
vanstee
137
6.8k
We Have a Design System, Now What?
morganepeng
51
7.4k
Docker and Python
trallard
44
3.3k
The Cult of Friendly URLs
andyhume
78
6.2k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
550
Building Flexible Design Systems
yeseniaperezcruz
328
38k
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
Why Our Code Smells
bkeepers
PRO
336
57k
Optimising Largest Contentful Paint
csswizardry
34
3.1k
How to Ace a Technical Interview
jacobian
276
23k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Transcript
Physical Computing with Scratch and Python
None
Boot the Pi and open Scratch
GPIO Server • GPIO Server On
Broadcast • configXout • gpioXon • gpioXoff • wait X
secs • forever Component GPIO pin Red LED 25 Amber LED 8 Green LED 7 Buzzer 15
Close Scratch and open Python 3
Open a new file • File > New File •
File > Save • Save as camjam.py
GPIO Zero LED from gpiozero import LED led = LED(25)
while True: led.on() sleep(1) led.off() sleep(1) Save and run: Ctrl + S F5
GPIO Zero LED from gpiozero import LED led = LED(25)
led.blink()
GPIO Zero Button + LED from gpiozero import Button, LED
button = Button(21) led = LED(25) while True: button.wait_for_press() led.on() button.wait_for_release() led.off()
GPIO Zero Button + LED from gpiozero import Button, LED
button = Button(21) led = LED(25) while True: led.on() button.wait_for_press() led.off() button.wait_for_release()
GPIO Zero Button + LED from gpiozero import Button, LED
button = Button(21) led = LED(25) while True: led.blink() button.wait_for_press() led.off() button.wait_for_release()
Traffic Lights from gpiozero import Button, TrafficLights button = Button(21)
lights = TrafficLights(25, 8, 7) while True: button.wait_for_press() lights.on() button.wait_for_release() lights.off()
Traffic Lights from gpiozero import Button, TrafficLights button = Button(21)
lights = TrafficLights(25, 8, 7) while True: lights.blink() button.wait_for_press() lights.on() button.wait_for_release()
Traffic Lights from gpiozero import Button, TrafficLights, Buzzer from time
import sleep button = Button(21) lights = TrafficLights(25, 8, 7) buzzer = Buzzer(15) while True: lights.on() buzzer.off() button.wait_for_press() lights.off() buzzer.on() button.wait_for_release()
Traffic Lights while True: lights.green.on() sleep(1) lights.amber.on() sleep(1) lights.red.on() sleep(1)
lights.off()
Traffic Lights while True: button.wait_for_press() lights.green.on() sleep(1) lights.amber.on() sleep(1) lights.red.on()
sleep(1) lights.off()
Traffic Lights Sequence • Can you make a full traffic
lights sequence? • Use the button for a pedestrian crossing • Use buzzer.beep() to indicate safe crossing
Documentation and help guides • raspberrypi.org/documentation/usage/scratch/gpio • gpiozero.readthedocs.org • raspberrypi.org/resources
• raspberrypi.org/education/downloads
Physical Computing with Scratch and Python