Thanks for clarifying this! I am still figuring out how to apply it to detect whether there is USB power or not, while operating on battery. digitalRead(CHG) and digitalRead(PWR) are both 0 with battery plugged in, whether USB is plugged in or not. Should I be approaching this in a different way?
Based on that if you have both battery and usb you’ll see the usb is only used to charge the battery, then it runs off battery for awhile. That surprised me, I thought it’d charge the battery and then run off the USB but that’s not what the above is showing in my testing.
–April update: I think the battery part of the above is wrong. It appears to use USB and not battery, when USB is available, thus onBatteryPower = !hasUsbPower; is what I use now. The part that tripped me up before is the voltage is different between USB only and USB + charged battery.
Is it possible to do conditional compilation based on what the target board is? Some sort of #if .... #endif to check power one way for xenon and another for boron? I’d really like to have one code base to roll out on both boards if possible.