def ch_ctrl(ch): if ch = 1: GPIO.OUT(channel1, 0) channel1_state = True input(press enter to stop) GPIO.OUT(channel1, 1) channel1_state = False
def AlarmLightEnable(enable): global vibSensorAlarmLight if enable == False: GPIO.OUT(vibSensorAlarmLight, GPIO.LOW) elif enable == True: GPIO.OUT(vibSensorAlarmLight, GPIO.HIGH)
def SetAngle(Servo, angle): duty = angle / 18 + 2 GPIO.OUT(Servo, True) p = GPIO.PWM(Servo, 50) p.start(0) p.ChangeDutyCycle(duty) sleep(2) p.stop()
def play(): pressed = False while True: for i in range(len(switches)): while GPIO.input(switches[i]): val = i pressed = True GPIO.OUT(leds[i]) print("Yay")
def drive(direction, rspeed, lspeed): if direction > 0: GPIO.OUT(RIN1, 0) GPIO.output(RIN2, 1) GPIO.output(self.LIN1, 0) GPIO.output(LIN2, 1) else: GPIO.output(RIN1, 1) GPIO.output(RIN2, 0) GPIO.output(LIN1, 1) GPIO.output(LIN2, 0)
import RPi.GPIO as GPIO import time led = 3 GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(led, GPIO.OUT) GPIO.output(led, 0) BlinkTimes = input("How many times LED shoud Blink ? \n") OnTime = input("Enter LED on duration \n") OffTime = input("Enter LED off duration \n") print("LED will blink for ", BlinkTimes) for i in range(int(BlinkTimes)): GPIO.OUT(led, 1) time.sleep(int(OnTime)) GPIO.OUT(led, 0) time.sleep(int(OffTime)) print(str(i+1) + " times blinked")
for r in result: print r if r != None: print 'number plate found. Car can be parked.' GPIO.output(green1, 1) lcd.message('Car can be parked') time.sleep(2) lcd.clear() else: print 'number plate not found' GPIO.output(red1, 1) GPIO.output(buzzer1, 1) lcd.message('Car cannot be parked') time.sleep(2) lcd.clear() curs.close() db.close() GPIO.output(green1, 0) GPIO.output(red1, 0) GPIO.output(buzzer1, 0) #closing light if turned on for photo if GPIO.OUT(led): GPIO.output(led, 0) else: print 'out of range' j += 1
def ch_ON(ch): if ch = 1: GPIO.OUT(channel1, 0) channel1_state = True
else: print ("invalid argument for 'channel_state()' try 1,2, etc.") #user control on/off def ch_ctrl(ch): if ch = 1: GPIO.OUT(channel1, 0) channel1_state = True input(press enter to stop) GPIO.OUT(channel1, 1) channel1_state = False if ch = 2: GPIO.OUT(channel2, 0) channel2_state = True input(press enter to stop) GPIO.OUT(channel2, 1) channel2_state = False if ch = 3: GPIO.OUT(channel3, 0) channel3_state = True input(press enter to stop) GPIO.OUT(channel3, 1) channel3_state = False if ch = 4: GPIO.OUT(channel4, 0) channel4_state = True
for i in range(1, 10, 2) m1a.changedutycycle(10) #PWM_instance.start(duty_cycle) m1b.changedutycycle(0) m2a.changedutycycle(0) m2b.changedutycycle(5) stop() #GPIO.OUT(M1A, True) #GPIO.OUT(M1B, False) #GPIO.OUT(M2A, False) #GPIO.OUT(M2B, False) print('Run Robot:\n W: Forword\n S:Backward \n A:Left\n D:Right\n **Any other key to stop and exit**\n') while True: ch = getch() print(ch) if ch=='w'or ch=='W': forward() elif ch=='s'or ch=='S': backward() elif ch=='a'or ch=='A': left() elif ch=='d'or ch=='D': right() else stop() GPIO.OUT(M1A, False) GPIO.OUT(M1B, False) GPIO.OUT(M2A, False) GPIO.OUT(M2B, False) GPIO.cleanup() sys.exit()