Slide 1

Slide 1 text

Physical Computing with Scratch and Python

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Boot the Pi and open Scratch

Slide 4

Slide 4 text

GPIO Server ● GPIO Server On

Slide 5

Slide 5 text

Broadcast ● configXout ● gpioXon ● gpioXoff ● wait X secs ● forever Component GPIO pin Red LED 25 Amber LED 8 Green LED 7 Buzzer 15

Slide 6

Slide 6 text

Close Scratch and open Python 3

Slide 7

Slide 7 text

Open a new file ● File > New File ● File > Save ● Save as camjam.py

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

GPIO Zero LED from gpiozero import LED led = LED(25) led.blink()

Slide 10

Slide 10 text

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()

Slide 11

Slide 11 text

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()

Slide 12

Slide 12 text

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()

Slide 13

Slide 13 text

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()

Slide 14

Slide 14 text

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()

Slide 15

Slide 15 text

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()

Slide 16

Slide 16 text

Traffic Lights while True: lights.green.on() sleep(1) lights.amber.on() sleep(1) lights.red.on() sleep(1) lights.off()

Slide 17

Slide 17 text

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()

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

Documentation and help guides ● raspberrypi.org/documentation/usage/scratch/gpio ● gpiozero.readthedocs.org ● raspberrypi.org/resources ● raspberrypi.org/education/downloads

Slide 20

Slide 20 text

Physical Computing with Scratch and Python