def play(self): delay = 0 step = [5, 10, 15, 20, 25, 30, 35, 40, 45, 55, 60, 65, 70] button = Button() button.on_up = self.volumeUp button.on_down = self.volumeDown button.on_left = self.multiplyUp button.on_right = self.multiplyDown button.on_enter = self.togglePause button.on_backspace = self.backButton ir = InfraredSensor() ts = TouchSensor() servo = MediumMotor() while True: self.volume = self.getVolume() button.process() if self.pause == True: continue distance = int(math.fabs(ir.value())) position = int(math.fabs(servo.position)) for x in step: if distance <= x: hertz = int(x * 15) # print("Hertz - " + str(hertz)) break for x in step: if position <= x: duration = int(x * 5 * self.multiply) # print("Duration - " + str(duration)) break if ts.is_pressed: if delay == 200: delay = 0 else: if delay == 0: delay = 200 # play sound self.sound.tone([(hertz, duration, delay)])
#code for all the missions mentioned are up #-------------------------------------------------------------------------------------------------------------------------------------------- #This is where the movement happens. the function "ColorChecking" is a function to decide what to do based on color. #--------------- failsafe ------------- def failsafe(): sys.exit() #-------------------------------------- #this is when the code accually starts Sound_.play_tone( frequency=400, duration=0.5, volume=50 ) #there is a 15-20 second lag when we start a program so this tells us that master has alreafy started by beeping start = time.time( ) #this makes it so that when we call start it is equal to what ever far the robot is in the code (IE: 00:12 if it was 12 seconds in) btn.on_backspace = failsafe while True: #the code that is indented repetes forever untill we stop the program if (btn.down): #if the down button is pressed: break #leave the loop pass btn.wait_for_released( 'enter') #waits untill the enter(middle) button is pressed ColorChecking() #calls the function color checking see above # Beepity beep! Sound_.play_tone(frequency=400, duration=0.5, volume=50)
def down(state): print('Down button pressed' if state else 'Down button released') def enter(state): print('Enter button pressed' if state else 'Enter button released') def backspace(state): print('Backspace button pressed' if state else 'Backspace button released') btn.on_left = left btn.on_right = right btn.on_up = up btn.on_down = down btn.on_enter = enter btn.on_backspace = backspace # This loop checks buttons state continuously (every 0.01s). # If the new state differs from the old state then the appropriate # button event handlers are called. while True: btn.process() # Check for currently pressed buttons. sleep(0.01) # If running this script from VS Code, press the stop button to quit # if running from Brickman, long-press backspace button to quit