A p5.js library for controlling the AxiDraw pen plotter via the WebSerial API.
Upload the latest release as a file in your sketch and then reference it from index.html like so:
<head>
...
<script src="p5.axidraw.js"></script>
...
</head>
An example sketch that connects to the AxiDraw when the mouse is clicked and draws a diagonal line:
const axi = new axidraw.AxiDraw();
let connected = false;
function setup() {
createCanvas(400, 400);
}
function mouseClicked() {
if (!connected) {
// Note: connect() must be called from a user gesture (e.g. a mouse click) due to
// browser security restrictions
axi.connect()
.then(() => {
connected = true;
});
}
// Draw a diagonal line
axi.penDown();
axi.moveTo(10, 10);
axi.penUp();
// Draw a diagonal line, but async
// axi.penDown()
// .then(() => axi.moveTo(10, 10))
// .then(() => axi.penUp());
}
See the examples directory for more.
See jmpinit.github.io/p5.axidraw for the API docs.