Friday, July 29, 2016

Using Scratch to control Raspberry Pi GPIO

In the previous post, I have built my first circuit and able to control the LED light using the gpio command:
http://pandaeatsbamboo.blogspot.hk/2016/07/the-hello-world-circuit-with-raspberry.html

Similar control can be done via Scratch, this is the official tutorial:
https://www.raspberrypi.org/blog/a-new-version-of-scratch-for-raspberry-pi-now-with-added-gpio/

This is a super simple Scratch script to illustrate this:


In this simple script, when you click the flag icon, it will set the gpio pin 17 (BCM) to 1 to switch on the LED.  When you press the spacebar on your keyboard, it will set the gpio pin 17 to 0 to switch off the LED.  With this you can incorporate the GPIO control into your own scratch script.  Give it a try!

No comments: