#! /usr/bin/python3 # Last edited on 2018-07-06 17:07:56 by stolfilocal def wait_for_user_ok(): """Waits for user to type 'ok[ENTER]' or 'abort[ENTER]' on the python shell window. When she types 'ok', returns {True}. If she types 'abort' or CTRL-D (end-of-file), returns {False}. If the user types anything else, keeps asking again.""" while True: stderr.write("[muff_mainloop:] type 'ok[ENTER]' or 'abort[ENTER]': \n"); stderr.flush() s = stdin.readline() if s == "": # End of file: return False s = s.strip() # Remove leading and trailing whitespace, including EOL. if s == "ok": return True elif s == "abort": return False # ---------------------------------------------------------------------- def switch_lights_on(sport,Lset): nS = len(Lset); # Number of entries in {Lset} kS = 0; # Entry in {Lset}. lix_prev = -1 # Previous LED index from {Lset}. for lix in range(num_LEDs): # Make sure we have the next index from {Lset} in {lix_prev}: if lix_prev < lix: # Get next pair from {Lset}: if kS < nS: lix_prev = Lset[kS] kS = kS + 1 assert type(lix_prev) is int and lix_prev >= 0 and lix_prev < num_LEDs else: lix_prev = num_LEDs assert lix_prev >= lix # Decide the intensity of LED {lix}: if lix == lix_prev: pwr = 1.0 else: pwr = 0.0 # Turn the LED on or off: muff_arduino.switch_LED(sport,lix,pwr) # We must be done: assert kS == nS return