---
# System prepended metadata

title: Untitled

---

#include "Seeed_BME280.h"
#include <Wire.h>
#include "rgb_lcd.h"

BME280 bme280;
rgb_lcd lcd;

int colorR = 0;
int colorG = 0;
int colorB = 255;

int BuzzerPin = 2;
int LED = 4;

void setup() {
    // set up the LCD's number of columns and rows:
    lcd.begin(16, 2);
    lcd.setRGB(colorR, colorG, colorB);
    lcd.print("Hello!");
    delay(5000);

    // buzzer set up
    pinMode(BuzzerPin, OUTPUT);
    // LED
    pinMode(LED, OUTPUT);

    Serial.begin(9600);
    if (!bme280.init()) {
        Serial.println("Device error!");
    }
}

void loop() {

    String start_c = "\{ ";
    String end_c = " \}";
    String comma_c =",";    

    String temp = "\"temp\":";
    float temp_val = bme280.getTemperature();

 

    String humidity = "\"humidity\":";
    float humidity_val = bme280.getHumidity(); 

    String light = "\"light\":";
    int light_val = analogRead(A0);
    light_val = map(light_val, 0, 800, 0, 10);
     

    String all = start_c + temp + temp_val + comma_c+ humidity + humidity_val + comma_c + light + light_val + end_c;
    Serial.println(all);

    // Display the three parameters
    if (temp_val < 28) {
        colorR = 0;
        colorG = 255;
        colorB = 0;
    } else {
        colorR = 255;
        colorG = 0;
        colorB = 0;
    }
    lcd.setRGB(colorR, colorG, colorB);
    lcd.setCursor(0, 0);
    lcd.print("T:");
    lcd.print(temp_val);
    lcd.print(", H:");
    lcd.print(humidity_val);
    lcd.setCursor(0, 1);
    lcd.print(", L:");
    lcd.print(light_val);

    if (temp_val > 28) {
        tone(BuzzerPin, 200); // tone(pin, frequency)
        // ok: digitalWrite(BuzzerPin, HIGH);
        // ok: analogWrite(BuzzerPin, 128);
        delay(500);
        noTone(BuzzerPin);
	// ok: digitalWrite(BuzzerPin, LOW);
        // ok: analogWrite(BuzzerPin, 0);
        if (light_val > 7){
            digitalWrite(LED, LOW); // set the LED on
        } else {
            digitalWrite(LED, HIGH); // set the LED on
        } 
        delay(4500);

    } else {
        if (light_val > 7){
            digitalWrite(LED, LOW); // set the LED on
        } else {
            digitalWrite(LED, HIGH); // set the LED on
        } 
        delay(5000);
    }
}