// BSEC Software Library - Version: 1.6.1480
#include <bsec.h>
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/3cd71424-ed50-407c-affe-783e581eee97
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
String weather_report;
float humidity;
float temperature;
int light;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
#include <Arduino_MKRIoTCarrier.h>
MKRIoTCarrier carrier;
int modeSelect = 0;
int previousMode = 0;
int refreshCount = 0;
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
//while (!Serial);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
//Get Cloud Info/errors , 0 (only errors) up to 4
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
//Wait to get cloud connection to init the carrier
while (ArduinoCloud.connected() != 1) {
ArduinoCloud.update();
delay(500);
}
delay(500);
CARRIER_CASE = false;
carrier.begin();
carrier.display.setRotation(0);
carrier.display.fillScreen(ST77XX_BLACK);
carrier.display.setTextColor(ST77XX_WHITE);
carrier.display.setTextSize(3);
carrier.display.setCursor(60, 80);
carrier.display.print("Aether");
//carrier.display.setCursor(60, 120);
//carrier.display.print("Station");
delay(2000);
carrier.display.fillScreen(ST77XX_BLACK);
carrier.display.setTextColor(ST77XX_WHITE);
carrier.display.setTextSize(2);
carrier.display.setCursor(70, 80);
carrier.display.print("Connected");
carrier.display.setCursor(50, 110);
carrier.display.print("To IoT Cloud");
delay(2000);
}
void loop() {
ArduinoCloud.update();
carrier.Buttons.update();
while (!carrier.Light.colorAvailable()) {
delay(5);
}
int none;
carrier.Light.readColor(none, none, none, light);
temperature = carrier.Env.readTemperature();
humidity = carrier.Env.readHumidity();
if (carrier.Button0.onTouchDown()) {
modeSelect = 0;
} else if (carrier.Button1.onTouchDown()) {
modeSelect = 1;
} else if (carrier.Button2.onTouchDown()) {
modeSelect = 2;
} else if (carrier.Button3.onTouchDown()) {
modeSelect = 3;
}
if (modeSelect != previousMode) {
updateDisplay();
previousMode = modeSelect;
refreshCount = 0;
} else if (refreshCount >= 50) {
updateDisplay();
refreshCount = 0;
}
if (humidity >= 60 && temperature >= 15) {
weather_report = "It is very humid outside";
} else if (temperature >= 25 && light >= 700) {
weather_report = "Hot and sunny outside";
} else if (light <= 100) {
weather_report = "It is dark outside";
} else if (temperature >= 15 && light >= 700) {
weather_report = "Warm and sunny outside";
} else if (temperature <= 16 && light >= 700) {
weather_report = "A little cold, but sunny outside";
} else if (humidity >= 90 && temperature <= 15) {
weather_report = "It is wet and rainy outside";
}
refreshCount++;
}
void updateDisplay() {
if (modeSelect == 0) {
carrier.display.fillScreen(ST77XX_RED);
carrier.display.setTextColor(ST77XX_WHITE);
carrier.display.setTextSize(4);
carrier.display.setCursor(70, 50);
carrier.display.print("Temp:");
carrier.display.setCursor(40, 110);
carrier.display.print(temperature);
carrier.display.print(" C");
} else if (modeSelect == 1) {
carrier.display.fillScreen(ST77XX_BLUE);
carrier.display.setTextColor(ST77XX_WHITE);
carrier.display.setTextSize(4);
carrier.display.setCursor(70, 50);
carrier.display.print("Humi:");
carrier.display.setCursor(40, 110);
carrier.display.print(humidity);
carrier.display.print(" %");
} else if (modeSelect == 2) {
carrier.display.fillScreen(ST77XX_GREEN);
carrier.display.setTextColor(ST77XX_BLACK);
carrier.display.setTextSize(4);
carrier.display.setCursor(60, 60);
carrier.display.print("Light:");
carrier.display.setCursor(80, 120);
carrier.display.print(light);
}
else {
carrier.display.fillScreen(ST77XX_BLACK);
}
}