#include #define DHT_SENSOR_TYPE DHT_TYPE_11 #define LED_RED 9 #define LED_YELLOW 10 #define LED_GREEN 11 #define LED_BLUE 6 #define LED_WHITE 5 static const int DHT_SENSOR_PIN = 2; DHT_nonblocking dht_sensor( DHT_SENSOR_PIN, DHT_SENSOR_TYPE ); int led_value,led_color,led_procedures,led_gradual,led_intermittence,proc_alarm,temp_max,temp_min,hum_max,hum_min; String led_color_str,led_value_str,led_procedures_str,temp_max_str,temp_min_str,hum_max_str,hum_min_str,proc_alarm_str; void setup() { Serial.begin(9600); pinMode(4, INPUT); } static bool measure_environment( float *temperature, float *humidity ) { static unsigned long measurement_timestamp = millis( ); if( millis( ) - measurement_timestamp > 1000ul ) { if( dht_sensor.measure( temperature, humidity ) == true ) { measurement_timestamp = millis( ); return( true ); } } return( false ); } void loop() { float temperature; float humidity; if (digitalRead(4) == HIGH) {if( measure_environment( &temperature, &humidity ) == true ) { Serial.print( temperature ); Serial.print("|"); Serial.print( humidity ); Serial.println(); } } if (Serial.available()) { led_procedures_str = Serial.readStringUntil('.'); int led_procedures = led_procedures_str.toInt(); led_color_str = Serial.readStringUntil(';'); int led_color = led_color_str.toInt(); led_value_str = Serial.readStringUntil('\n'); int led_value = led_value_str.toInt(); switch(led_procedures){ case 0: switch(led_color){ case 1: led_value = map(led_value,0,100,0,255); analogWrite(9,led_value); break; case 2: led_value = map(led_value,0,100,0,255); analogWrite(10,led_value); break; case 3: led_value = map(led_value,0,100,0,255); analogWrite(11,led_value); break; case 4: led_value = map(led_value,0,100,0,255); analogWrite(6,led_value); break; case 5: led_value = map(led_value,0,100,0,255); analogWrite(5,led_value); break; } break; case 1: switch(led_color){ case 1: led_value = map(led_value,0,100,0,255); for(led_gradual=0;led_gradual=0;led_gradual--){ analogWrite(9,led_gradual); delay(10); } delay(500); break; case 2: led_value = map(led_value,0,100,0,255); for(led_gradual=0;led_gradual=0;led_gradual--){ analogWrite(10,led_gradual); delay(10); } delay(500); break; case 3: led_value = map(led_value,0,100,0,255); for(led_gradual=0;led_gradual=0;led_gradual--){ analogWrite(11,led_gradual); delay(10); } delay(500); break; case 4: led_value = map(led_value,0,100,0,255); for(led_gradual=0;led_gradual=0;led_gradual--){ analogWrite(6,led_gradual); delay(10); } delay(500); break; case 5: led_value = map(led_value,0,100,0,255); for(led_gradual=0;led_gradual=0;led_gradual--){ analogWrite(5,led_gradual); delay(10); } delay(500); break; } break; case 2: switch(led_color){ case 1: for(led_intermittence=0;led_intermittence<3;led_intermittence++){ analogWrite(9,led_value); delay(500); analogWrite(9,0); delay(500); } break; case 2: for(led_intermittence=0;led_intermittence<3;led_intermittence++){ analogWrite(10,led_value); delay(500); analogWrite(10,0); delay(500); } break; case 3: for(led_intermittence=0;led_intermittence<3;led_intermittence++){ analogWrite(11,led_value); delay(500); analogWrite(11,0); delay(500); } break; case 4: for(led_intermittence=0;led_intermittence<3;led_intermittence++){ analogWrite(6,led_value); delay(500); analogWrite(6,0); delay(500); } break; case 5: for(led_intermittence=0;led_intermittence<3;led_intermittence++){ analogWrite(5,led_value); delay(500); analogWrite(5,0); delay(500); } break; } break; } temp_max_str = Serial.readStringUntil('l'); int temp_max = temp_max_str.toInt(); temp_min_str = Serial.readStringUntil('-'); int temp_min = temp_min_str.toInt(); hum_max_str = Serial.readStringUntil('+'); int hum_max = hum_max_str.toInt(); hum_min_str = Serial.readStringUntil('t'); int hum_min = hum_min_str.toInt(); proc_alarm_str = Serial.readStringUntil('|'); int proc_alarm = proc_alarm_str.toInt(); if (humidity > hum_max){ analogWrite(9,100); delay(500); analogWrite(9,0); } if (proc_alarm = 911){ } } }