2016-05-09 19:32:02 +02:00
|
|
|
# glowing pendulum block tutorial
|
|
|
|
|
2016-11-01 18:42:42 +01:00
|
|
|
The glowing pendulum changes the screen brightness based on the acceleration measured on the @boardname@.
|
2016-05-09 19:32:02 +02:00
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## Rebuild the game!
|
2016-05-09 19:32:02 +02:00
|
|
|
|
|
|
|
The blocks have been shuffled! Put them back together so that...
|
|
|
|
* all LEDs are turned on
|
2016-11-01 18:42:42 +01:00
|
|
|
* the @boardname@ repeats code **forever** that
|
2016-05-09 19:32:02 +02:00
|
|
|
* 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)
|
|
|
|
});
|
|
|
|
```
|