This program does not work in the simulator, only in a micro:bit.
Set Accelerometer Range
Set up the part of the micro:bit that measures acceleration (how much the microbit is speeding up or slowing down), in case you need to measure high or low acceleration.
input.setAccelerometerRange(AcceleratorRange.OneG);
Parameters
range
means the biggest number of gravities of acceleration you will be measuring (either1g
,2g
,4g
, or8g
). Any bigger numbers will be ignored by your micro:bit, both when you are picking a number of gravities, and when you are measuring acceleration.
Example
This program sets the highest acceleration that your micro:bit will measure is 4G. Then it shows acceleration from side to side until you stop the program.
input.setAccelerometerRange(AcceleratorRange.FourG);
basic.forever(() => {
basic.showNumber(input.acceleration(Dimension.X));
});