Getting Started
To create a custom device follow the instructions below.
- Create a new device class which extends the DeviceController class.
import { DeviceController } from "@espruino-tools/core";
export class MyNewDevice extends DeviceController {
constructor() {
super();
}
}
- From here you can use the
UART.write()
method to write directly to the device using the espruino commands or use the built in methods such asdevice.Pin.analogOn('D1',0.5)
.
export class MyNewDevice extends DeviceController {
constructor() {
super();
}
myNewMethod() {
this.UART.write("/* do something in espruino js */");
}
motorOn(speed) {
this.Pin.analogOn("D1", speed);
}
}
- From here you can import your new class and not have to worry about reimplementing connection, writing or evaluating methods.
import { MyNewDevice } from "./my-new-device-class.js";
let device = new MyNewDevice();
device.connect(function () {
console.log("connected");
});
device.myNewMethod();
device.motorOn();