Project 15: Balancing Dot

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
Description of the LED dot app: Uses an LED Matrix and Accelerometer to move a dot around the LED Matrix.
Only one of the LED Matrix drawing functions is needed: point(). The point() function is used to draw a dot on the Matrix. The program continually reads the forces on the accelereometer, and when the force passes a threshold, the point is moved.
Breadboard

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.

Hook as the Accelerometer the same way as was done in previous examples. The LED Matrix and Accelerometer circuits need to sit separately on the breadboard - they don't interact with each other.

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)

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.

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.

How do you prevent the dot from falling off the screen?

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 Accel
Note that the dot will just run right off the screen. It'll come back, though.

This is a summary of this thing
Lorem ipsum dolor sit amet, consectetuer adipiscing.
Connect the LED Matrix
This is a summary of this thing
Lorem ipsum dolor sit amet, consectetuer adipiscing.
Connect the LED Matrix