Quantcast
Viewing all articles
Browse latest Browse all 5391

Python • Re: Motor Control RASP 3B

hello... thanks for your answers by the way...
i changed python code already....

import RPi.GPIO as GPIO
import time

motor_pin = 18
boton_pin = 17

GPIO.setmode(GPIO.BCM)
GPIO.setup(motor_pin, GPIO.OUT)
GPIO.setup(boton_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

def encender_motor():
GPIO.output(motor_pin, GPIO.HIGH)
print("Motor encendido")

def apagar_motor():
GPIO.output(motor_pin, GPIO.LOW)
print("Motor apagado")

try:
while True:
GPIO.wait_for_edge(boton_pin, GPIO.FALLING)
entrada = input("Introduce una letra: ")
if entrada == 'r':
encender_motor()
GPIO.wait_for_edge(boton_pin, GPIO.RISING)
apagar_motor()
else:
print("Carácter no reconocido, intenta de nuevo.")
time.sleep(0.5)

except KeyboardInterrupt:
GPIO.cleanup()

=======================
after that, the error that i get is:
RuntimeError: Error waiting for edge

Statistics: Posted by Gantonio — Thu May 30, 2024 5:27 am



Viewing all articles
Browse latest Browse all 5391

Trending Articles