Obniz.M5StickC

クラスリファレンス
TypeScript

Obniz.M5StickC is a predefined class for M5StickC by M5.

Defined Parts

In this class, the devices in the parts library are used to create
The electronic components on the device (M5StickC) are pre-registered in the class.
They are automatically initialized and ready for use when connected.

axp

Power Management AXP192

var obniz = new Obniz.M5StickC('OBNIZ_ID_HERE');
obniz.onconnect = async function() {
  const Vbat = await obniz.axp.getVbat();
}

buttonA

Front Button

var obniz = new Obniz.M5StickC('OBNIZ_ID_HERE');
obniz.onconnect = async function() {
  obniz.buttonA.onchange = () => {
    console.log("changed");
  }
}

buttonB

Upper Button

var obniz = new Obniz.M5StickC('OBNIZ_ID_HERE');
obniz.onconnect = async function() {
  obniz.buttonB.onchange = () => {
    console.log("changed");
  }
}

imu

Accelerometer and gyroscope. the M5StickC has different built-in IMUs depending on the version. This library automatically detects and switches components.

Only the IMU is not initialized automatically. Call setupIMUWait() once.

var obniz = new Obniz.M5StickC("OBNIZ_ID_HERE");
obniz.onconnect = async () => {
    await obniz.setupIMUWait();
    const accel = await obniz.imu.getAccelWait();
    const gyro = await obniz.imu.getGyroWait();
}

ir

Infrared LED

var obniz = new Obniz.M5StickC('OBNIZ_ID_HERE');
obniz.onconnect = async function() {
  obniz.ir.send([0x00, 0x01]);
}

led

RED LED

var obniz = new Obniz.M5StickC('OBNIZ_ID_HERE');
obniz.onconnect = async function() {
  obniz.led.blink();
}

Interface

Below interface is prepared

grove0

Grove Connector on M5StickC

let obniz = new Obniz.M5StickC("OBNIZ_ID");
obniz.onconnect = async () => {
    const speaker = obniz.wired("Grove_Speaker", {grove: obniz.grove0});
    speaker.play(1000); //1000hz
    await obniz.wait(1000);
    speaker.stop();
}