Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- # Use for PWM on /dev/bone/pwm/
- from pathlib import Path
- #from NewMotor_TB6600 import Pwm # see https://pastebin.com/R70P1wAn
- from time import sleep
- import gpiod
- # import os
- import sys
- pwmPeriod = '500000'
- PWMPATH1 = '/dev/bone/pwm/1/a'
- PWMPATH2 = '/dev/bone/pwm/1/b'
- CHIP1 = 'gpiochip1'
- LINE_OUT = [28]
- CHIP0 = 'gpiochip0'
- LINE_IN = [26]
- chip1 = gpiod.Chip(CHIP1)
- chip0 = gpiod.Chip(CHIP0)
- lineOUT = chip1.get_lines(LINE_OUT)
- lineOUT.request(consumer=' ', type=gpiod.LINE_REQ_DIR_OUT)
- lineIN = chip0.get_lines(LINE_IN)
- lineIN.request(consumer=' ', type=gpiod.LINE_REQ_EV_RISING_EDGE)
- #pwm1aPeriod = Path('/dev/bone/pwm/1/a/')
- #pwm1aDuty_Cycle = Path('/dev/bone/pwm/1/a/duty_cycle')
- #pwm1aEnable = Path('/dev/bone/pwm/1/a/enable')
- #pwm1bPeriod = Path('/dev/bone/pwm/1/b/period')
- #pwm1bDuty_Cycle = Path('/dev/bone/pwm/1/a/duty_cycle')
- #pwm1bEnable = Path('/dev/bone/pwm/1/a/enable')
- f = open(PWMPATH1+'/period', 'w')
- f.write(pwmPeriod)
- #f.close()
- f = open(PWMPATH1+'/enable', 'w')
- f.write('0')
- #f.close()
- f = open(PWMPATH2+'/period', 'w')
- f.write(pwmPeriod)
- #f.close()
- f = open(PWMPATH2+'/enable', 'w')
- f.write('0')
- #f.close()
- duty_cycle = 10000
- f = open(PWMPATH1+'/duty_cycle', 'w')
- f = open(PWMPATH2+'/duty_cycle', 'w')
- try:
- while True:
- port = int(input("Please type 0 or 1 : "))
- if lineIN == 0:
- f = open(PWMPATH1+'/enable', 'rw')
- f.write('0')
- f = open(PWMPATH2+'/enable', 'rw')
- f.write('0')
- sleep(0.5)
- lineOUT.set_values([0])
- elif lineIN == 1:
- f = open(PWMPATH1+'/enable', 'rw')
- f.write('0')
- f = open(PWMPATH2+'/enable', 'rw')
- f.write('0')
- sleep(0.5)
- lineOut.set_values([0])
- elif port == 0:
- lineOUT.set_values([1])
- f = open(PWMPATH1+'/duty_cycle', 'w')
- f = open(PWMPATH1+'/enable', 'w')
- f.write('1')
- sleep(2.5)
- f.write('0')
- elif port == 1:
- lineOUT.set_values([1])
- f = open(PWMPATH2+'/duty_cycle', 'w')
- f = open(PWMPATH2+'/enable', 'w')
- f.write('1')
- sleep(2.5)
- f.write('0')
- except KeyboardInterrupt:
- f = open(PWMPATH1+'/enable', 'w')
- f.write('0')
- f.close()
- f = open(PWMPATH2+'/enable', 'w')
- f.write('0')
- f.close()
- print("Kosher Salt!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement