if pos.top:
        print("up")
        robot.forward()
    elif pos.left:
        print("left")
        robot.left()
    elif pos.right:
        print("right")
        robot.right()
    elif pos.bottom:
        print("down")
        robot.backward()
    elif pos.middle:
        print("fire")
        #robot.stop()


def stop():
    robot.stop()


robot = Robot(left=(4, 14), right=(17, 18))
bd = BlueDot()
bd.border = True
bd.when_pressed = dpad
bd.when_move = dpad
bd.when_released = stop

#robot = Robot(left=(left=(4,14), right(17,18))
pause()
Exemple #2
0
from signal import pause

def change_dot(pos):
    if pos.top:
        if bd.color == "red":
            bd.color = GREEN
        else:
            bd.color = "#ff0000"
    elif pos.bottom:
        if bd.border:
            bd.border = False
        else:
            bd.border = True
    elif pos.left:
        if bd.visible:
            bd.visible = False
        else:
            bd.visible = True
    elif pos.right:
        if bd.square:
            bd.square = False
        else:
            bd.square = True

bd = BlueDot()
bd.color="pink"
bd.border = False
bd.square = True
bd.when_pressed = change_dot

pause()
Exemple #3
0
    socket.SOCK_DGRAM)  # UDP
sock.bind((UDP_IP, UDP_PORT))

BUTT_L = 18  # Left button pin
BUTT_R = 23  # Right button pin
DIR = 17  # Direction pin of A4988 driver
STEP = 27  # Step pin of A4988 driver
SLEEP = 22  # Sleep pin of A4988 driver
arr = [
    'b', 's'
]  # Array controls direction over UDP, "s" means stop but it seems that it doesn't matter anymore. Not quite sure though
leftState = False  # To keep the logical status of left button
rightState = False  # To keep the logical status of right button
timeState = False  # ? not suer waht for... some leftover
bd = BlueDot(cols=2, rows=2)  # Define a number of bluetooth buttons
bd.border = True  # Give bluetooth buttons some border
bd[0, 1].color = "green"  # Change a color of bluetooth button
bd[1, 1].color = "red"  # Change a color of bluetooth button

GPIO.setup(BUTT_L, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)  # Button L.
GPIO.setup(BUTT_R, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)  # Button P.
GPIO.setup(DIR, GPIO.OUT, initial=GPIO.LOW)  # Directon
GPIO.setup(STEP, GPIO.OUT, initial=GPIO.LOW)  # Step
GPIO.setup(SLEEP, GPIO.OUT, initial=GPIO.LOW)  # Sleep


def fun_udp():
    while True:
        global arr
        try:  # https://www.programmersought.com/article/708917122/
            sock.settimeout(