双色LED

一、关于双色 LED

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

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

我们用的,是共阴型。


双色LED_第1张图片
图片发自App

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

二、关于通道

双色LED_第2张图片

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)