pxt-calliope/olddocs/lessons/glowing-pendulum/tutorial.md
Tom Ball f4eca66648 move lessons out of web site
will move select lessons back to "educators" section
2016-06-14 11:49:58 -04:00

30 lines
833 B
Markdown

# glowing pendulum block tutorial
The glowing pendulum changes the screen brightness based on the acceleration measured on the BBC micro:bit.
### Rebuild the game!
The blocks have been shuffled! Put them back together so that...
* all LEDs are turned on
* the BBC micro:bit repeats code **forever** that
* reads the acceleration along the ``y`` axis,
* calculate the absolute value of the acceleration
* scales down the acceleration value by a factor of `4`
* uses the scaled value to set the screen **brightness**
```blocks
basic.showLeds(`
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
`)
basic.forever(() => {
let acceleration = input.acceleration(Dimension.Y);
acceleration = Math.abs(acceleration);
acceleration = acceleration / 4;
led.setBrightness(acceleration)
});
```