//Program created by Isma LB #include #define TX 1 #define LED_OUT A3 #define NIGHT_TRESHOLD 80 #define DIRECT_SUN_UP_TRESHOLD 1000 #define DIRECT_SUN_LOW_TRESHOLD 800 #define MIN_STATE_TIME 25000 SendOnlySoftwareSerial CustomSerial(TX); const long A = 1000; //Resistence on darkness on KΩ const int B = 27; //Resistence on light (10 Lux) on KΩ const int Rc = 10; //Calibracion resistance on KΩ int value, ilum; //values used for the treshold and button logic unsigned long lastChange = 0; bool overrideON = false; bool buttonPressed = false; bool lightOn = false; void setup() { //set the prescaler to 1 to run at 8MHz CLKPR = (1<1020&&!buttonPressed){ buttonPressed = true; overrideON = !overrideON; lastChange = 0; } if(value<800){ buttonPressed = false; } if(!lightOn&& (ilum>NIGHT_TRESHOLD&&ilumDIRECT_SUN_UP_TRESHOLD || ilum<=NIGHT_TRESHOLD) ) { lightOn = false; CustomSerial.println('d'); //Send the code for light not needed } // Waits to make light chages least often (Not needed for networking) if(millis() - lastChange > MIN_STATE_TIME)return; lastChange = millis(); if(lightOn){ // Light needed, turn light ON digitalWrite(LED_OUT,HIGH); } else{ //light not needed, turn light OFF digitalWrite(LED_OUT,LOW); } }