@ -16,14 +16,15 @@ MCUFRIEND_kbv tft;
# include <math.h>
int DustSensePin = 1 3;
int DustSensePin = 31 ;
//globals for ppd42 dust sensor
//let's start with 100 readings. (copy and paste)
unsigned int airreading [ 100 ] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ;
//unsigned int airreading[100] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
unsigned long starttime = 0 ;
unsigned long sampletime_ms = 6 0000; //sample 60s == 60000 ;
unsigned long sampletime_ms = 1 0000; //sample 60s == 60000 ;
unsigned long lowpulseoccupancy = 0 ;
unsigned long duration = 0 ;
float ratio = 0 ;
float concentration = 0 ;
unsigned int x = 0 ;
@ -38,6 +39,9 @@ int brightnessread = 0;
int cat = 0 ;
int resultsread1 = 0 ;
int screenreadyforprint = 0 ;
double count = 0 ;
void setup ( void )
{
Serial . begin ( 9600 ) ;
@ -59,32 +63,49 @@ void loop(void)
if ( screenreadyforprint = = 0 ) {
tft . fillScreen ( BLACK ) ;
tft . WriteCmdData ( 0x51 , 0x0000 ) ;
tft . setTextColor ( 0 XFFFF ) ;
tft . setTextSize ( 2 ) ;
tft . setCursor ( 0 , 36 ) ;
tft . println ( " running sensor now " ) ;
tft . println ( " Starting Sensor " ) ;
screenreadyforprint = 1 ;
}
duration = pulseIn ( DustSensePin , LOW , 500000 ) ;
airreading [ x ] = pulseIn ( DustSensePin , LOW , 500000 ) ;
tft . println ( " Results are in: " ) ;
lowpulseoccupancy = lowpulseoccupancy + duration ;
//tft.println(airreading)
if ( ( millis ( ) - starttime ) > sampletime_ms ) //if the sample time == 30s
{
if ( ( millis ( ) - starttime ) > sampletime_ms ) //if the sample time == 30s
{
tft . fillScreen ( BLACK ) ;
tft . WriteCmdData ( 0x51 , 0x0000 ) ;
tft . setTextColor ( 0 XFFFF ) ;
tft . setTextSize ( 2 ) ;
tft . setCursor ( 0 , 36 ) ;
ratio = lowpulseoccupancy / ( sampletime_ms * 10.0 ) ; // Integer percentage 0=>100
concentration = 1.1 * powf ( ratio , 3 ) - 3.8 * powf ( ratio , 2 ) + 520 * ratio + 0.62 ; // using spec sheet curve
tft . print ( " Count: " ) ;
tft . println ( count ) ;
tft . println ( lowpulseoccupancy ) ;
//tft.print(",");
tft . println ( ratio ) ;
//Serial.print(",");
//tft.print(",");
tft . print ( " Concentration is: " ) ;
tft . println ( concentration ) ;
lowpulseoccupancy = 0 ;
starttime = millis ( ) ;
//tft.println("Results printed.");
count + + ;
}
}
void showmsgXY ( int x , int y , int sz , const GFXfont * f , const char * msg )