Пример #1
0
from gpiozero import Motor
import pygame
from pygame.locals import *

motor = Motor(2, 3)
motor.enable()

done = false
while not done:
    event = pygame.event.poll()
    if event.type == pygame.QUIT:
        done = true
    elif event.type == pygame.KEYUP:
        if event.key == pygame.K_w:
            motor.value = 0
        if event.key == pygame.K_s:
            motor.value = 0
    else:
        keys = pygame.key.get_pressed()
        if keys[pygame.K_w]:
            motor.forward()
        elif keys[pygame.K_s]:
            motor.backwards()
        elif keys[pygame.K_SPACE]:
            motor.stop()
Пример #2
0
                leftSide = leftSide - 100
                
            elif (event.key == pygame.K_d or event.key == pygame.K_RIGHT):
                rightSide = rightSide - 50

            elif (event.key == pygame.K_w or event.key == pygame.K_UP):
                rightSide = rightSide + 100
                leftSide = leftSide + 100
            
            

            if (leftSide == -50):
                #Turn Left
                motor1.forwards()
                motor2.forwards()
                motor3.backwards()
                motor4.backwards()
                
            elif (rightSide == -50):
                #Turn Right
                motor3.forwards()
                motor4.forwards()
                motor1.backwards()
                motor2.backwards()
               
                
            elif (rightSide == 100 and leftSide == 50 ):
                #Turn half left
               
                motor3.stop()
                motor4.stop()