Home AMX User Forum NetLinx Studio

Counting

I think I am having a total brain dump or a nervous breakdown or something. I need to fetch a variable, and everytime the user presses a button, that number will increase by one. I am allowing them to set the clock via the touch panel. When they enter the clock settings screen, the current time is displayed. I am capturing that like so:
nHours = ATOI(LEFT_STRING(TIME,2))
nMinutes = ATOI(MID_STRING(TIME,4,2))

That works fine. What I need to now do is allow them to push the hour up or down button and have it increment or decrement the hour by one each button press. After they are done setting the clock, I was going to send the new variables (nHours and nMinutes) to the NetLinx as the new time using this format:

SEND_COMMAND <DEV>,"'CLOCK <mm-dd-yy> <hh:mm:ss>'"

A simple up counter should only take like 5 minutes to write. Maybe I am just tired. I currently have it set up as a FOR loop, but I can't remember how to get it to stop and wait until the button is pressed again. Right now, it goes through the whole thing auomatically.

Comments

  • Couldn't you just do:
    BUTTON_EVENT[dvTP,1] // add an hour
    {
         PUSH:
         {
              nHours++
         }
    }
    
    BUTTON_EVENT[dvTP,2] // subtract an hour
    {
         PUSH:
         {
              nHours--
         }
    }
    
  • Yes, that would work if I was setting the time live. I was going to allow them to set the time and then have it update after they were done. That being the case, nHours and nMinutes really do not change until the new time takes effect. When I just do it that way, all it does it adds one or subtracts one from the current time and that is all. I think I am going to just let the time update live, then I could use that. Thanks for the reply.
  • AMXJeffAMXJeff Posts: 450
    Using Update Button.
    BUTTON_EVENT[dvTP,100] // Plus Hours
    {
    	PUSH:
    	{
    		// Guarantees 0-23
    		cHours = ((cHours + 1) &#37; 24);
    		SEND_COMMAND dvTP,"'^TXT-100,0,',FORMAT('%02d',cHours)"
    	}
    }
    
    
    BUTTON_EVENT[dvTP,101] // Min Hours
    {
    	PUSH:
    	{
    		// Guarantees 0-23
    		cHours = ((cHours + 11) % 24);
    		SEND_COMMAND dvTP,"'^TXT-100,0,',FORMAT('%02d',cHours)"
    	}
    }
    
    BUTTON_EVENT[dvTP,102] // Plus Mins
    {
    	PUSH:
    	{
    		// Guarantees 0-59
    		cMins = ((cMins + 1) % 60);
    		SEND_COMMAND dvTP,"'^TXT-102,0,',FORMAT('%02d',cMins)"
    	}
    }
    
    BUTTON_EVENT[dvTP,103] // Min Mins
    {
    	PUSH:
    	{
    		// Guarantees 0-59
    		cMins = ((cMins + 59) % 60);
    		SEND_COMMAND dvTP,"'^TXT-102,0,',FORMAT('%02d',cMins)"
    	}
    }
    
    BUTTON_EVENT[dvTP,104] // Update
    {
    	PUSH:
    	{
    		LOCAL_VAR CHAR cDateTime[100];
    		
    		cDateTime = "FORMAT('%02d',DATE_TO_MONTH(LDATE))";
    		cDateTime = "cDateTime,FORMAT('-%02d',DATE_TO_DAY(LDATE))";
    		cDateTime = "cDateTime,FORMAT('-%02d',(DATE_TO_YEAR(LDATE) % 100))";
    		cDateTime = "cDateTime,FORMAT(' %02d',cHours)";
    		cDateTime = "cDateTime,FORMAT(':%02d',cMins)";
    		cDateTime = "cDateTime,FORMAT(':%02d',0)";
    		
    		SEND_COMMAND 0,"'CLOCK ',cDateTime"
    	}
    }
    
  • AMXJeffAMXJeff Posts: 450

    nHours = ATOI(LEFT_STRING(TIME,2))
    nMinutes = ATOI(MID_STRING(TIME,4,2))

    // Better Way

    nHours = TIME_TO_HOUR(TIME);
    nMinutes = TIME_TO_MINUTE(TIME);
  • yuriyuri Posts: 861
    I think I am having a total brain dump or a nervous breakdown or something. I need to fetch a variable, and everytime the user presses a button, that number will increase by one. I am allowing them to set the clock via the touch panel. When they enter the clock settings screen, the current time is displayed. I am capturing that like so:
    nHours = ATOI(LEFT_STRING(TIME,2))
    nMinutes = ATOI(MID_STRING(TIME,4,2))

    That works fine. What I need to now do is allow them to push the hour up or down button and have it increment or decrement the hour by one each button press. After they are done setting the clock, I was going to send the new variables (nHours and nMinutes) to the NetLinx as the new time using this format:

    SEND_COMMAND <DEV>,"'CLOCK <mm-dd-yy> <hh:mm:ss>'"

    A simple up counter should only take like 5 minutes to write. Maybe I am just tired. I currently have it set up as a FOR loop, but I can't remember how to get it to stop and wait until the button is pressed again. Right now, it goes through the whole thing auomatically.

    even better, when using a G4 panel, just copy the buttons from the setup page, and you are done in < 1 minute :p
  • AMXJeffAMXJeff Posts: 450
    yuri wrote: »
    even better, when using a G4 panel, just copy the buttons from the setup page, and you are done in < 1 minute :p


    You get an A++++++++++++++++++
  • yuriyuri Posts: 861
    AMXJeff wrote: »
    You get an A++++++++++++++++++


    i always do :p
Sign In or Register to comment.