Example 1: Simulated Accelerometer
Code
let history = [];
function setup() {
createCanvas(400, 400);
}
function draw() {
background(252);
const sensor = 0.5 + 0.5 * sin(frameCount * 0.04);
history.push(sensor);
if (history.length > width) history.shift();
stroke(255, 45, 140);
noFill();
beginShape();
for (let i = 0; i < history.length; i++) {
const y = map(history[i], 0, 1, height - 30, 30);
vertex(i, y);
}
endShape();
fill(20);
noStroke();
text('sim sensor: ' + sensor.toFixed(2), 12, 20);
}Try this: Replace the simulation value with real sensor or serial input later.