pwmout value


Ok I am really confused with PWMOUT.

I have an 18X setup and have an LED on output 3.

I have serial in working and it can chat to the computer fine via terminal. I want to be able to change the brightness of the LED via PWM.

So, I have:
serin 2, N4800, b10

That'll give me a value between 0-9 which I'll send.

I then have:
if b10="0" then backlightoff
which means if I send 0 it will go to a sub that sends pwmout 3,0,0 to turn it off.

I then need to know what to put next. What sums to turn 1-9 into the correct PWM values to get me something like 10-100%. It doesn't need to be exact, just about right.

So I want to know what sums I need to do to create the two values needed for the pwmout:
pwmout 3, ?, ?



Technical Support
Staff member
'PWMOUT pin, period, duty' - period is how fast the output gets updated, duty is how long during that period the output is on for.

The period can probably be arbitrary to start with, 0..255, so may as well use 255, the longest period.

Duty runs 0..1023 ( off to full ), so the following should work ...

- SERIN ...,b0 ' b0 <= "0","1","2".."9"
- b0 = b0-"0" ' b0 <= an actual number 0..9
- w0 = b0*1023/9
- PWMOUT 3,255,w0