Dimmer ramp to amount, integer versus % and/or how to concatenate them

Discussion in 'Pascal Logic Code Examples' started by Trevor, Jun 23, 2022.

  1. Trevor

    Trevor

    Joined:
    Nov 22, 2018
    Messages:
    298
    Likes Received:
    22
    Location:
    Melbourne Victoria
    Hi All,
    I have the code below as part of my testing setup, its used to turn on the selected gate address, using a dimmer to ramp up to selected level, wait then ramp down to selected level, for the selected amount of times.
    Mostly it works ok, but if i select 100 as the ramp up rate it will only get to 40%, I'm getting the value from a logic i/o linked to a slider to select from 0 to 100, so it puts 100 in there for the ramp rate, and will only get to 40% of maximum. If i manually put in 100% it will go to 100%.

    What i have been trying to figure out is how to add the % sign to the value so it see's it as a percentage and not a number. Has anyone out there delved into the logic engine at this level and tried something similar?
    As usual any help is appreciated.
    regards
    Trevor


    Code:
    Once GetLightingState(83) = On then
        begin
        clearscreen;
       Ramp_Up_To   := GetIntSystemIO("Ramp_To_Up"); 
       Ramp_Dn_To := GetIntSystemIO("Ramp_To_Dn");
        
        GA_Rate := GetIntSystemIO("GA Rate");
        GA_Delay := GetIntSystemIO("GA Delay");
        GA_Count := GetIntSystemIO("GA Count");
        GA_Address := GetIntSystemIO("Gate_Address");
     
     
         repeat
           GA_Count := GA_Count - 1;
           SetLightingLevel(GA_Address, Ramp_Up_To, GA_Rate);
           Delay(Ga_Delay + 5);
           SetLightingLevel(GA_Address, Ramp_Dn_To, GA_Rate);
           Delay(Ga_Delay + 5);
           clearscreen;
           TextPos(1695, 720);
           DrawText(GA_Count);
         until GA_Count < 1;   
       end;
     
    Trevor, Jun 23, 2022
    #1
  2. Trevor

    Trevor

    Joined:
    Nov 22, 2018
    Messages:
    298
    Likes Received:
    22
    Location:
    Melbourne Victoria
    H i Again,

    I just figured it out, i found this little ditty...

    PercentToLevel(ramp_level) and its value is converted to a percent for you.

    :)
     
    Trevor, Jun 23, 2022
    #2
    Mr Mark likes this.
  3. Trevor

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,524
    Likes Received:
    173
    Location:
    Adelaide, Australia
    Everything internally works in bytes (i.e. 0-255). The percentage option is just for us humans. When you enter a literal % in the logic engine, it automatically converts it to the corresponding byte for you when you compile the program (just like it converts tags to numbers). If you pass a variable as an argument to a cbus function, it will always be interpreted as a byte from 0 (off) to 255 (ON).

    Similarly, everything returned from a cbus function is a byte, so if you want a percentage you can call the corresponding LevelToPercent function.
     
    Ashley, Jun 23, 2022
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.