Is there a way to have PWM use 255 instead of 65025 (via duty_u16).
I feel like I'm missing something for using RGB led's, despite searching.
Sorry if this is a dumb question but I cant work it out or find the answer.
PWM limited to 255
Re: PWM limited to 255
You can left shift the value in order to switch from 8 to 16 bits.
Say you have 0 ≤ value ≤ 255
if you make
value = value << 8
You will have 0 ≤ value ≤ 65280
Maybe you can elaborate on what your problem really is.
Say you have 0 ≤ value ≤ 255
if you make
value = value << 8
You will have 0 ≤ value ≤ 65280
Maybe you can elaborate on what your problem really is.
-
- Posts: 51
- Joined: Thu Dec 27, 2018 11:38 pm
- Location: Québec, Canada
Re: PWM limited to 255
Create your own classYou can left shift the value in order to switch from 8 to 16 bits.
Code: Select all
from machine import PWM
class PWM8(PWM):
def duty(self,value=None):
if value is None:
return self.duty_u16() >> 8
if value > 254:
self.duty_u16(0xfffe)
else:
self.duty_u16((value << 8) | value)
if __name__ == "__main__":
from machine import Pin
from PWM8 import PWM8
pwm = PWM8(Pin(10))
pwm.duty(128)
print("current duty is ",pwm.duty())
Re: PWM limited to 255
That's great, thank you both for taking the time to answer.