双色LED

作者: 启蒙时代 | 来源:发表于2019-11-05 22:21 被阅读0次

    一、关于双色 LED

    红绿双色LED,一般红色代表忙碌,绿色代表准备。

    双色LED,实际上是有两个LED灯,各两个脚,共用一个脚,就变成三个脚。如果共阳,称为共阳型,共阴,称为共阴型。

    我们用的,是共阴型。

    双色LED

    如图,引脚处的-代表GND,S代表高电平。

    二、关于通道

    GPIO number并不是通道,GPIO number所对应的1-40的引脚序号,才是通道。

    三、一个跑马灯实例

    import RPi.GPIO as GPIO

    import time

    pins = {'pin_R':11, 'pin_G':12}  # pins is a dict

    sleep_time =0.5

    GPIO.setmode(GPIO.BOARD)      # Numbers GPIOs by physical location

    for i in pins:

    GPIO.setup(pins[i], GPIO.OUT)  # Set pins' mode is output

    GPIO.output(pins[i], GPIO.LOW) # Set pins to low(0V) to off led

    print("i is ",i,pins[i])

    def loop():

    while True:

                GPIO.output(pins['pin_R'], GPIO.HIGH)  # Set pins to high(+3.3V) to on led

                print(pins['pin_R']," Red Led is On...")

                time.sleep(sleep_time)

                GPIO.output(pins['pin_R'], GPIO.LOW)

                print(pins['pin_R']," Red Led is off...")

                time.sleep(sleep_time)

                GPIO.output(pins['pin_G'], GPIO.HIGH)

                print(pins['pin_G']," Green Led is On...")

                time.sleep(sleep_time)

                GPIO.output(pins['pin_G'], GPIO.LOW)

                print(pins['pin_G']," Green Led is off...")

                time.sleep(sleep_time)

    def destroy():

    for i in pins:

    GPIO.output(pins[i], GPIO.LOW)    # Turn off all leds

    GPIO.cleanup()

    if __name__ == "__main__":

    try:

    loop()

    except KeyboardInterrupt:

    destroy()

    相关文章

      网友评论

          本文标题:双色LED

          本文链接:https://www.haomeiwen.com/subject/tffybctx.html