Beispiel #1
0
    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)])
Beispiel #2
0
medium_motor = MediumMotor()
btn = Button()


# Press left button to turn medium motor left (counterclockwise)
def left(state):
    if state:  # if state = True
        medium_motor.on(speed=-10)
    else:
        medium_motor.stop()


# Press right button to turn medium motor right (clockwise)
def right(state):
    if state:
        medium_motor.on(speed=10)
    else:
        medium_motor.stop()


btn.on_left = left
btn.on_right = right

while True:  # This loop checks buttons state continuously,
    # calls appropriate event handlers
    btn.process()  # Check for currently pressed buttons.
    # If the new state differs from the old state,
    # call the appropriate button event handlers.
    sleep(0.01)  # buttons state will be checked every 0.01 second
Beispiel #3
0
        try:
            missions[selectedProgram].run()
            if selectedProgram < numMissions - 1:
                selectedProgram = selectedProgram + 1
        except Exception as e:
            soundGenerator.beep()
            robot.debug("EXCEPTION")
            robot.debug(e)
            selectedProgram = selectedProgram + 1
        robot.afterMission()
        print(missionNames[selectedProgram])


# Register the buttonListener
buttonListener.on_left = left
buttonListener.on_right = right
buttonListener.on_enter = enter

soundGenerator.beep()

# Read the calibrated values and test if the Gyro is drifting
robot.init()
#testoPesto.run()

print(missionNames[selectedProgram])
# Our Main Loop
while True:
    # Check if any buttons are pressed, and call the corresponding event handler
    buttonListener.process()
    # Debounce; Make sure the user has time to release the button
    sleep(0.1)
Beispiel #4
0
def down(state):  # down 이벤트 함수
    if state:  #  아래 버튼 눌림
        lcd.text_pixels('Down button pressed', x=0, y=50, font='courB14')
        lcd.update()
        sleep(0.2)
    else:  # 아래 버튼 뗌
        lcd.text_pixels('Down button released', x=0, y=50, font='courB14')
        lcd.update()
        sleep(0.2)


def enter(state):  # enter 이벤트 함수
    if state:  #  엔터 버튼 눌림
        lcd.text_pixels('Enter button pressed', x=0, y=50, font='courB14')
        lcd.update()
        sleep(0.2)
    else:  #  엔터 버튼 뗌
        lcd.text_pixels('Enter button released', x=0, y=50, font='courB14')
        lcd.update()
        sleep(0.2)


btn.on_left = left  #왼쪽 버튼 이벤트 함수를 left 함수로 등록
btn.on_right = right  #오른쪽 버튼 이벤트 함수를 right 함수로 등록
btn.on_up = up  #위쪽 버튼 이벤트 함수를 up 함수로 등록
btn.on_down = down  #아래쪽 버튼 이벤트 함수를 down 함수로 등록
btn.on_enter = enter  #엔터 버튼 이벤트 함수를 enter 함수로 등록
while True:
    btn.process()  # 버튼 이벤트 상태를 감지 함
    sleep(0.01)
Beispiel #5
0
	# touch any part of the body
	if( cnt >= 3):
		indx=-3
		while indx > 0-cnt:
			tmpX=Sx[indx]
			tmpY=Sy[indx]
			if( tmpX==x and tmpY==y):
				return True
			indx -= 3

	return False

# subscribe the button events
btn.on_left = left
btn.on_right = right
btn.on_up = up
btn.on_down = down
createBuger()
display.clear()

# draw hanburger
display.draw.ellipse((hx,hy,hx+step,hy+step))

while True:
	# draw score on the screen
	display.draw.text((0,2), 'Score {0}'.format(length), fill='black')

	# process the button event
	btn.process()
Beispiel #6
0
    global currentProgram
    global program
    global run
    bt = button.buttons_pressed
    if "left" in bt or "right" in bt or "enter" in bt:
        if type(plus) == type(2):
            if plus > 0:
                program += 1
            else:
                program -= 1
        elif type(plus) == type(True):
            run = currentProgram
        currentProgram = (program % len(programs)) + 1


button.on_right = lambda x: c(1)
button.on_left = lambda x: c(-1)
button.on_enter = lambda x: c(True)

# Program running handling
currentProgram = 1
pastProgram = currentProgram

console.reset_console()
console.text_at("Selected: " + str(currentProgram))

while True:
    button.process()
    if currentProgram != pastProgram:
        clearColumn(1)
        console.text_at("Selected: " + str(currentProgram))