problem with a variable
Hello I am having trouble. I am working on a program block (please note, this is only a small bit in a larger program) that uses the led_pwm.spin.
What I am trying to do is get the variable "maxbright" to start at 0 and increment to 64 and stop. after this block is completed "maxbright" will remain at 64 for all the rest of code that follows.
everything I have tried don't work at all or don't compile.
thanks
What I am trying to do is get the variable "maxbright" to start at 0 and increment to 64 and stop. after this block is completed "maxbright" will remain at 64 for all the rest of code that follows.
everything I have tried don't work at all or don't compile.
thanks


Comments
If you use a variable (I used "result") you can change its value from zero to maxbright like this.
repeat result from 0 to maxbright repeat x from 7 to _numleds-8 leds[x] := result waitcnt(clkfreq / (rtime1)+ cnt) ' center LEDs slowly go from 0 to maxbright 64This will only change the values of leds[7] and leds[8] though.
This will delay after each element of the two "leds" elements are set. If you want to delay after both elements are set you'd want to change the indentation on the waitcnt to this.
repeat result from 0 to maxbright repeat x from 7 to _numleds-8 leds[x] := result waitcnt(clkfreq / (rtime1)+ cnt) ' center LEDs slowly go from 0 to maxbright 64If you explain in more detail what you want to do, I (or others) may be able to help more.
con _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 MAX_BRIGTH = 64 MS_DELAY = 100 VAR byte luminosity byte isMaxBright OBJ pst : "Parallax Serial Terminal" PUB Main pst.Start(57600) pause(500) luminosity~ isMaxBright := false repeat repeat MAX_BRIGTH ifnot(isMaxBright) luminosity := (++luminosity) // 65 pst.dec(luminosity) pst.char(13) pause(MS_DELAY) if(luminosity == MAX_BRIGTH) isMaxBright := true PRI pause(ms) waitcnt(((clkfreq / 1_000 * ms - 3932) #> 381) + cnt) returnYes that whats I am trying to do. Many thanks to Duane Degn for the code it works great.
Now a new problem I need to fix is when the LEDs fad on, they seem to flicker. I think its a timing issue, but not sure.
I have attached all the program code I have done so far. The methood called "Death" , is not finished yet. this block is to slow the sweep speed to stop then fade the LEDs off.
In led_pwm_1.spin to:
You should get less flicker.
You might want to try several different values for "delay" to see what looks best.