Lights On override

Do you have a question on how to do something.
Ask in here.
Post Reply
tanked_kiwi
Posts: 37
Joined: Thu May 22, 2014 3:25 am

Lights On override

Post by tanked_kiwi »

I'm trying to code my dimming expansion so that when lights on is selected, my leds will go to their End %, until out of lights on mode.

I have it all working with a custom memory location that I can manually edit from the app. All I need is to detect when lights on mode is selected and have the byte changed depending on that. Is there a memory location I can read to determine this?

Evan.
tanked_kiwi
Posts: 37
Joined: Thu May 22, 2014 3:25 am

Re: Lights On override

Post by tanked_kiwi »

Nevermind, I got it.

This will set the dimming expansion channels to their end% when lights on mode is used. I have used my LED psu relay (Port 4) as the trigger, but you could use a virtual relay outlet tied to LightsOnPorts instead. Here is the code for anyone that may find it useful.

Overriding the led channels from the web app/server still works as it should and as soon as you hit Lights Off everything returns to normal.

Criticism (constructive of course :) ) is welcome, still new to this programming lingo and not sure if this is the most efficient way to do it.

Add this to Setup:

Code: Select all

ReefAngel.LightsOnPorts = Port4Bit; /// Make sure your chosen relay outlet for the following code is included here.

///// Place additional initialization code below here

  InternalMemory.write(199, 0); //Set the Custom Memory location with the non-overridden value

  ////// Place additional initialization code above here

Add this to Loop:

Code: Select all

///// Place your custom code below here

  ////// ---------------Override PWM Light Channels--------------------
  
  // Custom Memory Location To Store Overide State
  if (bitRead(ReefAngel.Relay.RelayMaskOn,3)) { 
    if (InternalMemory.read(199)!=1){
      InternalMemory.write(199, 1);
    }  
  }
  else if (InternalMemory.read(199)!=0){
    InternalMemory.write(199, 0);
  }    
  
  
  // Removes LED's from a Overridden State
  if ( InternalMemory.read(199) == 0 )
  {
    ReefAngel.PWM.SetChannel( 0, PWMSlope((InternalMemory.read(204)),(InternalMemory.read(205)),(InternalMemory.read(206)),(InternalMemory.read(207)),(InternalMemory.read(258)),(InternalMemory.read(259)),(InternalMemory.read(260)),(InternalMemory.read(258)))); //Set Channel 0 to PWMSlope using internal memory settings for Channel 0
    
ReefAngel.PWM.SetChannel( 1, PWMSlope((InternalMemory.read(204)),(InternalMemory.read(205)),(InternalMemory.read(206)),(InternalMemory.read(207)),(InternalMemory.read(261)),(InternalMemory.read(262)),(InternalMemory.read(263)),(InternalMemory.read(261)))); //Set Channel 1 to PWMSlope using internal memory settings for Channel 1
    
ReefAngel.PWM.SetChannel( 2, PWMSlope((InternalMemory.read(204)),((InternalMemory.read(205))-(InternalMemory.read(284))),(InternalMemory.read(206)),((InternalMemory.read(207)+(InternalMemory.read(284)))),(InternalMemory.read(264)),(InternalMemory.read(265)),(InternalMemory.read(266)),(InternalMemory.read(264)))); //Set Channel 2 to PWMSlope using internal memory settings for Channel 2, includes difference for Actinic Offset
    
ReefAngel.PWM.SetChannel( 3, PWMSlope((InternalMemory.read(204)),(InternalMemory.read(205)),(InternalMemory.read(206)),(InternalMemory.read(207)),(InternalMemory.read(267)),(InternalMemory.read(268)),(InternalMemory.read(269)),(InternalMemory.read(267)))); //Set Channel 3 to PWMSlope using internal memory settings for Channel 3
    }

  // Override LED's to End% Intensity for each Channel
  if ( InternalMemory.read(199) == 1 )
  {
    ReefAngel.PWM.SetChannel( 0, (InternalMemory.read(259)) ); //Set channel 0 to channel 0 end%
    ReefAngel.PWM.SetChannel( 1, (InternalMemory.read(262)) ); //Set channel 1 to channel 1 end%
    ReefAngel.PWM.SetChannel( 2, (InternalMemory.read(265)) ); //Set channel 2 to channel 2 end%
    ReefAngel.PWM.SetChannel( 3, (InternalMemory.read(268)) ); //Set channel 3 to channel 3 end%
  }

////// Place your custom code above here
EDIT: This worked fine for awhile and then stopped working. I think I may have corrupted the memory location from constantly writing to that location. I have now added a check to make sure it only gets written to when needed.
Code above has been updated.
Post Reply