Altering a variable in a loop.


Closed Thread
Results 1 to 27 of 27

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Altering a variable in a loop.

    Here's the basic principle of using the flag method:
    Code:
    UpButton VAR PortB.0   			' Active high button
    DnButton VAR PortB.1   			' Active high button
    
    Setting VAR BYTE
    SettingChanged VAR BIT
    DutyCycle VAR BYTE
    
    Main:
    
      If UpButton THEN
        Setting = Setting + 1              ' Increment setting
        If Setting = 6 THEN Setting = 5    ' Make sure it doesn't go beyond 5
        SettingChanged = 1                 ' Set flag indicating new setting
      EndIf
    
    
      If DnButton THEN
        Setting = Setting - 1
        If Setting = 255 THEN Setting = 0  ' Make sure it doesn't go below 0
        SettingChanged = 1                 ' Set flag indicating new setting
      EndIf
    
      If SettingChanged THEN
        LOOKUP Setting, [12,23,34,45,56], DutyCycle
        SettingChanged = 0                 ' Clear flag
      EndIf
    
    
      
      ' Your regulator code here...
      ' Your regulator code here...
      ' Your regulator code here...
    
    Goto Main
    /Henrik.

  2. #2
    Join Date
    Aug 2012
    Location
    Comodoro Rivadavia - Patagonia Argentina
    Posts
    51


    Did you find this post helpful? Yes | No

    Default Re: Altering a variable in a loop.

    very good your contribution! I find it very helpful to see the logic with other people who program to learn more every day... Thanks Henrik

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts