#include "DHTesp.h"
#include "LiquidCrystal.h"
// model.h includes the tinyeverywhereml includes
// NOTE: wokwi does not load the tinyeverywhereml library correctly here.
// known issue, no-known solution currently.
#include "cmodel.h"
Eloquent::TinyML::TensorFlow::TensorFlow<2, 1, ARENA_SIZE> tf;
const int DHT_PIN = 23;
DHTesp dhtSensor;
const int rs = 19, en = 18, d4 = 5, d5 = 17, d6 = 16, d7 = 4;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int columns = 16;
const int rows = 2;
String temp, humi;
void setup() {
Serial.begin(115200);
lcd.begin(columns,rows);
lcd.print("Hello ^.^");
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
tf.begin(cmodel);
// check if model loaded fine
if (!tf.isOk()) {
Serial.print("ERROR: ");
Serial.println(tf.getErrorMessage());
while (true) delay(1000);
}
}
void lcdWrite(LiquidCrystal lcd, String msg, String msg2=""){
lcd.clear();
// return cursor to top left
lcd.home();
lcd.print(msg);
if( msg2 != "" ){
// move cursor down a row.
lcd.setCursor(0,1);
lcd.print(msg2);
}
}
void loop() {
TempAndHumidity data = dhtSensor.getTempAndHumidity();
temp = "Temp: " + String(data.temperature, 2) + " C";
humi = "Humidity: " + String(data.humidity, 1) + "%";
float x[2] = {data.temperature, data.humidity};
float input[1] = { x }
int predicted = tf.predict(input);
if( predicted == 0 )
lcdWrite(lcd, "NORMAL");
else:
lcdWrite(lcd, "EXTREME!!!");
delay(1000);
}