Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /////////////////////////
  2. // Arduino Altimeter BMP085
  3. // Designed by naldin
  4. // naldin.net (at) gmail
  5. // 01/13/2014
  6. // v1.00
  7. /////////////////////////
  8.  
  9. #include <Wire.h>
  10. #include <Adafruit_BMP085.h>
  11. #include <EEPROM.h>
  12.  
  13. //Variables
  14. int val_0 = 0;
  15. int val = 0;
  16. int val1 = 0;
  17. int cen1 = 0;
  18. int dec1 = 0;
  19. int uni1 = 0;
  20. int led = 13;
  21. int switch1 = 7;
  22. int pot = A0; //for test
  23.  
  24. Adafruit_BMP085 bmp;
  25.  
  26. void setup() {                
  27.   bmp.begin();
  28.   Serial.begin(9600);
  29.   pinMode(led, OUTPUT);
  30.   pinMode(switch1, INPUT);
  31.   val_0 = bmp.readAltitude();
  32. }
  33.  
  34. void loop() {
  35.   if (digitalRead(switch1) == HIGH){
  36.     currentalt();
  37.   }
  38.   showread();
  39. }
  40.  
  41.  
  42. //show values from eeprom
  43. void showread() {
  44.   while(digitalRead(switch1) == LOW){
  45.     delay(2000);
  46.     blink1(3,100,50);
  47.     delay(2000);
  48.  
  49.     delay(1000);
  50.     blink1(EEPROM.read(0),300,200);
  51.  
  52.     delay(1000);
  53.     blink1(EEPROM.read(1),300,200);
  54.  
  55.     delay(1000);
  56.     blink1(EEPROM.read(2),300,200);
  57.   }
  58.  
  59.   //going to getvalue function
  60.   Serial.println("Exited showread");
  61.   blink1(15,100,50);
  62.   delay(2000);
  63.   getvalue();
  64. }
  65.  
  66.  
  67. //getting and processing values
  68. void getvalue(){
  69.   while(digitalRead(switch1) == LOW){
  70. //    val = analogRead(pot); //for test
  71.     val = bmp.readAltitude() - val_0;
  72.     Serial.println(val);
  73.     delay(100);
  74.     digitalWrite(led, HIGH);
  75.  
  76.     if (val > val1){
  77.       val1 = val;
  78.     }
  79.   }
  80.  
  81.   //extracting and burning values to eeprom
  82.   cen1 = val1/100;
  83.   dec1 = (val1 - (cen1*100))/10;
  84.   uni1 = (val1 - (cen1*100) - (dec1*10));
  85.  
  86.   EEPROM.write(0,cen1);
  87.   EEPROM.write(1,dec1);
  88.   EEPROM.write(2,uni1);
  89.  
  90.   //going to showread function
  91.   Serial.println("Exited getvalue");
  92.   blink1(15,100,50);
  93.   digitalWrite(led, LOW);
  94.   delay(2000);
  95. //  showread();
  96. }
  97.  
  98.  
  99.  
  100. // show current altitude
  101. void currentalt(){
  102.   int alt1 = val_0;
  103.   blink1(15,100,50);
  104.   delay(2000);
  105.   while(digitalRead(switch1) == LOW){
  106.     Serial.print("Altitude = ");
  107.     Serial.print(alt1);
  108.     Serial.println(" meters");    
  109.     cen1 = alt1/100;
  110.     dec1 = (alt1 - (cen1*100))/10;
  111.     uni1 = (alt1 - (cen1*100) - (dec1*10));
  112.  
  113.     delay(2000);
  114.     blink1(3,100,50);
  115.     delay(2000);
  116.  
  117.     delay(1000);
  118.     blink1(cen1,300,200);
  119.  
  120.     delay(1000);
  121.     blink1(dec1,300,200);
  122.  
  123.     delay(1000);
  124.     blink1(uni1,300,200);
  125.  
  126.   }
  127.   blink1(15,100,50);
  128.   delay(2000);  
  129. }
  130.  
  131.  
  132.  
  133. //blink function
  134. void blink1(int j, int bl, int sp){
  135.   int i =0;
  136.   for(i = 0 ; i < j; i ++) {
  137.     digitalWrite(led, HIGH);
  138.     delay(bl);
  139.     digitalWrite(led, LOW);
  140.     delay(sp);
  141.   }
  142. }