(Startup) Mode variable->startup Relay->off Motors->isolate Gyro->initialize/check Voltage levels->check Button press->check With button 2 pressed, set safemode variable active (which sets an artificial voltage limit) With button 4 pressed, enter hall effect sensor calibration With button 3+4 pressed, enter current loop PID calibration With button 1+4 pressed, enter balancing PID calibration With no button press, start up normally: output status on LEDs: error: flashing red LED, error code on other 3 LEDs 0% battery - 000 (just flashing red) could not initialize gyro/acc - 100 (green on) 15v voltage invalid - 010 (yellow on) 5v voltage invalid - 001 (orange on) temperature reading invalid - 011 (yellow+orange) hall effect sensors invalid - 110 (green+yellow) current readings invalid - 111 (green+yellow+orange) ok: battery status shown on LEDs, 25% = red, 50% = red+orange, 75% = red+orange+yellow, 100% = red+orange+yellow+green status shown for 1 second (or error indefinitely) run the voltage safety check in background (or not? don't want to be too safe and mess up the motor processing) then Relay->on Mode variable->standby Motors->short start gyro/acc polling interrupt timer that will update internal variables (specifically board angle, board rotation and others will be used only in the interrupt) status shown by top LED of battery level (ie green for 100%) blinking, to signify board is on and in standby mode software timer started for 10 seconds, after which automatic shutdown occurs due to inactivity shutdown is also initiated by any button press (in the standby mode) monitor the board angle variable and rider foot sensors until the running condition is maintained for 2 seconds (use a software timer): board angle within 5 degrees of vertical on both axes (assuming loose board is 10-20 degrees) both feet are touching the board if running condition is entered but not maintained for 2 seconds, reset the 10 second shutdown timer (to allow more time for another attempt) if running condition entered: Mode variable->run Show status->top LED showing battery condition glows solid Motor set current->0 Motors->run enable physics interrupt timer (in same function as gyro/acc polling) enable hall sensor and speed/accel calculation interrupt timer enable PWM and ADC measurements (bulk of the work is handled by the interrupts) keep track of when absolute speed exceeds 5mph then set forward direction variable to the direction associated with the speed otherwise and if acceleration is small (ie not stopping after gaining speed but cruising/balancing in the slow zone) reset the forward direction to none monitor for presence of standby condition (no time requirement): absolute speed < 1 mph and turning angle > 10 degrees (board tilted heavily at slow speed) speed < 1 mph in forward direction, forward direction has been set (at least 5mph), and board angle tilted to decelerate in forward direction (stopping after run) no rider foot contact or extreme board position (overturned, etc) - this might be dangerous to implement in case it triggers improperly with standby condition met, enter standby mode above otherwise loop while riding, letting interrupts handle the work entering calibration modes: flash calibration status LEDs for two seconds, during which if buttons are released resume regular startup if buttons not released, turn on LEDs glowing solid, then wait until all buttons are released before proceeding set different interrupt routines (ISRs) than normal, which are not as optimized and check for other settings, while enabling voltage control, etc.