在树莓派上用python通过串口控制继电器开关电路

import RPi.GPIO as GPIO
import time

PORT=4
GPIO.setmode(GPIO.BCM)
GPIO.setup(PORT, GPIO.OUT)

def blink(times, delay):
    while times>0:
        if 0==times%2:
            GPIO.output(PORT, GPIO.HIGH) #or output(PORT, GPIO.True)
        else:
            GPIO.output(PORT, GPIO.LOW)
        time.sleep(delay)
        times-=1
    return


if __name__ == '__main__':
    blink(20, 1)

你可能感兴趣的:(python)