Description | Create a dot - a single point of light on the LED Matrix - that moves around on the LED Matrix as you tilt the screen. The effect is that it appears that the user is balancing a dot on the lid of the RaspberrySTEM. |
Materials |
RaspberrySTEM™ Base with Raspberry Pi
RaspberrySTEM™ CREATOR Lid LED Matrix RaspberrySTEM™ Cell AccelerometerRaspberrySTEM™ Cell |
Prerequisites | Accelerometer & LED Matrix Projects |
As in the previous LED Matrix examples, initialize the framebuffer:
from rstem.led_matrix import FrameBuffer
fb = FrameBuffer()Create an infinite loop that writes a point() to the display.
fb.erase() fb.point(x, y) fb.show()You should see the point displayed on the screen.
Didn't work - no worries. Go back to the first LED Matrix Project to troubleshoot the circuit.
As in the previous Accelerometer examples, initialize the Accelerometer:
from rstem.accel import Accel
accel = Accel()As in the previous Accelerometer examples, you can get all the forces with:
x_force, y_force, z_force = accel.forces()As a quick check to make sure the accelerometer is working, just print out the forces returned from the Accelerometer:
print(x_force, y_force, z_force)
What is a "threshold"? ...
The effect should be that tilting the board left and right move the dot to the left and right. Adjust the threshold and step (the amount of the increase or decrease) so that the dot moves at a reasonable rate.
Note that the dot will just run right off the screen. It'll come back, though.
Each time you In your game loop, check if the x_force is greater than some threshold. If so, increase x a little bit. Likewise, if the x_force is lower than some threshold, decrease x.
The effect should be that tilting the board left and right move the dot to the left and right. Adjust the threshold and step (the amount of the increase or decrease) so that the dot moves at a reasonable rate.
from rstem.accel import AccelNote that the dot will just run right off the screen. It'll come back, though.