UNPKG

pxt-microbit

Version:

micro:bit target for Microsoft MakeCode (PXT)

69 lines (52 loc) 1.88 kB
# Plot Acceleration ## Introduction @unplugged The ``||led:plot bar graph||`` uses the screen to display the _magnitude_ (how big a number is whether it's positive or negative) of a value. This is a great tool to understand the data returned by sensors... like the accelerometer. ## Acceleration In a ``||basic:forever||`` loop, ``||led:plot||`` ``||input:acceleration||`` in the ``x`` dimension on the LEDs. ```blocks basic.forever(function() { led.plotBarGraph( input.acceleration(Dimension.X), 0 ) }) ``` ## Console Click on the **(+)** in the ``||led:plot bar graph||`` block to expand it. The ``||led:serial write||`` parameter will appear and is set to **ON**. Now, after a moment, the **Show data Simulator** button will show up near the simulator. Click on it to see a chart of the values plotted by the block over a period of time. Hover over the board in the simulator to make a force in the ``x`` dimension. ```blocks basic.forever(function() { led.plotBarGraph( input.acceleration(Dimension.X), 0, true ) }) ``` ## Maximum value If you specify the maximum value, the block can do a better job at displaying the data. For example, we can tell the block that we don't expect values beyond ``1000`` mg. ```blocks basic.forever(function() { led.plotBarGraph( input.acceleration(Dimension.X), 1000, true ) }) ``` ## Other sensors You can use this block for pretty much any kind of data. Try it out! Plot the ``||input:light level||`` inside the ``||basic:forever||`` instead. Play with the light sensor in the simulator. ```blocks basic.forever(function() { led.plotBarGraph( input.lightLevel(), 0, true ) }) ``` ## Download and try Download the code to your @boardname@ and test the sensors. ```template basic.forever(function() {}) ```