BakeBit - Green LED

From FriendlyELEC WiKi
Revision as of 14:25, 14 December 2016 by Yftan (Talk | contribs) (介绍)

Jump to: navigation, search

查看中文

1 Introduction

Green LED
  • The BakeBit - Green LED is an LED module. This module has a a triode which is used to turn the LED on or off. There is a potentiometer in series connection with the LED. When users adjust the potentiometer the LED's luminance will be changed accordingly.Or you input PWM signals to control the the LED's luminance.

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 相关资料