This shows you the differences between two versions of the page.
| tutorials:arduino:analogread [2014/02/27 22:33] aaron created | tutorials:arduino:analogread [2014/02/28 10:21] (current) sam | ||
|---|---|---|---|
| Line 9: | Line 9: | ||
| ===== Abstract ===== | ===== Abstract ===== | ||
| + | How to do this,please refer to [[http://docs.cubieboard.org/tutorials/arduino/controlling_led |light led]] and [[http://docs.cubieboard.org/tutorials/arduino/connecting|how to connect cubieboard and arduino]] | ||
| + | |||
| {{:tutorials:arduino:t1.jpg|400}} | {{:tutorials:arduino:t1.jpg|400}} | ||
| {{:tutorials:arduino:t2.jpg|400}} | {{:tutorials:arduino:t2.jpg|400}} | ||
| Line 15: | Line 17: | ||
| ==== Source Code ==== | ==== Source Code ==== | ||
| <code> | <code> | ||
| - | int potPin = 0; //定义模拟接口0 连接LM35 温度传感器 | + | int potPin = 0; | 
| void setup() | void setup() | ||
| { | { | ||
| - | Serial.begin(9600);//设置波特率 | + | Serial.begin(9600); | 
| } | } | ||
| void loop() | void loop() | ||
| { | { | ||
| - | int val;//定义变量 | + | int val; | 
| - | int dat;//定义变量 | + | int dat; | 
| - | val=analogRead(0);// 读取传感器的模拟值并赋值给val | + | val=analogRead(0); | 
| - | dat=(125*val)>>8;//温度计算公式 | + | dat=(125*val)>>8; | 
| - | Serial.print("Tep:");//原样输出显示Tep 字符串代表温度 | + | Serial.print("Tep:"); | 
| - | Serial.print(dat);//输出显示dat 的值 | + | Serial.print(dat); | 
| - | Serial.println("C");//原样输出显示C 字符串 | + | Serial.println("C"); | 
| - | delay(500);//延时0.5 秒 | + | delay(500); | 
| } | } | ||
| </code> | </code> | ||