def set_pwm_freq(self, freq_hz):
        """Set the PWM frequency to the provided value in hertz."""
        prescaleval = 25000000.0    # 25MHz
        prescaleval /= 4096.0       # 12-bit
        prescaleval /= float(freq_hz)
        prescaleval -= 1.0
        logger.debug('Setting PWM frequency to {0} Hz'.format(freq_hz))
        logger.debug('Estimated pre-scale: {0}'.format(prescaleval))
        prescale = int(math.floor(prescaleval + 0.5))
        logger.debug('Final pre-scale: {0}'.format(prescale))
        oldmode = self.i2c.read_U8(MODE1)
        newmode = (oldmode & 0x7F) | 0x10    # sleep
        self.i2c.write8(MODE1, newmode)  # go to sleep
        self.i2c.write8(PRESCALE, prescale)
        self.i2c.write8(MODE1, oldmode)
        time.sleep(0.005)
        self.i2c.write8(MODE1, oldmode | 0x80)
def set_pwm_freq ( self , freq_hz ) : prescaleval = 25000000.0 prescaleval /= 4096.0 prescaleval /= float ( freq_hz ) prescaleval -= 1.0 logger . debug ( 'Setting PWM frequency to {0} Hz' . format ( freq_hz ) ) logger . debug ( 'Estimated pre-scale: {0}' . format ( prescaleval ) ) prescale = int ( math . floor ( prescaleval + 0.5 ) ) logger . debug ( 'Final pre-scale: {0}' . format ( prescale ) ) oldmode = self . i2c . read_U8 ( MODE1 ) newmode = ( oldmode & 0x7F ) | 0x10 self . i2c . write8 ( MODE1 , newmode ) self . i2c . write8 ( PRESCALE , prescale ) self . i2c . write8 ( MODE1 , oldmode ) time . sleep ( 0.005 ) self . i2c . write8 ( MODE1 , oldmode | 0x80 )
Set the PWM frequency to the provided value in hertz.