#include "DHTesp.h"
const int DHT_PIN = 15;
const int t_pL = 5;
const int e_pL = 18;
const float ss = 0.034;
long durnL;
float dist_cmL;
const int t_pW = 21;
const int e_pW = 19;
long durnW;
float dist_cmW;
DHTesp dhtSensor;
// Servo lock;
// Servo food;
// Servo water;
const int lock_pin = 32;
const int water_pin = 33;
const int foood_pin = 25;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
pinMode(t_pL, OUTPUT);
pinMode(e_pL, INPUT);
pinMode(t_pW, OUTPUT);
pinMode(e_pW, INPUT);
}
// Read temperature and humidity
// 21127601
double getTemp(){
TempAndHumidity data = dhtSensor.getTempAndHumidity();
return data.temperature;
}
double getHumid(){
TempAndHumidity data = dhtSensor.getTempAndHumidity();
return data.humidity;
}
// Measure water level
// 21127601
double getWaterLevel() {
digitalWrite(t_pW, LOW);
delayMicroseconds(2);
digitalWrite(t_pW, HIGH);
delayMicroseconds(10);
digitalWrite(t_pW, LOW);
durnW = pulseIn(e_pW, HIGH);
dist_cmW = durnW * ss / 2;
return 30 - dist_cmW;
}
// Check if the Lid is open (> 10 cm)
// 21127601
bool isLidOpen(){
digitalWrite(t_pL, LOW);
delayMicroseconds(2);
digitalWrite(t_pL, HIGH);
delayMicroseconds(10);
digitalWrite(t_pL, LOW);
durnL = pulseIn(e_pL, HIGH);
dist_cmL = durnL * ss / 2;
if(dist_cmL > 10)
return true;
return false;
}
//21127643
// Lock the cage
// 21127643
void lockCage(){
}
// Lock the cage
// 21127643
void openCage(){
}
// Release water
// 21127643
void releaseWater() {
}
// Release food
// 21127643
void releaseFood() {
}
// Read
void loop() {
// put your main code here, to run repeatedly:
delay(2000); // this speeds up the simulation
Serial.println(getWaterLevel());
Serial.println(isLidOpen());
}