import gpio import i2c // https://github.com/toitware/toit-axp192/blob/v1.0.1/src/axp192.toit import axp192 main: led_pin := gpio.Pin 10 --output led_pin.set 0 sleep --ms=100 i2c_bus := i2c.Bus --sda=gpio.Pin 21 --scl=gpio.Pin 22 axp192_device := i2c_bus.device 0x34 axp192.set_bits axp192_device axp192.ADC_ENABLE_SETTING_REGISTER_1 axp192.ADC_ENABLE_BATTERY_VOLTAGE // https://github.com/m5stack/M5StickC/blob/b4c4b15d4608472948af069afe8081e218296b06/src/AXP192.cpp#L354 battery_voltage := ( ((axp192_device.registers.read_u8 0x78) << 4) \ + (axp192_device.registers.read_u8 0x79) \ ) * 1.1 / 1000 print "battery $(%.03f battery_voltage)V"