Shop OBEX P1 Docs P2 Docs Learn Events
variable ramping — Parallax Forums

variable ramping

stilgarstilgar Posts: 47
edited 2012-12-07 18:37 in Propeller 1
Could someone explain bit by bit how to ramp a variable. I did a search but did not find any info to answer my question.

I am wanting to understand this line of code. I know what it does but don't understand how it does.

volume := ++volume <# 32

in the program the line slowly raises the volume variable on my wav player.
I am also interested in how to decrease the variable as well.

thanks,
stilgar

Comments

  • Mike GMike G Posts: 2,702
    edited 2012-12-06 13:22
    Increment volume until 32 is reached (limit maximum). Please see the Propeller manual page 155 for a detailed explanation of <#. Page 152 has information on pre/post increment (++).
    http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/Web-PropellerManual-v1.2.pdf
  • MagIO2MagIO2 Posts: 2,243
    edited 2012-12-06 14:03
    ++volume is called a pre increment. This means that the variable is incremented first and the result of the increment is used in the rest of the expression. You could translate this code into:

    volume := volume + 1
    volume := volume <# 32

    If you write volume++ in an expression, that's called a post increment. So, first the value of volume is read and used in the rest of the expression and then it is increased. This of course would not make sense in this expression.
  • stilgarstilgar Posts: 47
    edited 2012-12-06 14:57
    thanks for the info
    stilgar
  • JonnyMacJonnyMac Posts: 9,108
    edited 2012-12-06 14:57
    You can do the same thing with pre-decrement:

    volume := --volume #> 0
  • lardomlardom Posts: 1,659
    edited 2012-12-07 10:12
    I use a memory aid to remember the difference between the maximum limit '<#' and the minimum limit '#>' ; This '<' represents an eye looking right which = 'maximum'. This '#' represents the eyeball 'highlight'. So one 'highlighted eye' looks toward 'maximum' '<#' and the other toward 'minimum' '#>'.
    volume := ++volume <# 32
    

    Every time this line is executed 1 is added to the 'volume' variable up to a maximum of 32. I think it helps to learn to state a line of code in plain english.
  • cavelambcavelamb Posts: 720
    edited 2012-12-07 12:55
    However, we often find that ramping may need something more than ++1 increment.

    As in the following example.
    LED Throb - steps up and down by 2.

    { Throb.Spin }
    CON     
    _CLKMODE=XTAL2
    _XINFREQ =5_000_000
    MSec   = _XINFREQ / 1_000
    USec   = _XINFREQ / 1_000_000
    T500U = Usec * 500                                          
    T300M = Msec * 300                                  
    Tsteps= 50                       
    VAR
    Byte X, LED
    PUB  Throb
       LED := 23
      dira [LED] :=1
        Repeat                              
          ' going up
          Repeat X from 1 to Tsteps step 2   
             outa[LED] := 1                                     
             waitCNT ((X*T500U) +cnt)        
             outa[LED] := 0                                      
             waitCNT ((Tsteps-X+1)*T500U+cnt)
          outa[LED] := 1                      
          waitcnt(T300M +cnt)
    
          'going down
          Repeat X from 1 to Tsteps step 2          
             outa[LED] := 1    
             waitCNT ((Tsteps-X+1)*T500U+cnt)
             outa[LED] := 0                                         
             waitCNT ((X*T500U) +cnt)
          waitcnt (T300M*2 +cnt)      
    
    
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-12-07 18:37
    lardom wrote: »
    I use a memory aid to remember the difference between the maximum limit '<#' and the minimum limit '#>' ; This '<' represents an eye looking right which = 'maximum'. This '#' represents the eyeball 'highlight'. So one 'highlighted eye' looks toward 'maximum' '<#' and the other toward 'minimum' '#>'.

    I always think of the "> <" symbols as hungry mouths. They're always open to the larger item, and when used as a limit they also get to eat a number sign.
Sign In or Register to comment.