Back to Parent

#include <Servo.h>

#include <Adafruit_NeoPixel.h>

//provides information about the LED strip
#define PIXEL_PIN D11
#define PIXEL_COUNT 30
#define PIXEL_TYPE NEO_GRB + NEO_KHZ800


Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

//sets all of the colors used
uint32_t red = strip.Color(255, 0, 0);
uint32_t blue = strip.Color(0, 0, 255);
uint32_t white = strip.Color(255, 255, 255);
uint32_t green = strip.Color(0, 255, 0);
uint32_t orange = strip.Color(255, 165, 0);

int condition = 0;

Servo servo;
int servoPin(D10);

bool updatePosition = true;

#include <Arduino_LPS22HB.h>

//sets the current temperature as a global variable to be compared later on, set as 0 for now
float temperature = 32;
float newTemperature = 0;

void setup() {
  strip.begin();
  strip.show();//intialize all pixels to off
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(LEDR, OUTPUT);
  pinMode(LEDB, OUTPUT);
  pinMode(LEDG, OUTPUT);
  //above sets up the led to be the output
  while (!Serial);
  digitalWrite(LEDR, HIGH);
  digitalWrite(LEDB, HIGH);
  digitalWrite(LEDG, HIGH);

  servo.attach(D10);

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

}
void loop() {
  //set the servo to the blocked/default position
  newTemperature = BARO.readTemperature();
  // read the sensor value
  float pressure = BARO.readPressure();
  // if condition is already met, just keep LEDs as green
  if (condition == 1) {
    strip.fill(orange, 0, 29);
    strip.show();
    delay(5000);
    condition = 0;
  }
  if (condition == 0) {
    //flicker the light until the condition is met
    //float tempDiff = 0;
    //tempDiff = newTemperature - 32;
    if (BARO.readTemperature() - 23.5 < 2){
      servo.write(0);
      delay(1000);
      strip.fill(blue, 0, 29);
      strip.show();
      strip.setBrightness(200);
      strip.show();
      delay(random(25,100));
      strip.setBrightness(50);
      strip.show();
      delay(random(25,100));
      newTemperature = BARO.readTemperature();
      //tempDiff = BARO.readTemperature() - 32;
      Serial.println(newTemperature);
      //Serial.println(tempDiff);
    }
    //if the temperature difference is met, the color will change and the servo will open
    if (BARO.readTemperature() - 23.5 > 2){
        strip.fill(green, 0, 29);
        strip.show();
        servo.write(150);
        delay(2500);
        condition = 1;
    }
  }

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

    //else if(BARO.readTemperature() < temperature){
    //  strip.fill(blue, 0, 29);
    //  strip.show();
  //}

  // print the sensor value
  Serial.print("Temperature = ");
  Serial.print(newTemperature);
  Serial.println(" C");
  Serial.print(newTemperature - temperature);
  Serial.print(condition);

  // print an empty line
  Serial.println();
  //temperature = BARO.readTemperature();
  // wait 1 second to print again
  delay(250);
}
Click to Expand

Content Rating

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

0