Probably the Simplest of Timing Questions but it has me Stumped!


hi everyone,

first ever post , second sketch have ever written please bear me.

basically trying automate indoor garden turning power leds on , off , reading outside , inside temperatures 2 x ds18s20 temp sensors.

i have got temp sensors , running , reporting serial monitor without major problems , have managed lights turn off on 12 hour cycles using 'millis' function understand principles behind. want modify code can have 10 hour dark , 14 hour light period. have been looking afternoon @ ways using cant work out.  i cant seem find online answers question without complete confusing me commands don't yet understand. thought post on hear see if point me in right direction.

i mega eager learn said second piece of code have ever written apologies simplest of questions. gratefully received.

this have created far works fine:

code: [select]

#include <onewire.h>
#include <dallastemperature.h>

onewire onewire(8);
dallastemperature sensors(&onewire);

int leds=13;
int second=1000;
unsigned long minute= 60000;
unsigned long hour= 3600000;
unsigned long halfday= 43200000;
unsigned long previousmillis=0;


void setup()
{
  pinmode(leds, output);
  sensors.begin(); //sets sensors
  serial.begin(9600);
}
 

void loop()

{
 //reading 2 x ds18s20 temp sensors
 
 sensors.requesttemperatures();
 float currenttemp1;
 currenttemp1 = sensors.gettempcbyindex(0);  
 
 float currenttemp2; //sets 'float' type variable called 'current temp
 currenttemp2 = sensors.gettempcbyindex(1);
 
 serial.println("inside temp =");
 serial.println(currenttemp1);
 serial.println("outside temp =");
 serial.println(currenttemp2);
 
 
   //lights toggling on/off on 12hour cycle
 
 unsigned long currentmillis = millis();

 if ((unsigned long)(currentmillis - previousmillis) >= hour)
 
     {
       
     digitalwrite(leds, !digitalread(leds)); // toggle led on pin 13
     previousmillis = currentmillis;
     
     }
       
}



many

mickey


do care when light , dark periods relative real-world time?

if not, have state variable recording whether it's 'light' or 'dark' , use determine duration apply in time calculation.


Arduino Forum > Using Arduino > Programming Questions > Probably the Simplest of Timing Questions but it has me Stumped!


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support