lilzz
Posts: 411
Joined: Sat Nov 30, 2013 5:27 pm

The following python code

Sat Jan 04, 2014 9:05 pm

Code: Select all

1)
 def __pwmRead__(self, channel):
        addr = self.getChannelAddress(channel)
        d = self.readRegisters(addr, 4)
        start = d[1] << 8 | d[0]
        end   = d[3] << 8 | d[2]
        return end-start
    
2)
    def __pwmWrite__(self, channel, value):
        addr = self.getChannelAddress(channel)
        d = bytearray(4)
        d[0] = 0
        d[1] = 0
        d[2] = (value & 0x0FF)
        d[3] = (value & 0xF00) >> 8
        self.writeRegisters(addr, d)
How the above bit manipulation goes?

Return to “Python”