UNPKG

@ongzzzzzz/p5.web-serial

Version:

A p5.js library for using the Web Serial API to access devices like Arduino, no setup required

25 lines (22 loc) 468 B
let port, reader, writer; async function setup() { createCanvas(windowWidth, windowHeight); background("black"); noLoop(); ({ port, reader, writer } = await getPort()); loop(); } async function draw() { if (port) { try { if (mouseIsPressed) { background("RED"); await writer.write("clicked!\n"); } else { background("BLACK"); await writer.write("not clicked!\n"); } } catch (e) { console.error(e) } } }