Today I was continuing with Scratch but it was a little-bit different. I was trying to control GPIO pins and my breadboard using Scratch. This type of Scratch was absolutely full of interesting new ideas, possible projects and other worlds of wonder! If you can control gpio pins, you can do anything! (insert mad scientist laugh here)
The instructions that I followed are found here but they’re a little complicated for a noob like me. So, I had to look at other pages also to read resistor color codes, find pin diagrams, and use variables in Scratch.
The first step is to install a new version of scratch that has support for GPIO. Here are the commands. It’s best to copy and paste them because there are many opportunities to make typing mistakes (this all goes on one line):
sudo wget https://dl.dropbox.com/s/gery97qildl7ozd/install_scratch_gpio.sh -O /boot/install_scratch_gpio.sh
When you type “startx” and go into Linux, you’ll notice a new version of Scratch (don’t worry, your old version is still there too). You’ll see some new things. There’s a block called “broadcast” that will let you turn on a GPIO pin by putting “broadcast pin11high” for example.
So, first, I connected an LED (and resistor) and ran the program that comes with it to blink the LED. It was pretty simple, turn pin 11 high for one second and then low for 2 seconds. But I decided that I wanted to use a push button on the breadboard. The website above talks about inputs a little bit, but I had to go to other pages to figure out how to wire it up. This one worked for me.
To figure out if the button is pressed or not, you use a “sensor value” block. I used pin7, so my block said “pin7 sensor value”. I wanted to put this into an “if” block, but it wouldn’t let me. So, I put it in a “think” block and I could see that when the button was not pressed, Scratchy would think “1” and when it was pressed, Scratchy would think “0”. So, I ended up storing the 1 or 0 in a variable called “button” and I used an “if” statement, “if button = 0” to trigger the program when the button is pressed.
Only problem with my little program is that I have to hold the button down. I might try to make it so that I press it once to start the blinking and again to stop the blinking.
I earlier read about someone who controlled a RC car with the Scratch Programming language and an RPI. I feel that that is really cool and hope that I could do something like that but with my own nerdy, girly flare to it. Now that I am able to control LEDS…… I CAN CONTROL THE WORLD mwa ha ha, just kidding.
Here’s a picture of the code that I used:
And here’s a video of my dad pressing the button while I click the green flag: