Browse Source

update the library and remove the port

xyu6 6 năm trước cách đây
mục cha
commit
2d2d591865
3 tập tin đã thay đổi với 0 bổ sung215 xóa
  1. 0 129
      AirQuality.cpp
  2. 0 42
      AirQuality.h
  3. 0 44
      examples/AirQuality_Sensor/AirQuality_Sensor.ino

+ 0 - 129
AirQuality.cpp

@@ -1,129 +0,0 @@
-/*
-  AirQuality library v1.0
-  2010 Copyright (c) Seeed Technology Inc.  All right reserved.
-
-  Original Author: Bruce.Qin
-
-  This library is free software; you can redistribute it and/or
-  modify it under the terms of the GNU Lesser General Public
-  License as published by the Free Software Foundation; either
-  version 2.1 of the License, or (at your option) any later version.
-
-  This library is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public
-  License along with this library; if not, write to the Free Software
-  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-*/
-#include"Arduino.h"
-#include"AirQuality.h"
-
-//Get the avg voltage in 5 minutes.
-
-void AirQuality::avgVoltage()
-{
-    if(i==150)//sum 5 minutes
-    {
-        vol_standard=temp/150;
-        temp=0;
-        Serial.print("Vol_standard in 5 minutes:");
-        Serial.println(vol_standard);
-        i=0;
-    }
-    else
-    {
-        temp+=first_vol;
-        i++;
-    }
-}
-void AirQuality::init(int pin)
-{
-    _pin=pin;
-    pinMode(_pin,INPUT);
-    unsigned char i=0;
-    Serial.println("sys_starting...");
-    delay(20000);//200000
-    init_voltage=analogRead(_pin);
-    Serial.println("The init voltage is ...");
-    Serial.println(init_voltage);
-    while(init_voltage)
-    {
-        if(init_voltage<798 && init_voltage>10)// the init voltage is ok
-        {
-            first_vol=analogRead(_pin);//initialize first value
-            last_vol=first_vol;
-            vol_standard=last_vol;
-            Serial.println("Sensor ready.");
-            error=false;;
-            break;
-        }
-        else if(init_voltage>798||init_voltage<=10)
-        {
-            i++;
-            delay(60000);//60000
-            Serial.println("waitting sensor init..");
-            init_voltage=analogRead(_pin);
-            if(i==5)
-            {
-                i=0;
-                error=true;
-                Serial.println("Sensor Error!");
-            }
-          }
-        else
-        break;
-    }
-    //init the timer
-    TCCR2A=0;//normal model
-    TCCR2B=0x07;//set clock as 1024*(1/16M)
-    TIMSK2=0x01;//enable overflow interrupt
-    Serial.println("Test begin...");
-    sei();
-}
-int AirQuality::slope(void)
-{
-    while(timer_index)
-    {
-        if(first_vol-last_vol>400||first_vol>700)
-        {
-            Serial.println("High pollution! Force signal active.");
-            timer_index=0;
-            avgVoltage();
-            return 0;
-        }
-        else if((first_vol-last_vol>400&&first_vol<700)||first_vol-vol_standard>150)
-        {
-            Serial.print("sensor_value:");
-            Serial.print(first_vol);
-            Serial.println("\t High pollution!");
-            timer_index=0;
-            avgVoltage();
-            return 1;
-
-        }
-        else if((first_vol-last_vol>200&&first_vol<700)||first_vol-vol_standard>50)
-        {
-            //Serial.println(first_vol-last_vol);
-            Serial.print("sensor_value:");
-            Serial.print(first_vol);
-            Serial.println("\t Low pollution!");
-            timer_index=0;
-            avgVoltage();
-            return 2;
-        }
-        else
-        {
-            avgVoltage();
-            Serial.print("sensor_value:");
-            Serial.print(first_vol);
-            Serial.println("\t Air fresh");
-            timer_index=0;
-            return 3;
-        }
-    }
-    return -1;
-}
-

+ 0 - 42
AirQuality.h

@@ -1,42 +0,0 @@
-/*
-  AirQuality library v1.0
-  2010 Copyright (c) Seeed Technology Inc.  All right reserved.
-
-  Original Author: Bruce.Qin
-
-  This library is free software; you can redistribute it and/or
-  modify it under the terms of the GNU Lesser General Public
-  License as published by the Free Software Foundation; either
-  version 2.1 of the License, or (at your option) any later version.
-
-  This library is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public
-  License along with this library; if not, write to the Free Software
-  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-*/
-#ifndef __AIRQUALITY_H__
-#define __AIRQUALITY_H__
-#include"Arduino.h"
-class AirQuality
-{
-public:
-    int i ;
-    long vol_standard;
-    int init_voltage;
-    int first_vol;
-    int last_vol;
-    long temp;
-    int counter;
-    boolean timer_index;
-    boolean error;
-    void init(int pin);
-    int slope(void);
-private:
-    int _pin;
-    void avgVoltage(void);
-};
-#endif

+ 0 - 44
examples/AirQuality_Sensor/AirQuality_Sensor.ino

@@ -1,44 +0,0 @@
-/*
-  AirQuality Demo V1.0.
-  connect to A1 to start testing. it will needs about 20s to start 
-* By: http://www.seeedstudio.com
-*/
-#include"AirQuality.h"
-#include"Arduino.h"
-AirQuality airqualitysensor;
-int current_quality =-1;
-void setup()
-{
-    Serial.begin(9600);
-    airqualitysensor.init(A0);
-}
-void loop()
-{
-    current_quality=airqualitysensor.slope();
-    if (current_quality >= 0)// if a valid data returned.
-    {
-        if (current_quality==0)
-            Serial.println("High pollution! Force signal active");
-        else if (current_quality==1)
-            Serial.println("High pollution!");
-        else if (current_quality==2)
-            Serial.println("Low pollution!");
-        else if (current_quality ==3)
-            Serial.println("Fresh air");
-    }
-}
-ISR(TIMER2_OVF_vect)
-{
-    if(airqualitysensor.counter==122)//set 2 seconds as a detected duty
-    {
-        airqualitysensor.last_vol=airqualitysensor.first_vol;
-        airqualitysensor.first_vol=analogRead(A0);
-        airqualitysensor.counter=0;
-        airqualitysensor.timer_index=1;
-        PORTB=PORTB^0x20;
-    }
-    else
-    {
-        airqualitysensor.counter++;
-    }
-}