scale a PWM value
347364
def scale_rc(self, servo, min, max, param):
        ''''''
        # default to servo range of 1000 to 2000
        min_pwm  = self.get_mav_param('%s_MIN'  % param, 0)
        max_pwm  = self.get_mav_param('%s_MAX'  % param, 0)
        if min_pwm == 0 or max_pwm == 0:
            return 0
        if max_pwm == min_pwm:
            p = 0.0
        else:
            p = (servo-min_pwm) / float(max_pwm-min_pwm)
        v = min + p*(max-min)
        if v < min:
            v = min
        if v > max:
            v = max
        return v
1072160
def step(self):
        """"""
        if self.cancelled or self.finished:
            return

        if not self.pwm_stages:
            self._finish()
            return

        if self.duration == 0:
            progress = 1
        else:
            run_time = time.time() - self._start_time
            progress = max(0, min(1, run_time / self.duration))
        self.stage_index = math.ceil((len(self.pwm_stages) - 1) * progress)
        stage = self.pwm_stages[self.stage_index]
        self._driver.set_pwm(stage)

        if progress == 1:
            self._finish()
558500
def _to_raw_pwm(self, values):
        
        return [self._to_single_raw_pwm(values[i])
                for i in range(len(self._pins))]
1252740
def _get_pwm_values(self, brightness=None, color=None):
        
        if brightness is None:
            brightness = self.brightness
        if color is None:
            color = self.color

        return [(x / 255) * brightness for x in self._rgb_to_rgbw(color)]
758414
def adc_to_percentage(value, max_volts, clamp=True):
    
    percentage = (100.0 / const.ADC_MAX_VAL) * value
    return max(min(100, percentage), 0) if clamp else percentage
939654
private static void scaleDownTenRoundUp(Slice decimal, int tenScale, Slice result)
    {
        boolean round;
        do {
            int powerTen = Math.min(tenScale, MAX_POWER_OF_TEN_INT);
            tenScale -= powerTen;

            int divisor = POWERS_OF_TEN_INT[powerTen];
            round = divideCheckRound(decimal, divisor, result);
            decimal = result;
        }
        while (tenScale > 0);

        if (round) {
            incrementUnsafe(decimal);
        }
    }
992396
def Y_ampl(self, new_y_scale):
        """"""
        self.parent.value('y_scale', new_y_scale)
        self.parent.traces.display()
353257
def controler_output(self, current_value):
        

        set_point = self.settings['set_point']
        Kp = self.settings['gains']['proportional']
        Ki = self.settings['gains']['integral']
        output_range = self.settings['output_range']
        time_step = self.settings['time_step']

        error_new = set_point - current_value
        print(('PD- error:\t', error_new, Ki, Kp, time_step))
        #proportional action
        self.u_P = Kp * error_new * time_step
        print(('PD- self.u_P:\t', self.u_P, self.u_I))

        #integral action
        self.u_I += Kp * Ki * (error_new + self.error) / 2.0 * time_step

        self.error = error_new

        print(('PD- self.u_P:\t', self.u_P, self.u_I))

        # anti-windup
        if self.u_P + self.u_I > output_range['max']:
            self.u_I = output_range['max']-self.u_P
        if self.u_P + self.u_I < output_range['min']:
            self.u_I = output_range['min']-self.u_P


        output = self.u_P + self.u_I
        print(('PD- output:\t', output))
        return output
989544
async def set_power(self, value: bool):
        """"""
        if value:
            status = "active"
        else:
            status = "off"
        # TODO WoL works when quickboot is not enabled
        return await self.services["system"]["setPowerStatus"](status=status)
95900
def _set_led_value(self, group, val):
        """"""
        new_bitmask = set_bit(self._value, group, bool(val))
        self._set_led_bitmask(new_bitmask)
304444
def set_power(self, sid, state):
    """"""
    sid_mask = 0x01 << (sid - 1)
    return self.set_power_mask(sid_mask, state)
729754
public void scale(float value) {
		r *= value;
		g *= value;
		b *= value;
		a *= value;
	}
196412
def set_pwm_frequency(self, value):
        
        self.__check_range('pwm_frequency', value)
        reg_val = self.calc_pre_scale(value)
        logger.debug("Calculated prescale value is %s" % reg_val)
        self.sleep()
        self.write(Registers.PRE_SCALE, reg_val)
        self.wake()
978021
def SADWindowSize(self, value):
        """"""
        if value >= 1 and value <= 11 and value % 2:
            self._sad_window_size = value
        else:
            raise InvalidSADWindowSizeError("SADWindowSize must be odd and "
                                            "between 1 and 11.")
        self._replace_bm()
1025017
def power_level(self, val):
        """"""
        if val in [0, 1, 2, 3]:
            self.pdx.PowerLevel = val
        elif type(val) is str:
            if val.lower() == "high":
                self.pdx.PowerLevel = 0
            elif val.lower() == "highlow":
                self.pdx.PowerLevel = 1
            elif val.lower() == "lowhigh":
                self.pdx.PowerLevel = 2
            elif val.lower() == "low":
                self.pdx.PowerLevel = 3
        else:
            raise ValueError("Not a valid power level")
1002531
def pin_6_pwm_128():
    
    # instantiate the pymata_core API
    board = PyMata3()

    # set the pin mode
    board.set_pin_mode(6, Constants.PWM)
    board.analog_write(6, 128)

    # wait for 3 seconds to see the LED lit
    board.sleep(3)

    # reset the board and exit
    board.shutdown()
394216
def scale_vote(self, value):
        ''' 
        '''
        value = int(value) * 100
        if value < 100:
            value = 100
        if value > 10000:
            value = 10000
        return value