forked from CytronTechnologies/pxt-sumobit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbattery.ts
26 lines (24 loc) · 796 Bytes
/
battery.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*******************************************************************************
* Function for SUMO:BIT battery input
*
* Company: Cytron Technologies Sdn Bhd
* Website: http://www.cytron.io
* Email: [email protected]
*******************************************************************************/
namespace sumobit {
/**
* Read the current battery voltage (2 d.p.).
*/
//% group="Battery"
//% weight=49
//% blockGap=8
//% blockId=sumobit_battery_read
//% block="battery voltage"
export function readBatteryValue(): number {
let highByte: number;
let lowByte: number;
highByte = sumobit.i2cRead(REG_ADD_VIN_HIGH);
lowByte = sumobit.i2cRead(REG_ADD_VIN_LOW);
return ((highByte << 8) | lowByte) / 100;
}
}