<s> import pyb <EOL> sw = pyb . Switch ( ) <EOL> pyb . LED ( <NUM_LIT:2> ) . off ( ) <EOL> led = pyb . LED ( <NUM_LIT:1> ) <EOL> leds = ( pyb . LED ( <NUM_LIT:4> ) , pyb . LED ( <NUM_LIT:3> ) , pyb . LED ( <NUM_LIT:2> ) ) <EOL> try : <EOL> import boot_mode <EOL> persisted_mode = boot_mode . mode <EOL> mode = boot_mode . mode <EOL> except : <EOL> persisted_mode = - <NUM_LIT:1> <EOL> mode = <NUM_LIT:0> <EOL> def mode_led ( mode ) : <EOL> for led in leds : <EOL> led . off ( ) <EOL> if mode >= <NUM_LIT:0> : <EOL> leds [ mode ] . on ( ) <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> led . on ( ) <EOL> pyb . delay ( <NUM_LIT:100> ) <EOL> led . off ( ) <EOL> pyb . delay ( <NUM_LIT:100> ) <EOL> if sw ( ) : <EOL> while True : <EOL> mode_led ( mode ) <EOL> pyb . delay ( <NUM_LIT> ) <EOL> if not sw ( ) : <EOL> mode_led ( - <NUM_LIT:1> ) <EOL> break <EOL> mode = ( mode + <NUM_LIT:1> ) % <NUM_LIT:3> <EOL> break <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> mode_led ( mode ) <EOL> pyb . delay ( <NUM_LIT:100> ) <EOL> mode_led ( - <NUM_LIT:1> ) <EOL> pyb . delay ( <NUM_LIT:100> ) <EOL> usb_mode = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) [ mode ] <EOL> if mode != persisted_mode : <EOL> with open ( '<STR_LIT>' , '<STR_LIT:w>' ) as f : <EOL> f . write ( '<STR_LIT>' % mode ) <EOL> f . write ( "<STR_LIT>" % usb_mode ) <EOL> pyb . sync ( ) <EOL> pyb . usb_mode ( usb_mode ) <EOL> print ( '<STR_LIT>' % usb_mode ) <EOL> del led , leds , mode , usb_mode , persisted_mode , i , sw , mode_led , boot_mode </s>
