Replicape / software /

#!/usr/bin/env python
A Mosfet class for setting the PWM of a power mosfet for Replicape. 

Author: Elias Bakken
License: BSD

You can use and change this, but keep this heading :)
import bbio as io

class Mosfet:

    def __init__(self, pin): = pin
        io.pwmEnable(pin) # Init the Pin to PWM mode
        io.pwmFrequency(pin, 20000) # Set a frequency, not important for now
    '''Set duty cycle between 0 and 1'''
    def setPower(self, value):
        self.power = value
        io.analogWrite(, int((1.0-value)*256.0))

    '''Set the PWM frequency'''
    def setFrequency(self, freq):
        io.pwmFrequency(, freq)

    ''' return the current power level '''
    def get_power(self):
        return self.power

    def close(self):
        io.pwmDisable( # Init the Pin to PWM mode