极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11052|回复: 0

【iam学代码】模拟串口读取

[复制链接]
发表于 2015-3-17 17:56:18 | 显示全部楼层 |阅读模式
  1. /*
  2.   AnalogReadSerial
  3.   Reads an analog input on pin 0, prints the result to the serial monitor.
  4.   Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
  5. 模拟串口读取程序,读取A0接口的数据,然后在串口监视器上显示结果。把滑动变阻器的中间脚
  6. 接到A0脚上,其余的接口分别接地gnd和5v

  7. This example code is in the public domain. 公开的
  8. */

  9. // the setup routine runs once when you press reset:
  10. void setup() {
  11.   // initialize serial communication at 9600 bits per second:
  12.   Serial.begin(9600);
  13. }

  14. // the loop routine runs over and over again forever:
  15. void loop() {
  16.   // read the input on analog pin 0:
  17.   int sensorValue = analogRead(A0);
  18.   // print out the value you read:
  19.   Serial.println(sensorValue);
  20.   delay(1);        // delay in between reads for stability
  21. }
复制代码
回复

使用道具 举报

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

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-19 04:55 , Processed in 0.033109 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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