九鼎创展论坛

标题: arduino ibox项目实战21-AnalogInput实验 [打印本页]

作者: armeasy    时间: 2014-10-28 13:39
标题: arduino ibox项目实战21-AnalogInput实验
硬件平台: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灯闪烁的间隔是否会发生变化。






欢迎光临 九鼎创展论坛 (http://bbs.9tripod.com/) Powered by Discuz! X3.2