The device’s embedded software was written in C using the Microchip XC8 compiler in the MPLAB X Integrated Development Environment (IDE). A code flow chart is shown in Fig 3. The compiled program is downloaded to the device using the PICkit 3 programmer. The software implements three main functions: measuring and saving to memory the 1-bit value representing device IN or OUT, enabling data logging, and disabling data logging. All are based on comparison of Vth to a Vref generated in the microcontroller. Following completion of the initialization routine, the device enters a low-power sleep mode in a continuous loop waiting for 16-bit timer rollover. At each rollover (65538 counts at 32.768 kHz = 2 s), the device wakes and evaluates three options: (1) run the log comparator output (IN or OUT status) subroutine (green in Fig 3), (2) run the logging on/off subroutine (blue in Fig 3), or (3) return to sleep. The time interval for checking logging on/off status and logging comparator output is set in the program code. For prototype evaluation, the logging on/off subroutine was run every 2 rollovers (4 sec), and the data logging interval was varied from 10 s (5 wake cycles) to 5 min (150 wake cycles) depending on the test conditions.