def __init__(self, master): frame = Frame(master) frame.pack() scale = Scale(frame, from_=0, to=180, orient=HORIZONTAL, command=self.update) scale.grid(row=0) GPIO.setmode(GPIO.BCM) self.servo = Servo() self.servo.attach(18)
servopin = 23 dir = 1 #debounce touch DEBOUNCE_DELAY = 0.05 btnState = 0 rawBtnIn = 0 prevBtnIn = 0 lastDebounceTime = 0 GPIO.setmode(GPIO.BCM) touch = TouchSensor() touch.attach(touchpin) servo = Servo() servo.attach(servopin) angle = 130 print(angle) servo.write(angle) def buttonPressed(): global dir global angle if (dir == 0): # left if (angle < 10): angle = 0 dir = 1 else:
import RPi.GPIO as GPIO from IEILab.GroveStarterKit import Servo from time import sleep try: GPIO.setmode(GPIO.BCM) s = Servo() s.attach(18) # PCM_CLK pin in BCM mode for angle in range(0, 181, 10): s.write(angle) print s.read() sleep(1) except ValueError as e: print 'Error: ', e except KeyboardInterrupt: pass finally: GPIO.cleanup()
from time import sleep import RPi.GPIO as GPIO from IEILab.GroveStarterKit import Servo from IEILab.GroveStarterKit import Touchsensor GPIO.setmode(GPIO.BCM) # touch in 18 # servo in 16 #2 4 6 8 10 12 14 16 18 #1 3 5 7 9 11 13 15 17 touchpin=18 servo = Servo() servo.attach(16) touch = TouchSensor() touch.attach(touchpin) loc=rand()%181 servo.write(loc) state=0 while True: if touch.isTouched() if state ==0 loc+=20 servo.write(loc) sleep(0.2) if loc>=180 state=1
import RPi.GPIO as GPIO from IEILab.GroveStarterKit import Servo from time import sleep GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) s = Servo() s.attach(18) # PCM_CLK pin in BCM mode s.write(0) sleep(1) s.write(180) sleep(1)