Search code examples
pythonraspberry-pigpioraspberry-pi4

Raspberry Pi send 3.3v signal for 100ms


I am working on a Image Classifier which will work on a RPi and after classifying the image from a camera it will need to send two 3.3v signals form two different GPIO pins for 100ms (based on the image classification).

How can I do this?

Thanks for your help and feel free to ask me more if needed.


Solution

  • import RPi.GPIO as GPIO
    from time import sleep
    
    led_pin = 17
    
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(led_pin, GPIO.OUT)
    
    for _ in range(2):
        GPIO.output(led_pin, True)
        sleep(0.1)
        GPIO.output(led_pin, False)
        sleep(0.1)
    

    Or setup more easily

    from gpiozero import LED
    from time import sleep
    
    led = LED(17)
    
    for _ in range(2):
        led.on()
        sleep(0.1)
        led.off()
        sleep(0.1)