37 lines
1.6 KiB
Markdown
37 lines
1.6 KiB
Markdown
|
# pogo activity
|
||
|
|
||
|
Construct a counter that uses acceleration.
|
||
|
|
||
|
To create a new script, go to the [Create Code](/microbit/create-code) page and tap `New Project` under `Block Editor`.
|
||
|
|
||
|
Welcome! This activity will teach how to construct a pendulum that glows using acceleration. Let's get started!
|
||
|
|
||
|
Create a **forever** loop that will constantly display the appropriate brightness on the LED display. Now let's measure the acceleration on the `y` axis and store that value in a variable. The `acceleration(y)` function will provide the value.
|
||
|
|
||
|

|
||
|
|
||
|
Since the micro:bit will be swinging up and down, we need to store the variable called jumps. We will set the variable called jumps to 0 to store the number 0.
|
||
|
|
||
|

|
||
|
|
||
|
The function `acceleration(y)` gets the acceleration value (milli g-force), in the `y` dimension. If the `acceleration(y)`is greater than 2000 milli g-force, we will change jumps by 1.
|
||
|
|
||
|
If the `acceleration(y)`is greater than 2000 milli g-force, we will display the image with `show LEDs` to display a smiley face on the LEDs and `clear screen` to to turn off all the LED lights on the LED screen.
|
||
|
|
||
|

|
||
|
|
||
|
Now let's register an event handler that will execute whenever an input button (A) is pressed during program execution.
|
||
|
|
||
|

|
||
|
|
||
|
Let's show what the brightness of the micro:bit is by turning all the LEDs on!
|
||
|
|
||
|

|
||
|
|
||
|
### ~avatar avatar
|
||
|
|
||
|
Excellent, you're ready to continue with the [challenges](/microbit/lessons/glowing-pendulum/challenges)!
|
||
|
|
||
|
### ~
|
||
|
|