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

From FriendlyELEC WiKi
Jump to: navigation, search
(相关资料)
(示例源代码)
 
(4 intermediate revisions by 2 users not shown)
Line 23: Line 23:
 
|SIG  || 信号
 
|SIG  || 信号
 
|}
 
|}
==硬件连接==
+
== 示例程序:LED Blink ==
使用标准4 Pin连接线与NEO Hub连接。
+
  
参考下图连接模块:
+
=== 硬件连接 ===
[[File:BakeBit - Green LED_nanopi_NEO.jpg|frameless|600px|BakeBit - Green LED_nanopi_NEO]]
+
连接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 Matrix - NEO Hub.pdf])
+
*[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 相关资料