BakeBit - Green LED/zh

From FriendlyELEC WiKi
Revision as of 10:45, 28 November 2016 by Tzs (Talk | contribs) (示例源代码)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

English

1 介绍

Green LED
  • BakeBit - Green LED是一个发光二极管模块,模块使用了一个三极管控制发光二极管的导通或关闭,并在发光二极管上串接了一个电位器,通过调节电位器接入电路的阻值,调整流过发光二极管的电流,从而改变发光二极管的亮度。也可使用可变占空比的PWM信号软件调节二极管发光的亮度。

2 特性

  • 使用标准的2.0mm 4 Pin BakeBit接口
  • LED亮度可调节
  • 数字信号输入

BakeBit - Green LED

  • 引脚说明:
名称 描述
GND
5V 电源5V
NC
SIG 信号

3 示例程序:LED Blink

3.1 硬件连接

连接LED到NanoHUB扩展板的D3接口:

LED-1.jpg LED-2.jpg

3.2 示例源代码

import time
from bakebit import *
 
# Connect the BakeBit LED to digital port D3
led = 3
 
pinMode(led,"OUTPUT")
time.sleep(1)
 
print ("This example will blink a BakeBit LED connected to the BakeBit on the port labeled D3.\nIf you're having trouble seeing the LED blink, be sure to check the LED connection and the port number.\nYou may also try reversing the direction of the LED on the sensor.")
print (" ")
print ("Connect the LED to the port labele D3!" )
 
while True:
    try:
        #Blink the LED
        digitalWrite(led,1)		# Send HIGH to switch on LED
        print ("LED ON!")
        time.sleep(1)
 
        digitalWrite(led,0)		# Send LOW to switch off LED
        print ("LED OFF!")
        time.sleep(1)
 
    except KeyboardInterrupt:	# Turn LED off before stopping
        digitalWrite(led,0)
        break
    except IOError:				# Print "Error" if communication error encountered
        print ("Error")

Github

3.3 运行示例

假设你已经参考bakebit教程安装了BakeBit源代码,
要运行示例程序,可以在开发板上进入 BakeBit/Software/Python目录,运行bakebit_led_blink.py:

cd ~/BakeBit/Software/Python
sudo python bakebit_led_blink.py

3.4 运行结果

BakeBit LED持续闪烁,闪烁的时间简隔是1秒钟。

4 相关资料