Close

Arduino Skyetch

A project log for Flashing Light Prize (6) Arduino 101 Break Up

Parting is Such Sweet Elation

Vije MillerVije Miller 08/01/2017 at 00:200 Comments
// Flashing Light Prize (6) Arduino 101 Break Up
// BMP180 Code by Sparkfun
// VijeMiller
#include <SFE_BMP180.h>
#include <Wire.h>
// BMP180
SFE_BMP180 pressure;
double base;
// States
int last = 0;
int up = 0;
int state = 0;
// TIP120
int light = 7;
void setup()
{
  Serial.begin(9600);
  pinMode(light, OUTPUT);
  digitalWrite(light, LOW);
  // BMP180 Working?
  if (pressure.begin())
    Serial.println("BMP180 init success");
  else  {
    Serial.println("BMP180 init fail (disconnected?)\n\n");
    while (1);
  }
  // Create Base Line
  base = getPressure();
  Serial.print("Base Line Pressure: ");
  Serial.print(base);
  Serial.println(" mb");
  delay(2000);
}
void loop()
{
  double a, P;
  // Get Pressure
  P = getPressure();
  // Different Between Base and New
  a = pressure.altitude(P, base);
  Serial.print(a * 3.28084, 1);
  Serial.println(" feet");
  // Higher by 0.5 Feet or More?
  if (a >= up) {
    if (state == 0) {
      digitalWrite(light, HIGH);
      state = 1;
    } else if (state == 1) {
      digitalWrite(light, LOW);
      state = 0;
    }
  }
  // Add 0.5 Feet
  // Store Last
  up = a + 0.1524;
  delay(500);
}
double getPressure()
{
  char status;
  double T, P, p0, a;
  status = pressure.startTemperature();
  if (status != 0)
  {
    delay(status);
    status = pressure.getTemperature(T);
    if (status != 0)
    {
      status = pressure.startPressure(3);
      if (status != 0)
      {
        delay(status);
        status = pressure.getPressure(P, T);
        if (status != 0)
        {
          return (P);
        }
      }
    }
  }
}

Discussions