p5.js deviceMoved() Function
The function deviceMoved() works in the device, and it is called when the device is moved by more than the threshold value along all the three X, Y or Z axis.
It only works in the device like mobile phones and it helps in detecting when the device is moved or rotated by more than a threshold value.
It can be used as a sensor in mobile devices like detecting motion, acceleration, rotation, heading, and location..
The default threshold is set to 0.5 and it can be changed using setMoveThreshold() function.
Now we will run some examples in android phones.
Step 1: Open online web editor of p5.js in the mobile phone using any browser “https://editor.p5js.org/”
Step 2: Write the following code in the editor section and run it to see the output.