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

arduino ibox项目实战21-AnalogInput实验

[复制链接]
跳转到指定楼层
楼主
发表于 2014-10-28 13:39:09 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
硬件平台:PC机一台,ibox卡片电脑一只,arduino扩展板一个,电位器外设一个
软件平台:WIN7操作系统,android4.0android4.4系统
实验目标:通过电位器旋转改变模拟电压,控制LED灯的闪烁间隔。
打开arduino的IDE开发工具,依次点击文件->示例-> 03.Analog->AnalogInput,AnalogInput的示例程序将会被打开,其源码如下:
  1. int sensorPin = A0;    // select the input pin for the potentiometer
  2. int ledPin = LED1;      // select the pin for the LED
  3. int sensorValue = 0;  // variable to store the value coming from the sensor

  4. void setup() {
  5.   // declare the ledPin as an OUTPUT:
  6.   pinMode(ledPin, OUTPUT);
  7. }

  8. void loop() {
  9.   // read the value from the sensor:
  10.   sensorValue = analogRead(sensorPin);
  11.   // turn the ledPin on
  12.   digitalWrite(ledPin, HIGH);
  13.   // stop the program for <sensorValue> milliseconds:
  14.   delay(sensorValue);
  15.   // turn the ledPin off:
  16.   digitalWrite(ledPin, LOW);
  17.   // stop the program for for <sensorValue> milliseconds:
  18.   delay(sensorValue);
  19. }
复制代码
       将电位器的两端接5VGND,中间接A0,运行程序,通过调节电位器,观察LED灯闪烁的间隔是否会发生变化。

回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-20 04:46 , Processed in 0.019036 second(s), 19 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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