def hit(points): pin1.write_digital(1) sleep(10) pin1.write_digital(0) points = max(points - 1, 0) redraw_points(points) return points
def removePowerFromSwitches(): pin0.write_digital(0) # switch 1, coin 1 pin1.write_digital(0) # switch 1, coin 2 pin2.write_digital(0) # switch 2, coin 1 pin3.write_digital(0) # switch 2, coin 2 pin4.write_digital(0) # switch 3, coin 1 pin6.write_digital(0) # switch 3, coin 2 pin7.write_digital(0) # switch 4, coin 1 pin9.write_digital(0) # switch 4, coin 2
def Light(colour, illuminate): if colour == "Red": if illuminate == "On": pin0.write_digital(1) elif illuminate == "Off": pin0.write_digital(0) elif colour == "Yellow": if illuminate == "On": pin1.write_digital(1) elif illuminate == "Off": pin1.write_digital(0) elif colour == "Green": if illuminate == "On": pin2.write_digital(1) elif illuminate == "Off": pin2.write_digital(0)
def read_distance(self): self.motor_stop(LEFT_MOTOR) self.motor_stop(RIGHT_MOTOR) divider = 42 maxtime = 250 * divider pin2.read_digital() pin1.write_digital(0) utime.sleep_us(2) pin1.write_digital(1) utime.sleep_us(10) pin1.write_digital(0) duration = machine.time_pulse_us(pin2, 1, maxtime) distance = duration / divider color = (0, 255, 0) if distance <= 35: color = (255, 0, 0) elif distance > 35 and distance < 50: color = (255, 128, 0) for led in range(4): self.np[led] = color self.np.show() return distance
def State(state): if state == "stop": pin0.write_digital(1) pin1.write_digital(0) pin2.write_digital(0) elif state == "getReady": pin0.write_digital(1) pin1.write_digital(1) pin2.write_digital(0) elif state == "go": pin0.write_digital(0) pin1.write_digital(0) pin2.write_digital(1) elif state == "readyToStop": pin0.write_digital(0) pin1.write_digital(1) pin2.write_digital(0)
else: stepspermin = 60 # avoid in average steps dropping too fast, Normal walk is > 80.... # amplitude average data if peaks[current_peak-1] != -1 and valleys[current_valley-1] != 2000: amplitude_window_values[count_amplitude] = peaks[current_peak-1] - valleys[current_valley-1] stepspermin_window_values[count_amplitude] = stepspermin count_amplitude = count_amplitude + 1 count_amplitude = count_amplitude % RAVG_AMP_WIN amplitude_avg = int(round(mymean(amplitude_window_values), 0)) stepspermin_avg = int(round(mymean(stepspermin_window_values), 0)) determine_toewalk(amplitude_avg, stepspermin_avg) if notify_bad_walk: # set pin 1 high pin1.write_digital(1) else: # pin0.write_digital(0) pin1.write_digital(0) if standing_still: pin2.write_digital(1) else: pin2.write_digital(0) #debug prints print ((sec, accel, current_peak, stepspermin, peaks[current_peak-1], peaks_sec[current_peak-1], valleys[current_valley-1], valleys_sec[current_valley-1], amplitude_avg, accel_avg))
def flipSwitch(switch): global switch1Pos, switch2Pos, switch3Pos, switch4Pos if switch == 1: if switch1Pos == 1: pin1.write_digital(1) sleep(500) pin1.write_digital(0) switch1Pos = 2 panelLEDs(0,(0,55,100)) flipSignalPoleLEDs(0, 2) else: pin0.write_digital(1) sleep(500) pin0.write_digital(0) switch1Pos = 1 panelLEDs(0,(55,100,0)) flipSignalPoleLEDs(0, 1) elif switch == 2: if switch2Pos == 1: pin3.write_digital(1) sleep(500) pin3.write_digital(0) switch2Pos = 2 panelLEDs(1,(0,55,100)) flipSignalPoleLEDs(2, 2) else: pin2.write_digital(1) sleep(500) pin2.write_digital(0) switch2Pos = 1 panelLEDs(1,(55,100,0)) flipSignalPoleLEDs(2, 1) elif switch == 3: if switch3Pos == 1: pin6.write_digital(1) sleep(500) pin6.write_digital(0) switch3Pos = 2 panelLEDs(2,(0,55,100)) flipSignalPoleLEDs(4, 2) else: pin4.write_digital(1) sleep(500) pin4.write_digital(0) switch3Pos = 1 panelLEDs(2,(55,100,0)) flipSignalPoleLEDs(4, 1) elif switch == 4: if switch4Pos == 1: pin9.write_digital(1) sleep(500) pin9.write_digital(0) switch4Pos = 2 panelLEDs(3,(0,55,100)) flipSignalPoleLEDs(6, 2) else: pin7.write_digital(1) sleep(500) pin7.write_digital(0) switch4Pos = 1 panelLEDs(3,(55,100,0)) flipSignalPoleLEDs(6, 1)