九鼎创展论坛中文版English
登录 | 立即注册 设为首页收藏本站 切换到宽版
查看: 5836|回复: 0
打印 上一主题 下一主题

arduino ibox项目实战24-Fading实验

[复制链接]
跳转到指定楼层
楼主
发表于 2014-10-28 14:15:46 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
硬件平台:PC机一台,ibox卡片电脑一只,arduino扩展板一个,电位器一个,LED灯一个
软件平台:WIN7操作系统,android4.0android4.4系统
实验目标:通过PWM实现LED灯的渐亮渐灭效果。
打开arduino的IDE开发工具,依次点击文件->示例-> 03.Analog->Fading,Fading的示例程序将会被打开,其源码如下:
  1. int ledPin = PWM0;    // LED connected to digital pin PWM0

  2. void setup() {
  3.   // nothing happens in setup
  4. }

  5. void loop() {
  6.   // fade in from min to max in increments of 5 points:
  7.   for (int fadeValue = 0 ; fadeValue <= 4095; fadeValue += 45) {
  8.     // sets the value (range from 0 to 4095):
  9.     analogWrite(ledPin, fadeValue);
  10.     // wait for 30 milliseconds to see the dimming effect
  11.     delay(30);
  12.   }

  13.   // fade out from max to min in increments of 5 points:
  14.   for (int fadeValue = 4095 ; fadeValue >= 0; fadeValue -= 45) {
  15.     // sets the value (range from 4095 to 0):
  16.     analogWrite(ledPin, fadeValue);
  17.     // wait for 30 milliseconds to see the dimming effect
  18.     delay(30);
  19.   }
  20. }
复制代码
       LED的正极连5V电源,负极接PWM0,运行程序,结合程序观看LED灯的效果,同时修改程序中参数反复实验,观察LED灯的状态。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|深圳市九鼎创展科技官方论坛 ( 粤ICP备11028681号-2  

GMT+8, 2024-9-28 12:20 , Processed in 0.019622 second(s), 19 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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