def init_servos(address): i2c_helper = ABEHelpers() bus = i2c_helper.get_smbus() pwm = PWM(bus, address) pwm.set_pwm_freq(60) pwm.output_enable() # cycle the arms on channels 0, 2, 4 print('cycling through all valid positions') for x in (175, 300, 425, 550): pwm.set_pwm(0, 0, x) sleep(1) pwm.set_pwm(2, 0, x) sleep(1) pwm.set_pwm(4, 0, x) sleep(2) return pwm
================================================ ABElectronics Servo Pi pwm controller | PWM output demo Version 1.0 18/11/2014 run with: sudo python demo-pwm.py ================================================ This demo shows how to set a 1KHz output frequency and change the pulse width between the minimum and maximum values """ # create an instance of the ABEHelpers class and use it # to find the correct i2c bus i2c_helper = ABEHelpers() bus = i2c_helper.get_smbus() # create an instance of the PWM class on i2c address 0x40 pwm = PWM(bus, 0x40) # Set PWM frequency to 1 Khz and enable the output pwm.set_pwm_freq(1000) pwm.output_enable() while (True): for x in range(1, 4095, 5): pwm.set_pwm(0, 0, x) #time.sleep(0.01) for x in range(4095, 1, -5): pwm.set_pwm(0, 0, x) #time.sleep(0.01)