def set_PWM(self, percent, ntries=15):
        '''
        '''
        count = 0
        success = False
        if percent < 0.:
            percent = 0.
        if percent > 100.:
            percent = 100.
        while not success and count <= ntries:
            if self.logger:
                self.logger.info('Setting PWM value to {:.1f} %'.format(percent))
            send_digital = int(1023. * float(percent) / 100.)
            send_string = 'P{:04d}!'.format(send_digital)
            result = self.query(send_string)
            count += 1
            if result:
                self.PWM = float(result[0]) * 100. / 1023.
                if abs(self.PWM - percent) > 5.0:
                    if self.logger:
                        self.logger.warning('  Failed to set PWM value!')
                    time.sleep(2)
                else:
                    success = True
                if self.logger:
                    self.logger.info('  PWM Value = {:.1f}'.format(self.PWM))
dataset/ETHPy150Open panoptes/POCS/scripts/read_weather.py/AAGCloudSensor.set_PWM/original