#include <DHT.h>
DHT sensor1(PA0, DHT22);
float humidity;
float temperature;
static int state = 0;
int c = 0;
void change(){
state ^= 1;
}
void setup() {
Serial.begin(115200);
pinMode(PB1, INPUT_PULLDOWN);
pinMode(PB0, OUTPUT);
attachInterrupt(PB1, change, RISING);
}
void loop() {
humidity = sensor1.readHumidity();
temperature = sensor1.readTemperature();
if(state == 0){
Serial.println(String("humidity: " + String(humidity)));
if(humidity > 50){
c++;
if(c>=2){
GPIOB -> ODR ^= 1;
c = 0;
}
}
else{
GPIOB -> ODR ^= 1;
}
}
else{
Serial.println(String("temperature:" + String(temperature)));
if(temperature > 30){
GPIOB -> ODR ^= 1;
}
else{
c++;
if(c>=2){
GPIOB -> ODR ^= 1;
c = 0;
}
}
}
Serial.println();
delay(1000);
}