|
大体是个测距离的,问题是现在输出老是闪,估计是因为测距部分用了一段时间吧。。。想问问高手有木有办法,改下程序。。。
硬件部分:
arduino mini
srf-04
共阳四位数码管
用了这里的库,Arduino入门教程--第二十四课--数码管显示器,使用电位器控制数字
http://www.geek-workshop.com/thread-3168-1-1.html
问题是显示出来闪啊闪的。求支援!!
程序:
- //Written by Dean Reading, 2012. [email][email protected][/email]
- /*
- This example is a centi-second counter to demonstrate the
- use of my SevSeg library.
- */
- #include "SevSeg.h"
- int inputPin=15; // 定义超声波信号接收接口 ECHO接4口
- int outputPin=14; // 定义超声波信号发出接口 TRIG 接5口
- int cm;
- int m;
- //Create an instance of the object.
- //Create global variables
- SevSeg sevseg;
- void setup() {
- //I am using a common anode display, with the digit pins connected
- //from 2-5 and the segment pins connected from 6-13
- sevseg.Begin(1,2,3,4,5,6,7,8,9,10,11,12,13);
- pinMode(inputPin, INPUT);
- pinMode(outputPin, OUTPUT);
- }
- void loop() {
- //Produce an output on the display
-
- digitalWrite(outputPin, LOW); // 使发出发出超声波信号接口低电平2μs
- delayMicroseconds(2);
- digitalWrite(outputPin, HIGH); // 使发出发出超声波信号接口高电平10μs,这里是至少10μs
- delayMicroseconds(10);
- digitalWrite(outputPin, LOW); // 保持发出超声波信号接口低电平
- cm = pulseIn(inputPin, HIGH) /58; //将回波时间换算成cm
- cm = (int(cm * 100)) / 100; //保留两位小数
- delay (100);
- m=cm;
-
-
- sevseg.PrintOutput();
- //Check if 10ms has elapsed
- sevseg.NewNum(m,2);
-
- }
复制代码
就是这样,小生先谢谢了
|
|