极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8714|回复: 2

高中学校的一个小项目,麻烦大家指导下。

[复制链接]
发表于 2013-4-13 12:10:51 | 显示全部楼层 |阅读模式
大体是个测距离的,问题是现在输出老是闪,估计是因为测距部分用了一段时间吧。。。想问问高手有木有办法,改下程序。。。
硬件部分:
arduino mini
srf-04
共阳四位数码管
用了这里的库,Arduino入门教程--第二十四课--数码管显示器,使用电位器控制数字
http://www.geek-workshop.com/thread-3168-1-1.html


问题是显示出来闪啊闪的。求支援!!
程序:


  1. //Written by Dean Reading, 2012.  [email][email protected][/email]

  2. /*
  3. This example is a centi-second counter to demonstrate the
  4. use of my SevSeg library.
  5. */

  6. #include "SevSeg.h"
  7. int inputPin=15;  // 定义超声波信号接收接口   ECHO接4口
  8.        int outputPin=14; // 定义超声波信号发出接口  TRIG 接5口
  9.        int cm;
  10.         int m;
  11. //Create an instance of the object.


  12. //Create global variables
  13. SevSeg sevseg;


  14. void setup() {
  15.   //I am using a common anode display, with the digit pins connected
  16.   //from 2-5 and the segment pins connected from 6-13
  17.   sevseg.Begin(1,2,3,4,5,6,7,8,9,10,11,12,13);
  18. pinMode(inputPin, INPUT);
  19.          pinMode(outputPin, OUTPUT);
  20. }

  21. void loop() {
  22.   //Produce an output on the display


  23. digitalWrite(outputPin, LOW); // 使发出发出超声波信号接口低电平2μs
  24.          delayMicroseconds(2);
  25.          digitalWrite(outputPin, HIGH); // 使发出发出超声波信号接口高电平10μs,这里是至少10μs
  26.          delayMicroseconds(10);
  27.          digitalWrite(outputPin, LOW);    // 保持发出超声波信号接口低电平
  28.          cm = pulseIn(inputPin, HIGH) /58; //将回波时间换算成cm
  29.        cm = (int(cm * 100)) / 100; //保留两位小数
  30.      delay (100);
  31.        m=cm;
  32.      
  33.       
  34.         sevseg.PrintOutput();
  35.   //Check if 10ms has elapsed
  36. sevseg.NewNum(m,2);
  37.   

  38.   }





复制代码



就是这样,小生先谢谢了
回复

使用道具 举报

发表于 2013-4-13 15:37:20 | 显示全部楼层
闪啊闪是因为不断地在刷新数据
delay(100)后面改成这个试试

if(m!=cm)
{
m=cm;
sevseg.PrintOutput();
sevseg.NewNum(m,2);
}
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-4-14 17:16:04 | 显示全部楼层
qptimus 发表于 2013-4-13 15:37
闪啊闪是因为不断地在刷新数据
delay(100)后面改成这个试试

好多了,谢谢
回复 支持 反对

使用道具 举报

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

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-5-14 05:26 , Processed in 0.043754 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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