Home AMX User Forum AMX General Discussion
Options

Blind controls

Hi,

I am looking to have 5 sets of blinds controlled via relays, with 5 buttons that select which blinds to operate and then open and close buttons to pulse the equilivant relays that have been selected from the above buttons.

I am using "Select and Active" to determine which buttons are active for the single blind control, but not sure what the best way to trigger the relays on the various combinations of selections. i know i could use "if" statements for all combinations, but would pefer a more efficient way.

Any help appreciated

Regards,

Noel

Comments

  • Options
    ColzieColzie Posts: 470
    I'd do something like this. I like to have the "config" type information for the whole system in a common location, separate from the control of the device. I'd have a variable array for the 1-5 buttons for blind selection, then use get_last to determine the current 1-5 value to send to the function.

    Variable population
    //these values correspond the actual relay values
    i_blinds[1][1] = 1
    i_blinds[1][2] = 2
    i_blinds[2][1] = 3
    i_blinds[2][2] = 4
    i_blinds[3][1] = 5
    i_blinds[3][2] = 6
    i_blinds[4][1] = 7
    i_blinds[4][2] = 8
    i_blinds[5][1] = 9
    i_blinds[5][2] = 10
    

    Blind control function
    /*
    	iBlind = 1, 2, 3, 4, or 5  //which blind
    	iCmd = 1 or 2  //up or down
    */
    define_function	fn_blinds (integer iBlind, integer iCmd)
    {	
    	pulse[dv_RELAY, i_blinds[iBlind][iCmd]]
    }
    
  • Options
    jjamesjjames Posts: 2,908
    nds2006 wrote: »
    Hi,

    I am looking to have 5 sets of blinds controlled via relays, with 5 buttons that select which blinds to operate and then open and close buttons to pulse the equilivant relays that have been selected from the above buttons.

    I am using "Select and Active" to determine which buttons are active for the single blind control, but not sure what the best way to trigger the relays on the various combinations of selections. i know i could use "if" statements for all combinations, but would pefer a more efficient way.

    Any help appreciated

    Regards,

    Noel
    I personally love look up tables. :D

    I'd do something like this:
    DEFINE_CONSTANT
    nRELAY_PULSE[]=
    {
    	 101 // OPEN
    	,102 // CLOSE
    }
    
    nRELAY_SELECT_BTNS[]=
    {
    	 111
    	,112
    	,113
    	,114
    }   
    
    INTEGER nRELAY_MAP[][]=
    {
    	// Relay 1
    	{
    		 1
    		,2
    	},  
    	// Relay 2
    	{   
    		 3
    		,4
    	}   
    	// Relay 3
    	{   
    		 5
    		,6
    	}   
    	// Relay 4
    	{   
    		 7
    		,8
    	}   
    }
    
    DEFINE_VARIABLE
    nSELECTED_RELAY[5]	// Holds which one you're controlling
    
    DEFINE_EVENT
    BUTTON_EVENT[dvTP,nRELAY_SELECT_BTNS]
    {
    	PUSH:
    		nSELECTED_RELAY[GET_LAST(nRELAY_SELECT_BTNS)] = !nSELECTED_RELAY[GET_LAST(nRELAY_SELECT_BTNS)]
    }
    
    BUTTON_EVENT[dvTP,nRELAY_PULSE]
    {
    	PUSH:
    	{	
    		FOR(nLOOP=1;nLOOP<=LENGTH_ARRAY(nSELECTED_RELAY);nLOOP++)
    		{
    			IF(nSELECTED_RELAY[nLOOP]
    				PULSE(dvRELAY,nRELAY_MAP[nLOOP][GET_LAST(nRELAY_PULSE)])
    		}
    	}
    }
    
    Note - I haven't tested this.

    Perhaps we're not on the same page either though, so I could be doing something here you don't want to do.

    Basically, you select which ones you wish to control, then hit the up or down button, and it does those ones that are selected. That's what you're trying to accomplish right?
  • Options
    nds2006nds2006 Posts: 10
    Hi,

    JJames, Yes that is what i am looking to do, select the blind buttons and then use open and close.

    I have tested you example and it does not seem to be just right.

    The nSELECTED_RELAY variable is not storing which buttons have been selected.

    BUTTON_EVENT[tp,nRELAY_SELECT_BTNS]
    {
    PUSH:
    {
    nSELECTED_RELAY[get_last(nRELAY_SELECT_BTNS)] = !nSELECTED_RELAY[get_last(nRELAY_SELECT_BTNS)]
    }
    }
    This is what I have in the code, can you explain what the ! is doing??

    Regards,

    Noel
  • Options
    jjamesjjames Posts: 2,908
    nds2006 wrote: »
    BUTTON_EVENT[tp,nRELAY_SELECT_BTNS]
    {
        PUSH:
    	{
    	nSELECTED_RELAY[get_last(nRELAY_SELECT_BTNS)] = !nSELECTED_RELAY[get_last(nRELAY_SELECT_BTNS)]
    	}
    }
    
    This is what I have in the code, can you explain what the ! is doing??
    Hmm . . . Like I said - I didn't test this, but the ! is NOT-ing the value of nSELECTED_RELAY[index]. It's a short way of saying,
    IF(nSELECTED_RELAY[GET_LAST(nRELAY_SELECTED_BTNS)]) == 0)
       ON[nSELECTED_RELAY[GET_LAST(nRELAY_SELECTED_BTNS)]]
    ELSE
       OFF[nSELECTED_RELAY[GET_LAST(nRELAY_SELECTED_BTNS)]]
    

    I don't have access to a processor right now - but are you watching the variable to see if it changes?
    You could add a LOCAL_VAR in that button event, and give it the value of GET_LAST(nRELAY_SELECTED_BTNS) and watch the value to make sure it's changing. I'm sure I'm missing something or doing something really stupid . . . I just can't see it. :p
  • Options
    SensivaSensiva Posts: 211
    Idea!!

    Can you make it more simple??

    I normally do it in this way, a single button for each blind that does all; Open, Close, Stop, No need to select.
  • Options
    Joe HebertJoe Hebert Posts: 2,159
    jjames wrote:
    I don't have access to a processor right now - but are you watching the variable to see if it changes?
    The values are changing but you won?t see them change in the debugger unless you view the total length of nSELECTED_RELAY. The FOR loop won?t execute as expected because there is no length to the nSELECTED_RELAY array.

    If the variable declaration is changed to this then all will be good.
    nSELECTED_RELAY[4] = {0,0,0,0}
  • Options
    jjamesjjames Posts: 2,908
    Joe Hebert wrote: »
    The values are changing but you won?t see them change in the debugger unless you view the total length of nSELECTED_RELAY. The FOR loop won?t execute as expected because there is no length to the nSELECTED_RELAY array.

    If the variable declaration is changed to this then all will be good.
    nSELECTED_RELAY[4] = {0,0,0,0}
    Are you sure? A variable defined as nSELECTED_RELAY[4] without initialization won't work? I use plenty of variables in code that don't have an initialization and can still loop through them with LENGTH_ARRAY. I've never encountered this problem.
  • Options
    Joe HebertJoe Hebert Posts: 2,159
    jjames wrote: »
    Are you sure? A variable defined as nSELECTED_RELAY[4] without initialization won't work? I use plenty of variables in code that don't have an initialization and can still loop through them with LENGTH_ARRAY. I've never encountered this problem.
    I?m positive it won?t work as expected. The length of the array is never set in the code and assigning values to individual elements in the array won?t alter the length of the array.

    You don?t have to initialize the array in the declaration as I suggested but somewhere in the code the length has to be set. You could also do something like this by using direct assignment:

    DEFINE_START
    nSELECTED_RELAY = ?0,0,0,0?

    or force the length like this:
    DEFINE_START
    SET_LENGTH_ARRAY(nSELECTED_RELAY,4)

    But somewhere in code the length has to be set or the FOR loop won?t loop.
  • Options
    nds2006nds2006 Posts: 10
    Putting the assignment into the DEFINE_START makes this work ok, thanks for all the information and help

    Regards,

    Noel
Sign In or Register to comment.