#define DHT_PIN 12
#define LED_LOW 7 //yellow
#define LED_HIGH 6 // orange
void setup() {
Serial.begin(115200);
pinMode(LED_LOW,OUTPUT);
pinMode(LED_HIGH,OUTPUT);
// put your setup code here, to run once:
}
void loop() {
pinMode(DHT_PIN,OUTPUT);
digitalWrite(DHT_PIN,LOW);
delay(18);
digitalWrite(DHT_PIN, HIGH);
delayMicroseconds(40);
pinMode(DHT_PIN, INPUT);
while(digitalRead(DHT_PIN) == HIGH);
while(digitalRead(DHT_PIN) == LOW);
while(digitalRead(DHT_PIN) == HIGH);
int i = 0;
do{
unsigned long int tOut = 0;
unsigned long int t = micros();
while(digitalRead(DHT_PIN) == LOW); // wait 50 us
while(digitalRead(DHT_PIN) == HIGH)
{
tOut = micros() - t;
}
if(tOut > 50)
{
output_toggle(LED_HIGH);
//this is a 1
}
else
{
output_toggle(LED_LOW);
//this a 0
}
i++;
}while(i != 40);
Serial.println("ok");
delay(1000);
// put your main code here, to run repeatedly:
}
void output_toggle(int pin)
{
int status = digitalRead(pin);
digitalWrite(pin,!status);
}