test_stand.py

mail@pastecode.io avatar
unknown
python
a month ago
1.6 kB
1
Indexable
Never
# Import the RPi.GPIO library for GPIO control
import RPi.GPIO as GPIO 

# Import the sleep function for introducing delays
from time import sleep

# Set the pin numbering mode to use physical pin numbers on the Raspberry Pi
GPIO.setmode(GPIO.BCM)

# Set up GPIO pins 4, 17, and 18 as output pins for controlling the motor
GPIO.setup(4, GPIO.OUT)
GPIO.setup(17, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)

#Set up GPIO pin 13 as output pins for controlling the servo motor
GPIO.setup(13, GPIO.OUT)

btn1 = 26
btn2 = 16
#Set up GPIO pins 26 and 19 as input pins for getting input from buttons
GPIO.setup(btn1, GPIO.IN)
GPIO.setup(btn2, GPIO.IN)



# Create a PWM (Pulse Width Modulation) object on pin 18 with a frequency of 100 Hz
p = GPIO.PWM(18, 100)
p2 = GPIO.PWM(13, 50)

p.start(0)
p2.start(0)

btn1_stat = 1
btn2_stat = 2
GPIO.output(18, False)
def check_btn():
    global btn1_stat
    global btn2_stat
    if GPIO.input(btn1) == 0:
        if btn1_stat == 0:
            btn1_stat = 1
        else:
            btn1_stat = 0
            
        
    if GPIO.input(btn2) == 0:
        if btn2_stat == 0:
            btn2_stat = 1
        else:
            btn2_stat = 0
   
        
    sleep(0.5)
        
    
    
while True:
    check_btn()
    while btn1_stat == 0:
        GPIO.output(18, True)
        GPIO.output(4, True)
        GPIO.output(17, False)
        p.start(25)
        check_btn()
    while btn2_stat == 0:
        
        p2.ChangeDutyCycle(2.5)
        check_btn()
        p2.ChangeDutyCycle(5)
        check_btn()
    p.start(0)
    GPIO.output(18, False)
        
        
    
Leave a Comment