Advertisement
Astranome

VarioBMP180_Nano

Sep 3rd, 2020
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. #include <Wire.h>
  2. //#include <BMP085.h>
  3. #include <Adafruit_BMP085.h>
  4. #include <LiquidCrystal_I2C.h>
  5. uint8_t bukva1[8] = {
  6. B00100,
  7. B01110,
  8. B11111,
  9. B00100,
  10. B00100,
  11. B00100,
  12. B00100
  13. };
  14. uint8_t bukva2[8] = {
  15. B11100,
  16. B10100,
  17. B11100,
  18. B00000,
  19. B00000,
  20. B00000,
  21. B00000
  22. };
  23. LiquidCrystal_I2C lcd(0x27, 16, 2); // Для экрана 16х2 (двухстрочный)
  24.  
  25. //BMP085 dps = BMP085();
  26. Adafruit_BMP085 dps;
  27. long vario=0,vario2=0;
  28. long Pressure = 0;
  29. float Temperature = 0, Altitude = 0;
  30. const int n=20;
  31. const byte buzzPin=3;
  32. //int delta=0;
  33. //const byte ledPin = 13;
  34. unsigned long time1=0,time2=0;
  35. int ibuf;
  36. int t1=0,t2=0;
  37. unsigned long tim[20],al[20];
  38. long QFE=0;
  39. void setup(void) {
  40. // Serial.begin(115200);
  41. Wire.begin();
  42. delay(1000);
  43.  
  44. if (!dps.begin()) {
  45. Serial.println("Could not find a valid BMP085 sensor, check wiring!");
  46. while (1) {}
  47. }
  48.  
  49. lcd.init();
  50. lcd.backlight();
  51.  
  52. lcd.noCursor();
  53. lcd.createChar(0,bukva1);
  54. lcd.createChar(1,bukva2);
  55.  
  56. QFE=dps.readPressure(); // Set ongroung pressure and now Altitude=0
  57. }
  58.  
  59.  
  60. void loop() {
  61. int i;
  62. float dg;
  63.  
  64. if (((millis() - time1)/1000.0) >= 5.0) {
  65. // dps.calcTrueTemperature();
  66. Temperature = dps.readTemperature();
  67. time1 = millis();
  68. }
  69.  
  70. t1++;
  71. t2++;
  72. // t3++;
  73. // t4++;
  74. if (t1 >= 10) {t1=0;noTone(buzzPin);}
  75. if (t2 >= 6) {t2=0;noTone(buzzPin);}
  76.  
  77. //if (vario < 0) noTone(buzzPin);
  78. if (vario > -5 && vario < -2) tone(buzzPin, 350); //Sink :-(
  79. if (vario <= -5 ) tone(buzzPin, 250); // Falling ;-((
  80. //if (vario <= -5 ) tone(buzzPin, 300);
  81. if (vario < 5 && vario > 1 && t1 == 5) { tone(buzzPin, 1444); } //Climbing !!
  82. if (vario >= 5 && t2 ==3 ) { tone(buzzPin, 1888);} // Termic !!!!
  83.  
  84. Altitude = (dps.readAltitude(QFE)*100);
  85.  
  86. //Altitude+=10;
  87. ibuf++;
  88. if (ibuf > n-1) ibuf=0;
  89. al[ibuf]=Altitude;
  90. tim[ibuf]=millis(); //ibuf*delta;
  91. /*
  92. // test
  93. for (i=0;i<n;i++){
  94. al[i]=i;
  95. tim[i]=i;
  96. ibuf=0;
  97. }
  98. */
  99.  
  100. long xs,ys,xys,xxs;
  101.  
  102. xs=0;
  103. ys=0;
  104. xys=0;
  105. xxs=0;
  106.  
  107. for ( i=0;i < n;i++){
  108. xs+=tim[i]-tim[0];
  109. ys+=al[i]-al[0];
  110. xys+=(tim[i]-tim[0])*(al[i]-al[0]);
  111. xxs+=(tim[i]-tim[0])*(tim[i]-tim[0]);
  112. }
  113.  
  114. xs=xs;
  115. ys=ys;
  116. xys=xys;
  117. xxs=xxs;
  118.  
  119.  
  120. //float tmp=0.0;
  121. dg=(xs*xs/n - xxs);
  122.  
  123. //tmp= (xs*ys - xys*n)/dg*10;
  124. /*
  125. if (abs(dg) > 0.0001)
  126. vario = (xs*ys - xys*n)/dg*10;
  127. else
  128. vario =99.9;
  129. */
  130.  
  131. vario=(xs*ys/n-xys)/dg*100;//(long)tmp;
  132. //vario=10;
  133. vario2=(vario+0.9*vario2);
  134. if (((millis() - time2)/1000.0) >= 1.0) {
  135.  
  136.  
  137. lcd.clear();
  138.  
  139. lcd.setCursor(0,0);
  140. if (vario >= 0)
  141. lcd.write(0);
  142. else
  143. lcd.print("\-");
  144. lcd.setCursor(2,0);
  145. lcd.print( abs(vario*0.1),1 );
  146. lcd.setCursor(8,0);
  147.  
  148. if (vario2 >= 0)
  149. lcd.write(0);
  150. else
  151. lcd.print("\-");
  152. lcd.setCursor(10,0);
  153. lcd.print(abs(vario2)*0.01,1);
  154. lcd.print("m/s");
  155.  
  156. lcd.setCursor(0,1);
  157. lcd.print( "A=");
  158. lcd.print( int(Altitude*0.01));
  159. lcd.print("m");
  160. lcd.setCursor(8,1);
  161. lcd.print("T=");
  162.  
  163. lcd.print(Temperature); // *0.1,1);
  164. lcd.write(1);
  165. lcd.print("C");
  166. time2=millis();
  167. }
  168. /*
  169. Serial.print(" U Alt(cm): ");
  170. Serial.print(Altitude);
  171. //Serial.print(" P(hPa): ");
  172. //Serial.print(Pressure*0.01);
  173.  
  174. Serial.print(" V: ");
  175. Serial.print(vario*0.1);
  176. Serial.print(" V2: ");
  177. Serial.print(vario2*0.1);
  178. Serial.print(" T: ");
  179. Serial.println(Temperature*0.1);
  180. */
  181. delay(100);
  182. }
  183.  
  184.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement