My code - now with RAnet

Share you PDE file with our community

Posts: 151
Joined: Wed Mar 13, 2013 5:36 pm
PostPosted: Mon Jul 01, 2013 11:00 am
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?
Image
User avatar
Posts: 5343
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Mon Jul 01, 2013 11:09 am
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.

Posts: 151
Joined: Wed Mar 13, 2013 5:36 pm
PostPosted: Mon Jul 01, 2013 12:12 pm
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();
    }
Image

Posts: 151
Joined: Wed Mar 13, 2013 5:36 pm
PostPosted: Mon Jul 01, 2013 1:14 pm
sorry. i have no programming skills whatsover.
Image
User avatar
Posts: 5343
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Mon Jul 01, 2013 1:33 pm
I see that :) No worries. I'll see what I can do on the trainride home for you.
User avatar
Posts: 5343
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Mon Jul 01, 2013 2:21 pm
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!

Posts: 151
Joined: Wed Mar 13, 2013 5:36 pm
PostPosted: Mon Jul 01, 2013 3:44 pm
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?
Image

Posts: 151
Joined: Wed Mar 13, 2013 5:36 pm
PostPosted: Mon Jul 01, 2013 3:47 pm
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();
        }
Image
User avatar
Posts: 5343
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Mon Jul 01, 2013 3:56 pm
Yeah exactly.

Posts: 151
Joined: Wed Mar 13, 2013 5:36 pm
PostPosted: Mon Jul 01, 2013 4:00 pm
lnevo wrote:Yeah exactly.

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

Return to My PDE/INO file

Who is online

Users browsing this forum: No registered users and 1 guest

cron