Back to Parent

#include <Arduino_LPS22HB.h>
#include <Adafruit_NeoPixel.h>
#define PIXEL_PIN D3
#define PIXEL_COUNT 30
#define PIXEL_TYPE NEO_GRB + NEO_KHZ800

Adafruit_NeoPixel strip = Adafruit_NeoPixel(30, D3, PIXEL_TYPE);

float old_temp = 0;

void setup() {
  Serial.begin(9600);
  //while (!Serial);

  if (!BARO.begin()) {
    Serial.println("Failed to initialize pressure sensor!");
    while (1);
  }

  pinMode(D2,INPUT_PULLDOWN);

  //LED strip code
    strip.begin();
    strip.show();
}

void loop() {
  // read the sensor value
  float pressure = BARO.readPressure();

  // print the sensor value
  Serial.print("Pressure = ");
  Serial.print(pressure);
  Serial.println(" kPa");

  float temperature = BARO.readTemperature();
  Serial.println();

  // wait 1 second to print again
  delay(1000);
  float temp_diff = temperature-old_temp;
  old_temp = temperature;

  int val = digitalRead(D2);
  Serial.print("the doorbell says ");
  Serial.print(val);
   //if doorbell says 1, it predicts the weather
   if(val == 1){
    Serial.print("temp diff ");
    Serial.print(temp_diff);
    if (temp_diff>=0.01 && temp_diff <10){
      Serial.println("warmer");
      int blinknum = random(50);
      strip.setBrightness(255);
      for (int j=0;j<blinknum;j++){
        for (int i=0; i<strip.numPixels();i++){
          strip.setPixelColor(i, random(255),random(255),random(255));
          strip.show();
        }
        delay(random(50));
        for (int i=0; i<strip.numPixels();i++){
          strip.clear();
          strip.show();
        }
        delay(10);
      }
    }
  else if (temp_diff<0.01 && temp_diff <10){
     Serial.println("colder");
     for (int i=0; i<strip.numPixels();i++){
          strip.setBrightness(30);
          strip.setPixelColor(i,0,0,255);
          strip.show();
          //strip.clear();
        }
for (int j = 30 ; j> 0 ; j--) {  
    for (int i = 0;i <strip.numPixels ();i ++) {  
      strip.setBrightness(j);
      strip.show();
    }
    delay(10); 
  }
    delay(10);
    }
   }
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0