
> [クラスリファレンス](https://obniz.github.io/obniz/obnizjs/classes/obnizcore.hardware.m5stickc.html)
> [TypeScript](https://github.com/obniz/obniz/blob/master/src/obniz/libs/hw/m5stickc.ts)

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

## Defined Parts

In this class, the devices in the [parts library](/ja/sdk/parts) 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](https://obniz.github.io/obniz/obnizjs/classes/parts.axp192.axp192.html)

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

### buttonA

Front [Button](/sdk/parts/Button/README.md)

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


### buttonB

Upper [Button](/sdk/parts/Button/README.md)

```
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.

- [MPU6886](/ja/sdk/parts/MPU6886/README.md)
- [SH200Q](/ja/sdk/parts/SH200Q/README.md)

````
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](/sdk/parts/InfraredLED/README.md)

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


### led

RED [LED](/sdk/parts/LED/README.md)

```
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();
}
```