As of June 2017, there is a version of Scratch 2.0 on Raspbian which makes this worksheet obsolete [/edit]
The first thing the boys did was to figure out how to use some of the sensors on the SenseHat – remember how in my other post, I said it was good practice to run the basic broadcast command before you do anything.
We had found some code from Albert’s GitHub page, however, when we tried to select the sensor value for accelerometer, we only had a few choices as shown below.
Luckily, after trying a few things, I suggested that we hit the green flag to check that the GPIO pins were on and that Scratch knew we had a SenseHat attached. When we next checked the sensing options a while heap of new options appeared, including the accelerometer (sorry, I forgot to screenshot it).
The boys had great fun playing with the sensors, but couldn’t quite figure out how to get the ‘shake’ function working so they went back to the original code for Interactive Pixel Pet.
x, y, z = sense.get_accelerometer_raw().values() while x<2 and y<2 and z<2: x, y, z = sense.get_accelerometer_raw().values()
This is what they come up with:
A job well done, if I do say so!
Now, I’m sure some of you have spotted that I could neaten up my code by removing the ‘ledbackground’ line and that ‘clearleds’ would be better suited to the end of the repeat loop as that would leave me with a completely blank neopixel array at the end of the animation sequence, but otherwise I’m pleased with our work in recreating the pixel pet for Scratch.
I look forward to trying out some of the other sensors using Scratch in the future!