I have a simple problem but i don't can solve.
If pwr >= 255 always go to 0 and no to 255.Why happen this?Code:pwr var byte
If up = 1 Then
PAUSE 50
pwr = pwr + 1
If pwr >= 255 Then pwr = 255
Endif
Printable View
I have a simple problem but i don't can solve.
If pwr >= 255 always go to 0 and no to 255.Why happen this?Code:pwr var byte
If up = 1 Then
PAUSE 50
pwr = pwr + 1
If pwr >= 255 Then pwr = 255
Endif
Since a byte can count up to 255 max when you add 1 to 255 the byte overflow and start from zero again (it cannot be 256).Quote:
If pwr >= 255 always go to 0 and no to 255.Why happen this?
If you want to keep your variable pwr at 255 then you can skip the add command, or you must use a word variable.
Code:pwr var byte
If up = 1 Then
PAUSE 50
If pwr = 255 Then Skip00
pwr = pwr + 1
Skip00:
Endif
Al.
Thank you. It is work.
I don't want use word variable , because pwr is for duty of HPWM.
Hi, Savnlik
You just can use :
or ...Code:
For I = 1 to 255
PAUSE 50
HPWM 1,I,1000 ' The reason of your loop ( BTW ...). 1000 is pwm freq.
NEXT I
Code:
DO
I = I + 1
....
While I < 255
For limiting Numbers:
AlainCode:
I = J MIN 255 ' I is the smaller ( MIN ) number between J and 255 ...
Or,Code:If Pwr > 254 then pwr = 255
Ouch, yes of course... my mistake, sorry.Quote:
I had test and not work.Because next have count 255 + 1 = 256