def shopOpened(): GPIO.output(GREEN_LED, True) GPIO.out(RED_LED, False) While True: if (detectSomething()): p.ChangeDutyCycle(7.5) # turn towards 90 degree else: p.ChangeDutyCycle(2.5) # turn towards 90 degree
def Gpio_Intent(status): if status in STATUSON: #Controlling GPIO GPIO.out(17, GPIO.HIGH) return statement('opening {}'.format(status)) elif status in STATUSOFF: #Controlling GPIO GPIO.out(17, GPIO.LOW) return statement('closing {}'.format(status)) return statement('not sure')
def enable ( randomdelay = 5): set_delay = randomdelay if randomdelay < 90 else 90 # limitamos a 90 segundos if (set_delay > 0): sleep(randint(1,randomdelay)) gpio.setwarnings(False) gpio.setmode(gpio.BCM) gpio.setup(GPIO_RELAY_PIN,gpio.OUT) gpio.out(GPIO_RELAY_PIN,gpio.HIGH)
def pulse(self, number_of_pulses): """Function that sends a number of pulses to the Arduino to make the desired move""" delay = number_of_pulses/2500 for i in range(number_of_pulses): GPIO.output(self.channel_out, GPIO.HIGH) time.sleep(delay) GPIO.out(self.channel_out, GPIO.LOW) time.sleep(delay) # Pause until arduino sends message signaling it has completed move while GPIO.input(self.channel_in) == GPIO.LOW: time.sleep(0.1)
def switchBeam(action): global beam if action == beam: print "Lightstate is already correct" elif (beam == False): #This is the method that turns on the highBeam beam = True GPIO.out(lys, True) #Call the method made by Bortne that turns on the lights through RPI print('Lights turned on') else: GPIO.out(lys, False) #Call the method made by Bortne that turns off the lights through RPI print('Lights turned off') beam = False
def switchBeam(action): global beam if action == beam: print"Lightstate is already correct" elif (beam == False): #This is the method that turns on the highBeam beam = True GPIO.out(lys, True) #Call the method made by Bortne that turns on the lights through RPI print('Lights turned on') else: GPIO.out(lys, False) #Call the method made by Bortne that turns off the lights through RPI print('Lights turned off') beam = False
def active(null): GPIO.out(led, GPIO.HIGH)
def shopClosed(): GPIO.output(GREEN_LED, False) GPIO.out(RED_LED, True)
import time GPIO.setmode(GPIO.BOARD) GPIO.setwarnings(False) sleeptime = 0.001 leds = [] led1 = {'num':11,'current':0.0,'freq':15,'duration':50,'state':0} leds.append(led1) led2 = {'num':7,'current':0.0,'freq':75,'duration':30,'state':0} leds.append(led2) led3 = {'num':15,'current':0.0,'freq':44,'duration':20,'state':0} leds.append(led3) for led in leds: GPIO.setup(led['num'], GPIO.OUT) GPIO.output(led['num'], False) print(led) while True: for led in leds: led['current'] += sleeptime if(led['current'] >= led['freq']): if(led['state'] == 0): led['state'] = 1 GPIO.output(led['num'], True) led['current'] = 0 if(led['current'] >= led['duration']): if(led['state'] == 1): led['state'] = 0 GPIO.output(led['num'], False) led['current'] = 0 for led in leds: GPIO.out(led['num'], False)
loopTimeStart = time.time() batteryloop += 1 saveLoop+= 1 timeStep+= 1 check = time.time() checkTime = check - startTime # #end programm emerge(angle, stepCounter) digitalWrite(motorSleep_Pin, LOW) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// # //if selected, the motor is driven to neutral position if (MotorReset == 1): GPIO.out(SLEEP, 1) motorResetPosition(alpha_max / 2, angle, stepCounter) print("Motor position reset" ); GPIO.out(SLEEP, 0); if (MotorPosition == 1) : GPIO.out(SLEEP,1) alpha = alphaDesired print("alpha read = ") print(alpha + ) time.sleep(1) loopTimeStart = time.time() while (abs(angle - alpha) > 0.08): angle = step(alpha, angle, stepCounter) loopTimeStart = time.time() GPIO.output(SLEEP, LOW)
BUZZ = 18 GPIO.setmode(GPIO.BCM) GPIO.setup(BUZZ, GPIO.OUT) GPIO.output(BUZZ, GPIO.LOW) GPIO.setup(LED, GPIO.OUT) GPIO.output(LED, GPIO.LOW) GPIO.setup(LDR, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) try: while True: if GPIO.input(LDR) == GPIO.HIGH: print("light up") i = 2 while i > 0: GPIO.out(BUZZ, GPIO.HIGH) time.sleep(0.5) i-=1 GPIO.output(LED, GPIO.HIGH) else: print("light down") GPIO.output(BUZZ, GPIO.LOW) GPIO.output(LED, GPIO.LOW) time.sleep(1) except KeyboardInterrupt: GPIO.cleanup()
def disable(): gpio.setwarnings(False) gpio.setmode(gpio.BCM) gpio.setup(GPIO_RELAY_PIN,gpio.OUT) gpio.out(GPIO_RELAY_PIN,gpio.LOW)
#!/usr/bin/env python import RPi.GPIO as GPIO import time GreenPin = 11 RedPin = 13 GPIO.setmode(GPIO.BOARD) GPIO.setup(GreenPin, GPIO.OUT) GPIO.setup(RedPin, GPIO.OUT) GPIO.output(GreenPin, GPIO.HIGH) GPIO.output(RedPin, GPIO.HIGH) try: while True: print '... led on' GPIO.output(GreenPin, GPIO.HIGH) GPIO.output(RedPin, GPIO.LOW) time.sleep(0.5) print 'led off ...' GPIO.output(GreenPin, GPIO.LOW) GPIO.output(RedPin, GPIO.HIGH) time.sleep(0.5) except KeyboardInterrupt: GPIO.out(RedPin, GPIO.HIGH) GPIO.cleanup();
gpio.setup(18, gpio.OUT) # Connect a client socket client_socket = socket.socket() connected = False while not connected: try: client_socket.connect(('192.168.4.1', 9696)) connected = True print("Connected!") break except Exception as e: print("Failed to connect: " + format(e) + " retrying...") time.sleep(1) pass # listen for incoming data socket.listen(1) conn, addr = socket.accept() while True: data = conn.recv(BUFFER) print("Received: ", data) if data == 1: gpio.out(22, 1) time.sleep(2) # provide a time delay to prevent switching too fast elif data == 0: gpio.out(22, 0) time.sleep(2) # provide a time delay to prevent switching too fast
camera.start_preview() time.sleep(2) stream = io.BytesIO() for foo in camera.capture_continuous(stream, 'jpeg'): # Write the length of the capture to the stream and flush to # ensure it actually gets sent connection.write(struct.pack('<L', stream.tell())) connection.flush() # Rewind the stream and send the image data stream.seek(0) connection.write(stream.read()) # Reset the stream for the next capture stream.seek(0) stream.truncate() # check the data being received from the base data = socket.recv(BUFFER) print("Received: ", data) if data == 1: gpio.out(GUN_CONTROL_PIN, 1) elif data == 0: gpio.out(GUN_CONTROL_PIN, 0) # Write a length of zero to the stream to signal we're done connection.write(struct.pack('<L', 0)) finally: connection.close() socket.close()