Page 8 of 10

Re: My code

PostPosted: Mon Jul 01, 2013 11:00 am
by bencollinz
lnevo wrote:The only reason I suggest this route is that I like to see my drivers blinking in feeding mode :) You could certainly set it in code, but then you lose the nice light show :D

wow, your code is insane! I tried to pick through it to figure out NTM mode after exiting feeding mode for a set amount of time and just got entirely lost. is there an easier way?

Re: My code

PostPosted: Mon Jul 01, 2013 11:09 am
by lnevo
It's actually pretty straight forward, but my code does a lot...

So during feeding mode, I update a variable with the current time. When feeding mode stops that variable stops getting updated and I know when feeding mode ends.

Code: Select all
static unsigned long feeding;
if (ReefAngel.DisplayedMenu==FEEDING_MODE) {
 feeding=now();
}


Then during each pass of loop() you can check that varaible and run NTM for whatever amount of time you want:

Code: Select all
if (now()-feeding > 1 && now()-feeding < 3600) { // 1 second after feeding mode until 60 minutes after feeding mode.
 ... // Run your smart_ntm here.
}


I left the ... in place of whatever you want to do. Keep in mind if you have other scheduling overrides and modes happening, you'll need to make that if part of that loop or do it after... this is where my stuff gets more complex and will probably similar in your code.

Re: My code

PostPosted: Mon Jul 01, 2013 12:12 pm
by bencollinz
like this?

Code: Select all
 void_loop(){
 if (hour() >=8 && hour() < 22)
  {
    if (ReefAngel.RF.Mode==Night) ReefAngel.RF.SetMode(Feeding_Stop,0,0);
    ReefAngel.RF.UseMemory=true;
        if (ReefAngel.DisplayedMenu==FEEDING_MODE)
        {
         feeding=now();
         }
        if (now()-feeding > 1 && now()-feeding < 3600) { // 1 second after feeding mode until 60 minutes after feeding mode.
ReefAngel.RF.SetMode(vtMode,vtSpeed,vtDuration);
}
    ReefAngel.Relay.Off(Port8);
  }
  else
  {
    ReefAngel.RF.UseMemory=false;
    ReefAngel.RF.SetMode(Night,15,0);
    ReefAngel.Relay.On(Port8);
  }
   // This should always be the last line
        ReefAngel.Portal( "bencollinz" );
        ReefAngel.ShowInterface();
    }

Re: My code

PostPosted: Mon Jul 01, 2013 1:14 pm
by bencollinz
sorry. i have no programming skills whatsover.

Re: My code

PostPosted: Mon Jul 01, 2013 1:33 pm
by lnevo
I see that :) No worries. I'll see what I can do on the trainride home for you.

Re: My code

PostPosted: Mon Jul 01, 2013 2:21 pm
by lnevo
Actually it looks like you got it. The only thing you need to add is to set UseMemory false if you are doing SetMode like that. Otherwise it looks good.

Don't forget to declare the feeding variable...the static unsigned long feeding; statement. It can be inside the loop function, as long as its before the test.

Good work!

Re: My code

PostPosted: Mon Jul 01, 2013 3:44 pm
by bencollinz
lnevo wrote:Actually it looks like you got it. The only thing you need to add is to set UseMemory false if you are doing SetMode like that. Otherwise it looks good.

Don't forget to declare the feeding variable...the static unsigned long feeding; statement. It can be inside the loop function, as long as its before the test.

Good work!

ok, but I want it to function as follows...
between 8am and 10pm I want it to use whatever setting from memory (ie. portal)
if between 8am and 10pm I go into feeding mode then for 1 hour afterwards it does NTM mode
otherwise it's nite mode ie. ReefAngel.RF.UseMemory=false; ReefAngel.RF.SetMode(Night,15,0);

is that making sense? or am I misunderstanding how this works?

Re: My code

PostPosted: Mon Jul 01, 2013 3:47 pm
by bencollinz
or like this?

Code: Select all
     void_loop(){
    if (hour() >=8 && hour() < 22)
      {
        if (ReefAngel.RF.Mode==Night) ReefAngel.RF.SetMode(Feeding_Stop,0,0);
        ReefAngel.RF.UseMemory=true;
            if (ReefAngel.DisplayedMenu==FEEDING_MODE)
            {
             feeding=now();
             }
            if (now()-feeding > 1 && now()-feeding < 3600) { // 1 second after feeding mode until 60 minutes after feeding mode.
  ReefAngel.RF.UseMemory=false;
    ReefAngel.RF.SetMode(vtMode,vtSpeed,vtDuration);
    }
        ReefAngel.Relay.Off(Port8);
      }
      else
      {
        ReefAngel.RF.UseMemory=false;
        ReefAngel.RF.SetMode(Night,15,0);
        ReefAngel.Relay.On(Port8);
      }
       // This should always be the last line
            ReefAngel.Portal( "bencollinz" );
            ReefAngel.ShowInterface();
        }

Re: My code

PostPosted: Mon Jul 01, 2013 3:56 pm
by lnevo
Yeah exactly.

Re: My code

PostPosted: Mon Jul 01, 2013 4:00 pm
by bencollinz
lnevo wrote:Yeah exactly.

testing it now. thank you so so so so much for helping me!