Advertisement
KRITSADA

IPST-SE Sensor Station with App inventor

Aug 14th, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.75 KB | None | 0 0
  1.     #include <ipst.h>
  2. #include "ipst.h"
  3. #include "ipst_gp2d120_lib.h"
  4.  
  5. float Humidity;
  6. float Temperature;
  7. float HIN;
  8. int TempAnalog;
  9. int ValueBluetooth;
  10. int force;
  11. int UV;
  12. int adcValue;
  13. int Gass;
  14.  
  15. void setup()
  16. {
  17.   setTextSize(2);
  18.   setTextColor(GLCD_YELLOW);
  19.   setTextColor(GLCD_SKY);
  20.   glcd(1, 1, "IPST-SE");
  21.   glcd(2, 1, "MicroBOX");
  22.   setTextSize(1);
  23.   setTextColor(GLCD_PINK);
  24.   glcd(7, 2, "Sensor Station");
  25.  
  26. }
  27. void loop()
  28. {
  29.  
  30.   if (uart1_available())
  31.     ValueBluetooth = uart1_getkey();
  32.  
  33.   if (ValueBluetooth == 1) {
  34.  
  35.     TempAnalog = analog(1);
  36.     if (TempAnalog < 340) {
  37.       Temperature = (-5.0 + (TempAnalog - 120.0)) / (240) * ( 15.0 + 5.0 ) + 3.5;
  38.       setFloatPrecision(2);
  39.       uart1("%f", Temperature);
  40.     }
  41.     else if (TempAnalog < 500)
  42.     {
  43.       Temperature = (15.0 + (TempAnalog - 340.0)) / (240) * (30 + 15.0) + 3.5;
  44.       setFloatPrecision(2);
  45.       uart1("%f", Temperature);
  46.     }
  47.     else if (TempAnalog < 660)
  48.     {
  49.       Temperature = (30.0 + (TempAnalog - 500.0)) / (160) * (50 + 30) + 3.5;
  50.       setFloatPrecision(2);
  51.       uart1("%f", Temperature);
  52.     }
  53.     else {
  54.       Temperature = (50.0 + (TempAnalog - 660.0)) / (130) * (75 + 50) + 3.5;
  55.       setFloatPrecision(2);
  56.       uart1("%f", Temperature);
  57.     }
  58.     delay(1000);
  59.    
  60.   }
  61.  
  62.   if (ValueBluetooth == 2)
  63.   {
  64.    
  65.     UV = analogRead(2);
  66.    
  67.     if (UV < 10)
  68.     {
  69.       uart1("%d", 0);
  70.     }
  71.     else if (UV >= 10 && UV < 46)
  72.     {
  73.       uart1("%d", 1);
  74.     }
  75.     else if (UV >= 46 && UV < 65)
  76.     {
  77.       uart1("%d", 2);
  78.     }
  79.     else if (UV >= 65 && UV < 83)
  80.     {
  81.       uart1("%d", 3);
  82.     }
  83.     else if (UV >= 83 && UV < 103)
  84.     {
  85.       uart1("%d", 4);
  86.     }
  87.     else if (UV >= 103 && UV < 124)
  88.     {
  89.       uart1("%d", 5);
  90.     }
  91.     else if (UV >= 124 && UV < 142)
  92.     {
  93.       uart1("%d", 6);
  94.     }
  95.     else if (UV >= 142 && UV < 162)
  96.     {
  97.       uart1("%d", 7);
  98.     }
  99.     else if (UV >= 162 && UV < 180)
  100.     {
  101.       uart1("%d", 8);
  102.     }
  103.     else if (UV >= 180 && UV < 200)
  104.     {
  105.       uart1("%d", 9);
  106.     }
  107.     else if (UV >= 200 && UV < 221)
  108.     {
  109.       uart1("%d", 10);
  110.     }
  111.     else if (UV >= 221 && UV < 240)
  112.     {
  113.       uart1("%d", 11);
  114.     }
  115.     delay(1000);
  116.   }
  117.  
  118.   if (ValueBluetooth == 3)
  119.   {
  120.     uart1("%d", getdist(A3));
  121.     delay(1000);
  122.   }
  123.  
  124.   if (ValueBluetooth == 4)
  125.   {
  126.     HIN = analog(4) / 204.6;
  127.     Humidity = (HIN - 0.958) / 0.0307;
  128.     setFloatPrecision(2);
  129.     uart1("%f", Humidity);
  130.     delay(1000);
  131.   }
  132.  
  133.   if (ValueBluetooth == 5)
  134.   {
  135.     Gass = analogRead(5); //Read Gas value from analog 5
  136.     delay(100);
  137.     if (Gass < 300)
  138.     {
  139.       out (15, 1);
  140.     }
  141.     else
  142.     {
  143.       out (15, 0);
  144.     }
  145.     uart1("%d", Gass);
  146.     delay(1000);
  147.   }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement