#!/usr/bin/python
#-*- encoding: utf-8 -*-
from periphery import PWM
import time
#Open PWM channel 0, pin 0
#Open /sys/class/pwm/pwmchip0/pwm0
pwm = PWM(0, 0)
#Select the period of PWM signal
#Write /sys/class/pwm/pwmchip0/pwm0/period
pwm.period = 0.02 # 20,000,000 nanoSec
#Change the polarity of the PWM signal
#Write /sys/class/pwm/pwmchip0/pwm0/polarity
pwm.polarity = "normal"
#Enable the PWM signal
#Write /sys/class/pwm/pwmchip0/pwm0/enable
pwm.enable()
#Select the duty cycle
#Write /sys/class/pwm/pwmchip0/pwm0/duty_cycle
#Move to Center
pwm.duty_cycle = 0.0725 # 0.0725 * 20,000,000 = 1,450,000
nanoSec
time.sleep(2)
#Move to Angle +90
pwm.duty_cycle = 0.1175 # 0.1175 * 20,000,000 = 2,350,000
nanoSec
time.sleep(2)
#Move to Angle -90
pwm.duty_cycle = 0.03125 # 0.03125 * 20,000,000 = 625,000
nanoSec
time.sleep(2)
#Move to Center
pwm.duty_cycle = 0.0725 # 0.0725 * 20,000,000 = 1,450,000
nanoSec
time.sleep(2)
#Not unexpoert
pwm.close()
|