Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
1.5 kB
1
Indexable
Never
from RpiMotorLib import RpiMotorLib
import RPi.GPIO as GPIO
import time

#define buttons layout
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
#define GPIO pins horitzontal
motor_h_GPIO_pins = (14, 15, 18)
motor_h_direction= 20
motor_h_step = 21
motor_h_distance = 500 # Default move 1mm => 80 steps per mm
#define GPIO pins vertical
motor_v_GPIO_pins = (5, 6, 13)
motor_v_direction= 26
motor_v_step = 19
motor_v_distance = 500 # Default move 1mm => 80 steps per mm


motor_v = RpiMotorLib.A4988Nema(
    motor_v_direction,
    motor_v_step,
    motor_v_GPIO_pins,
    "A4988"
)

motor_h = RpiMotorLib.A4988Nema(
    motor_h_direction,
    motor_h_step,
    motor_h_GPIO_pins,
    "A4988"
)

while True:
    if GPIO.input(2) == GPIO.LOW:
        print('LEFT')
        print('button 2')
        motor_h.motor_go(False, "1/16", motor_h_distance)
    if GPIO.input(27) == GPIO.LOW:
        print('UP')
        print('button 27')
        motor_v.motor_go(False, "1/16", motor_v_distance)
    if GPIO.input(4) == GPIO.LOW:
        print('DOWN')
        print('button 4')
        motor_v.motor_go(True, "1/16", motor_v_distance)
    if GPIO.input(17) == GPIO.LOW:
        print('RIGHT')
        print('button 17')
        motor_h.motor_go(True, "1/16", motor_h_distance)
    else:
        print("Nothing!")
    time.sleep(.5)