Difference between revisions of "Matrix - LED/zh"
From FriendlyELEC WiKi
(→特性) |
|||
Line 13: | Line 13: | ||
* PCB尺寸(mm):8x24 | * PCB尺寸(mm):8x24 | ||
[[File:led02pcb.png | frameless|400px|LED-01.PCB]] | [[File:led02pcb.png | frameless|400px|LED-01.PCB]] | ||
+ | |||
+ | ==使用方法== | ||
+ | ===连接=== | ||
+ | *连接到NanoPi | ||
+ | ::将配件S针脚连接到GPIO PIN1, V接5V,G接地 | ||
+ | [[File:LED&NanoPi.png|frameless|600px|NanoPi+LED]] | ||
+ | |||
+ | ===Linux下的C示例=== | ||
+ | <syntaxhighlight lang="c"> | ||
+ | #include <stdio.h> | ||
+ | #include <unistd.h> | ||
+ | #include "libfahw.h" | ||
+ | |||
+ | #define LED_BLINK_TIMES 10 | ||
+ | |||
+ | int main(int argc, char ** argv) | ||
+ | { | ||
+ | int ledPin = nanopi_GPIO_GPF1; | ||
+ | int i = 0; | ||
+ | int ret = -1; | ||
+ | |||
+ | if ((ret = exportGPIOPin(ledPin)) == -1) { | ||
+ | printf("exportGPIOPin(%d) failed\n", ledPin); | ||
+ | } | ||
+ | if ((ret = setGPIODirection(ledPin, GPIO_OUT)) == -1) { | ||
+ | printf("setGPIODirection(%d) failed\n", ledPin); | ||
+ | } | ||
+ | |||
+ | for (i = 0; i < LED_BLINK_TIMES; i++) { | ||
+ | if (i % 2) { | ||
+ | ret = setGPIOValue(ledPin, GPIO_HIGH); | ||
+ | } else { | ||
+ | ret = setGPIOValue(ledPin, GPIO_LOW); | ||
+ | } | ||
+ | if (ret == -1) { | ||
+ | printf("setGPIOValue(%d) failed\n", ledPin); | ||
+ | } | ||
+ | printf("LED blinking times %d\n", i); | ||
+ | sleep(1); | ||
+ | } | ||
+ | unexportGPIOPin(ledPin); | ||
+ | return 0; | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ===编译并运行示例=== | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | git clone http://github.com/friendlyarm/fa-hardware.git | ||
+ | cd fa-hardware | ||
+ | cd demo | ||
+ | cd button | ||
+ | make | ||
+ | </syntaxhighlight> | ||
+ | 将编译生成的button通过ftp上传到开发板上运行即可测试。 | ||
+ | |||
+ | ==相关资料== |
Revision as of 06:14, 25 August 2015
Contents
1 介绍
一个直径为5mm的LED,3-Pin 2.54mm排针,V接电源,G接地,S信号通过一个三极管放大控制LED的导通或关闭。您可以向S输出静态的高低电平信号,也可以输出变化的PWM信号,信号电平可以是3.3V或5V。当您向S输出高电平时LED以最大亮度发光,低电平就完全熄灭,可变占空比的PWM信号可以调节发光的亮度。我们提供红、绿、蓝三种颜色的配件供您购买。
2 特性
- GPIO或PWM控制,3.3/5V电平,亮度通过PWM可调
- 体积小巧, 带固定孔,方便嵌入到外壳
- 2.54mm排针接口
- PCB尺寸(mm):8x24
3 使用方法
3.1 连接
- 连接到NanoPi
::将配件S针脚连接到GPIO PIN1, V接5V,G接地
3.2 Linux下的C示例
#include <stdio.h> #include <unistd.h> #include "libfahw.h" #define LED_BLINK_TIMES 10 int main(int argc, char ** argv) { int ledPin = nanopi_GPIO_GPF1; int i = 0; int ret = -1; if ((ret = exportGPIOPin(ledPin)) == -1) { printf("exportGPIOPin(%d) failed\n", ledPin); } if ((ret = setGPIODirection(ledPin, GPIO_OUT)) == -1) { printf("setGPIODirection(%d) failed\n", ledPin); } for (i = 0; i < LED_BLINK_TIMES; i++) { if (i % 2) { ret = setGPIOValue(ledPin, GPIO_HIGH); } else { ret = setGPIOValue(ledPin, GPIO_LOW); } if (ret == -1) { printf("setGPIOValue(%d) failed\n", ledPin); } printf("LED blinking times %d\n", i); sleep(1); } unexportGPIOPin(ledPin); return 0; }
3.3 编译并运行示例
git clone http://github.com/friendlyarm/fa-hardware.git cd fa-hardware cd demo cd button make
将编译生成的button通过ftp上传到开发板上运行即可测试。