// Listing 11.5. Mechanizm tłumaczący PUMT — kod C++ Arduino komunikującego się za pomocą interfejsu Bluetooth oraz przeprowadzającego analizę pH i pola magnetycznego

//CZĘŚCI: SEKCJA 1.
//Sekcja czujników
    2    #include <SoftwareSerial.h>   //Programowy port szeregowy
    3    #define RxD 7
    4    #define TxD 6
    5    
    6    #define DEBUG_ENABLED  1
    7     
    8    SoftwareSerial blueToothSerial(RxD,TxD);
    9    // Ustawienie czujnika Vernier: 0,3
   10    // Mierzone wartości są wyrażane w gausach
   11    
   12    class analog_sensor{
   13       protected:
   14         int Interval;
   15         float Intercept;
   16         float Slope;
   17         float Reading;
   18         float Data;  
   19         float Voltage;
   20       public:
   21          analog_sensor(float I, float S);
   22          float readData(void);
   23          float voltage(void);
   24          float sensorReading(void);
   25    
   26    };   
   27    analog_sensor::analog_sensor(float I,float S)
   28    {
   29       Interval = 3000; // w ms
   30       Intercept = I; // w mT
   31       Slope = S; 
   32       Reading = 0;
   33       Data = 0;
   34    } 
   35    float analog_sensor::readData(void)
   36    {
   37       Data = analogRead(A0);
   38    }
   39    float  analog_sensor::voltage(void)
   40    {
   41       Voltage = readData() / 1023 * 5.0;
   42    }
   43     
   44    float analog_sensor::sensorReading(void)
   45    {
   46       voltage();
   47       Reading = Intercept + Voltage * Slope;
   48       delay(Interval);
   49       return(Reading);
   50    }     
   51
 
