|
|
一个PM2.5检测仪,如果不接IIC接口的TM1650四位LED数码管,从串口观察数据一切正常,但是一接入数据就乱了忽大忽小还经常出负值,关键是程序完全没变动。求大家指点一下,是程序哪错了?
- #include <Wire.h>
- #include <TM1650.h>
- TM1650 d;
- char *line=new char[3];
- int dustPin=A0;
- int dustVal=0;
- int ledPower=2;
- int delayTime=280;
- int delayTime2=40;
- float offTime=9680;
- void setup(){
- Wire.begin();
- Serial.begin(9600);
- pinMode(ledPower,OUTPUT);
- //pinMode(4, OUTPUT);
- }
- void loop(){
- // ledPower is any digital pin on the arduino connected to Pin 3 on the sensor
- digitalWrite(ledPower,LOW); // power on the LED
- delayMicroseconds(delayTime);
- dustVal=analogRead(dustPin); // read the dust value via pin 5 on the sensor
- delayMicroseconds(delayTime2);
- digitalWrite(ledPower,HIGH); // turn the LED off
- delayMicroseconds(offTime);
- delay(3000);
- Serial.println(dustVal);
- float dV3=dustVal;
- dV3=((dV3*5/1024)*0.172-0.0999)*1000;
- Serial.println("PM2.5:");
- d.displayOn();
- int data=dV3;
- sprintf(line, "%d", data );
- d.displayString(line);//实际的颗粒数
- Serial.println(dV3);
- Serial.println("data");
- Serial.println(data);
- Serial.println("line");
- Serial.println(line);
- }
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|