def main():
    """
    Main program function
    """

    # create an instance of the PWM class on i2c address 0x40
    pwm = PWM(0x40)

    # Set PWM frequency to 1 Khz and enable the output
    pwm.set_pwm_freq(1000)
    pwm.output_enable()

    while True:
        for count in range(1, 4095, 5):
            pwm.set_pwm(1, 0, count)
        for count in range(4095, 1, -5):
            pwm.set_pwm(1, 0, count)
Exemplo n.º 2
0
def main():
    """
    Main program function
    """

    # create an instance of the PWM class on i2c address 0x40
    pwm = PWM(0x40)

    # Set PWM frequency to 1 Khz and enable the output
    pwm.set_pwm_freq(1000)
    pwm.output_enable()

    while True:
        for count in range(1, 4095, 5):
            pwm.set_pwm(1, 0, count)
        for count in range(4095, 1, -5):
            pwm.set_pwm(1, 0, count)
Exemplo n.º 3
0
class servoDriver(object):
    servoFrequencyValue = 50
    PWMFrequencyValue = 200

    def __init__(self):
        #creating objects for the PWM and Motor
        self.pwm = pulseWidthModulation()
        self.ServoMotor = motor()

    def pulseWidthModulation(self):
        #Pulse Width Modulation(PWM) instatiation
        self.pwm = PWM(0x40)
        #Sets the PWM to a frequency of 200 Hz
        self.pwm.set_pwm_freq(self.PWMFrequencyValue)
        #Allow the output to be displayed
        self.pwm.output_enable()
        #Setting the channel for data stream to 1, time period to 1024 out of 4095.
        self.pwm.set_pwm(1, 0, 1024)

    def motor(self):
        #Instantiation of the servo object
        self.servo = Servo(0x40)
        #setting frequency for the PWM to interact with the PWM object
        self.servo.set_frequency(self.frequencyValuse)
        #setting the servo to move
        self.servo.move(1, 125, 250)

    def set_PWM_frequency(self, value):
        self.PWMFrequencyValue = value
        self.pwm.set_pwm_freq(self.PWMFrequencyValue)

    def get_PWM_frequency(self):
        return self.PWMFrequencyValue

    def set_servo_frequency(self, value):
        self.servoFrequencyValue = value
        self.servo.set_frequency(self.servoFrequencyValue)

    def get_servo_frequency(self):
        return self.servoFrequencyValue
Exemplo n.º 4
0
bus.invert_pin(15, 1)
bus.invert_pin(14, 0)
count = 0
dc = 0
while True:
    if bus.read_pin(14) == 1:
        count += 1
        print('\n\nbutton checked ' + str(count) + ' time')
        for i in range(1, 6):
            bus.write_pin(i, 1)
            #sleep(0.1)
        print('Read relais 1=' + str(bus.read_pin(16)) + '\nRead relais 2=' +
              str(bus.read_pin(15)))
        dc = 0
        #sleep(0.5)
    else:
        print('\n\nbutton pressed ')
        print('Volt1=' + str(adcdac.read_adc_voltage(1, 0)) + 'Volt2=' +
              str(adcdac.read_adc_voltage(2, 0)) + 'ciao ' + str(dc))
        if dc >= 4095:
            dc = 0
        else:
            for i in range(1, 4):
                pwm.set_pwm(i, dc, 0)
        for i in range(1, 6):
            bus.write_pin(i, 0)
        print('Read relais 1=' + str(bus.read_pin(16)) + '\nRead relais 2=' +
              str(bus.read_pin(15)))
        dc += 10
        #sleep(0.1)
Exemplo n.º 5
0
from ServoPi import PWM
pwm = PWM(0x41)
pwm.set_pwm_freq(1000)
##output_enable()
pwm.set_pwm(1, 0, 110)
Exemplo n.º 6
0
bus.write_pin(10, 0)
bus.write_pin(10, 1)

bus.write_pin(10, 0)
bus.set_pin_pullup(8, 1)
bus.set_pin_pullup(9, 1)
bus.invert_pin(9, 0)
bus.invert_pin(8, 0)
count = 0
dc = 0
while True:
    if bus.read_pin(7) == 1:
        count += 1
        print('button checked ' + str(count) + ' time')
        for i in range(9, 13):
            bus.write_pin(i, 1)
            sleep(0.1)
        bus.write_pin(16, 1)
        dc = 0
        sleep(0.5)
    else:
        print('button pressed ')
        print('Volt1=' + str(adcdac.read_adc_voltage(1, 0)) + 'Volt2=' +
              str(adcdac.read_adc_voltage(2, 0)) + 'ciao ' + str(dc))
        pwm.set_pwm(1, 4095 - dc, dc)
        for i in range(9, 13):
            bus.write_pin(i, 0)
        bus.write_pin(16, 0)
        dc += 10
        sleep(0.1)