YFROBOT创客社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2496|回复: 0
打印 上一主题 下一主题

玩转Arduino Esplora ---- 点亮RGB LED

[复制链接]

签到天数: 22 天

[LV.4]偶尔看看III

跳转到指定楼层
楼主
发表于 2013-12-8 14:53:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 原始人 于 2013-12-8 14:54 编辑

点亮RGB LED

上次的测试实验中我们已经测试了Esplora 是正常工作的,使用的程序为库中的 EsploraBlink 例程,它使用到的语法为:Esplora.writeRGB(R,G,B); 其中R、G、B值范围为0~255,代表设置R、G、B 3个颜色的亮度(0为熄灭,255为最大亮度);这次我们将EsploraBlink  程序中的语句稍加改动,来点亮板子上的 RGB LED,效果是相同的~

RGB LED位置:

下面我们来看下程序:

  1. /********************************************
  2. * Blink_Change
  3. * Change the EsploraBlink Example
  4. *********************************************/

  5. // include the Esplora library
  6. #include <Esplora.h>

  7. void setup() {
  8.   // nothing to setup
  9. }

  10. void loop() {

  11.   // write light level to the red LED
  12.   // 0 means the LED is off, 255 is full brightness
  13.   Esplora.writeRed(255);

  14.   // add a delay to keep the LED lit for
  15.   // 1000 milliseconds (1 second)
  16.   delay(1000);

  17.   // turn the red LED off, and the green LED on
  18.   Esplora.writeRed(0);
  19.   Esplora.writeGreen(255);

  20.   // add a delay
  21.   delay(1000);

  22.   // turn the green LED off, and the blue LED on
  23.   Esplora.writeGreen(0);
  24.   Esplora.writeBlue(255);

  25.   // add a delay  
  26.   delay(1000);

  27.   // turn all the LEDs on together
  28.   Esplora.writeRGB(255, 255, 255);

  29.   // add a delay  
  30.   delay(1000);

  31.   // turn the LEDs off
  32.   Esplora.writeRGB(0, 0, 0);

  33.   // add a delay  
  34.   delay(1000);
  35. }
复制代码

程序实现的效果为,点亮RGB LED,颜色顺序为:红、绿、蓝、白、熄灭~~ 用白纸遮挡住再看效果果然很好,不信可以试试哦!!
程序中使用到的语法为:

Esplora.writeRed (255);         点亮红灯

Esplora.writeBlue(255);         点亮蓝灯

Esplora.writeGreen (255);      点亮绿灯

上面的3条语句 和例程中使用到的 Esplora.writeRGB(255, 255, 255);  效果是一样的!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|联系我们|YFROBOT ( 苏ICP备20009901号-2  

GMT+8, 2024-5-8 03:42 , Processed in 0.121740 second(s), 26 queries .

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表