Artekit PropBoard: Power API
Power API documentation for the Artekit PropBoard.
Power API
The Power API contains functions to manage the low-power feature of the PropBoard and to measure the battery.
enterLowPowerMode function
Call this function to set the PropBoard into low-power mode. You can wake-up the board by sending a rising or falling edge to the pin specified by the pin parameter. Calling this function will shutdown the 3.3V and 5V domain, including audio amplifier, DAC, LED outputs and optionally the motion sensor.
Syntax
void enterLowPowerMode(uint32_t pin, uint32_t mode, bool motion_enabled = false);
Parameters
The pin parameter can be any pin from this list where the IRQ column is set to YES (actually, from pin 1 to pin 8), including pin 14 and pin 15. The pin 14 and 15 are the interrupts of the motion sensor and can also be used to wake-up the board. The motion sensor interrupt type and mode has to be previously configured. To learn about the motion sensor, refer to the PropBoard: Motion API document.
The mode parameter specifies the type of edge of the signal into the pin pin needed to wake-up the board. Can be one of the following values:
- FALLING: wake-up on a falling edge.
- RISING: wake-up on a rising edge.
- CHANGE: wake-up on a falling or rising edge (not recommended).
If the motion_enabled parameter is set to true then the function does not shutdown the motion sensor. This parameter is useful if you want to wake-up the board using one of the interrupts of the motion sensor (pin 14 or pin 15). If this parameter is omitted, it is defaulted to false.
Returns
If the function succeeds, it does not returns. See Notes here below.
Notes
If the function successfully sets the board into low-power mode, it does not returns. When the desired edge is detected on the specified pin, the board auto-resets and the program starts from the beginning. If the function fails, it returns and the program continues execution (for example, if a wrong pin number is passed to it).
You can always wake up the board from a reset from the Arduino IDE (for example, by downloading a new sketch) or by plugging the power supply again.
Example
// Set to true somewhere else in the program
bool power_off_condition = false;
void setup()
{
// Configure pin 3 as an input
pinMode(3, INPUT);
// Enable pull-up resistor
digitalWrite(3, 1);
// Do other stuff
Audio.begin();
}
void loop()
{
// Is power off condition met?
if (power_off_condition)
{
// Shutdown the board by entering in low-power mode and
// wake-up with a falling edge on pin 3.
enterLowPowerMode(3, FALLING);
}
}
readBattery function
Use the readBattery
function to read the current battery level, or the level of any power supply connected to the power connector, in millivolts.
Syntax
uint16_t readBattery()
Parameters
None.
Returns
The current battery level in millivolts.
Example
void setup()
{
// Configure serial
Serial.begin(9600);
}
void loop()
{
// Read battery
uint16_t battery = readBattery();
// Print the battery level to Serial
Serial.print("Battery: ");
Serial.print(battery);
Serial.println("mV");
delay(1000);
}