Stap 9: Het breken
We hebben nu onze zeer eigen tuin Controller systeem.
Wachten! Ik bedoel, eigen DIY Home automatiseringssysteem. Standaard is de besturing geprogrammeerd met een heleboel regels moeten we commentaar-out. Open-up TheDecider.h bestand nogmaals.
bool TheDecider( void )
{ bool r = false; time_diff = 0; time_now = now();
// update app.ready if it's been 5 minutes since last change.
Appliance * app = &Appliance_FeedPump;
for (; app != NULL; app = app->next ) { time_diff = (time_now - app->timestamp); if (time_diff > 300) { app->ready = true; } }
This code is stepping through all of the "appliance" objects and verifying that we have waited at least 5 minutes before checking the appliance since the last change. The code makes sense when you are controlling fans and garden grow lights but for home automation purposes, this can be reduced. I personally wouldn't set it below 30 seconds.
Het volgende blok van code in TheDecider functie zorgt ervoor dat de sensorgegevens voor vochtigheid en temperatuur functioneert zoals verwacht:
if ( Sensor_Humidity.value == 0 ) { Appliance_Humidifier.ready = false; } if ( Sensor_Temp.value == 0 ) { Appliance_ExhaustFan.state = true; Appliance_ExhaustFan.ready = false; Appliance_IntakeFan.state = true; Appliance_IntakeFan.ready = false; }
De volgende code is voor het reguleren van de temperatuur door het beheersen van fans:
// RH Range if (Appliance_Humidifier.ready == true) { // IF the humidity is less than the minVal and the Humidifier is OFF // THEN turn ON the Humidifier if ((Sensor_Humidity.value < Sensor_Humidity.minVal) && (Appliance_Humidifier.state != true)) { r = true; Appliance_Humidifier.state = true; myAppliance(&Appliance_Humidifier, false); } // IF the humidity is less than the minVal, turn ON the PUMP if ( (Sensor_Humidity.value < Sensor_Humidity.minVal) ) { r = true; Appliance_FeedPump.state = true; myAppliance(&Appliance_FeedPump, false); } ...
Het volgende blok van code is te beoordelen een fotocel ontvangt licht en welke maatregelen moeten worden genomen.
// IF the light reading is greater than the minVal // AND the ExhaustFan is ON - THEN turn OFF Light(s) if ( Appliance_Light.ready ) { if ( (Sensor_Light.value > Sensor_Light.minVal) && (Appliance_ExhaustFan.state == true) ) { r = true; Appliance_Light.state = false; myAppliance( &Appliance_Light, false ); } // IF the light reading is less than the minVal // THEN turn OFF lights if (Sensor_Light.value < Sensor_Light.minVal) { r = true; Appliance_Light.state = false; myAppliance(&Appliance_Light, false); } }
De resterende regels zijn voor het reguleren van een waterpomp. We kunnen verwijderen of commentaar ze uit. TheDecider functie eindigt met:
/* ToDo: */
return r; }