九鼎创展论坛
标题: arduino ibox项目实战6-AD转换实验 [打印本页]
作者: armeasy 时间: 2014-10-25 17:41
标题: arduino ibox项目实战6-AD转换实验
硬件平台:PC机一台,ibox卡片电脑一只,arduino扩展板一个
软件平台:WIN7操作系统,android4.0或android4.4系统
打开arduino的IDE开发工具,依次点击文件->示例->01.Basics->AnalogReadSerial,AnalogReadSerial的示例程序将会被打开,其源码如下:
- // the setup routine runs once when you press reset:
- void setup() {
- // initialize serial communication at 9600 bits per second:
- Serial.begin(9600);
- }
-
- // the loop routine runs over and over again forever:
- void loop() {
- // read the input on analog pin 0:
- int sensorValue = analogRead(A0);
- // print out the value you read:
- Serial.println(sensorValue);
- delay(1); // delay in between reads for stability
- }
复制代码 从程序清单可以看出,AD转换也非常的简单,在setup函数中设置串口的波特率,然后在loop函数中通过analogRead函数读取A0管脚上的电压,并最终在调试窗口上打印出来。运行效果如下:
欢迎光临 九鼎创展论坛 (http://bbs.9tripod.com/) |
Powered by Discuz! X3.2 |