Difference between revisions of "BakeBit - Green LED/zh"

From FriendlyELEC WiKi
Jump to: navigation, search
(Created page with "[BakeBit - Green LED|English] ==介绍== * MatBakeBit - Green LED是一个简单的发光二极管模块。3-Pin 2.54mm排针,V接电源,G接地,S信号通过一个三...")
 
(示例源代码)
 
(14 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[BakeBit - Green LED|English]
+
[[BakeBit - Green LED|English]]
 
+
 
==介绍==
 
==介绍==
* MatBakeBit - Green LED是一个简单的发光二极管模块。3-Pin 2.54mm排针,V接电源,G接地,S信号通过一个三极管放大控制LED的导通或关闭。您可以向S输出静态的高低电平信号,也可以输出变化的PWM信号,信号电平可以是3.3V或5V。当您向S输出高电平时LED以最大亮度发光,低电平就完全熄灭,可变占空比的PWM信号可以调节发光的亮度。
+
[[File:BakeBit - Green LED.jpg|thumb|Green LED]]
 +
*BakeBit - Green LED是一个发光二极管模块,模块使用了一个三极管控制发光二极管的导通或关闭,并在发光二极管上串接了一个电位器,通过调节电位器接入电路的阻值,调整流过发光二极管的电流,从而改变发光二极管的亮度。也可使用可变占空比的PWM信号软件调节二极管发光的亮度。
 +
 
 +
==特性==
 +
* 使用标准的2.0mm 4 Pin BakeBit接口
 +
* LED亮度可调节
 +
* 数字信号输入
 +
[[File:BakeBit Green LED PCB.png | frameless|300px|BakeBit - Green LED]]
 +
 
 +
* 引脚说明:
 +
{| class="wikitable"
 +
|-
 +
|名称 || 描述
 +
|-
 +
|GND  || 地
 +
|-
 +
|5V    || 电源5V
 +
|-
 +
|NC    || 空
 +
|-
 +
|SIG  || 信号
 +
|}
 +
== 示例程序:LED Blink ==
 +
 
 +
=== 硬件连接 ===
 +
连接LED到NanoHUB扩展板的D3接口:
 +
 
 +
::{| class="wikitable"
 +
|-
 +
|[[File:LED-1.jpg |frameless|300px]]    || [[File:LED-2.jpg |frameless|300px]]
 +
|-
 +
|}
 +
 
 +
=== 示例源代码 ===
 +
 
 +
<syntaxhighlight lang="python">
 +
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")
 +
</syntaxhighlight>
 +
 
 +
[https://github.com/friendlyarm/BakeBit/blob/master/Software/Python/bakebit_led_blink.py Github]
 +
 
 +
=== 运行示例 ===
 +
 +
假设你已经参考[http://wiki.friendlyarm.com/bakebit bakebit教程]安装了BakeBit源代码,<br />
 +
要运行示例程序,可以在开发板上进入 BakeBit/Software/Python目录,运行bakebit_led_blink.py:
 +
<syntaxhighlight lang="bash">
 +
cd ~/BakeBit/Software/Python
 +
sudo python bakebit_led_blink.py
 +
</syntaxhighlight>
 +
 
 +
=== 运行结果 ===
 +
 
 +
BakeBit LED持续闪烁,闪烁的时间简隔是1秒钟。
 +
 
 +
==相关资料==
 +
*[Schematic]([http://wiki.friendlyarm.com/wiki/images/2/2e/08-SCHEMATIC_LED.pdf BakeBit - Green LED.pdf])
 +
*[BakeBit Github项目](https://github.com/friendlyarm/BakeBit)
 +
*[BakeBit Starter Kit手册](http://wiki.friendlyarm.com/bakebit/bakebit_starter_kit_manual_cn.pdf)

Latest revision as of 10:45, 28 November 2016

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