def sensor_if(): global sensor_infrared if GPIO.INPUT(infrared) == 1: sensor_infrared = True elif GPIO.INPUT(infrared) == 0: sensor_infrared = False else: print("infrared sensor error") pass
def readPIR(): global pirSensors, pirSensivity # this is a generally low intellignet system so if not isArmed: return False pir_activity = [GPIO.LOW]*len(pirSensors) for idx in range(len(pinSensors)): pir_activity[idx] = GPIO.INPUT(pirSensors[idx]['gpio']) if sum(pir_activity) >= pirSensivity: return True return False
def poll_keypad(self): pins_to_sym = { (18, 17): "1", (18, 27): "2", (18, 22): "3", (23, 17): "4", (23, 27): "5", (23, 22): "6", (24, 17): "7", (24, 27): "8", (24, 22): "9", (25, 17): "*", (25, 27): "0", (25, 22): "#" } # må legge inn sleep her for row in self.row_pin: GPIO.output(row, GPIO.HIGH) sleep(0.1) # wait to maybe let it turn on for colm in self.colm_pin: if (GPIO.INPUT(colm) == GPIO.HIGH): GPIO.ouput(row, GPIO.LOW) return pins_to_sym[(row, colm)] GPIO.ouptput(row, GPIO.LOW)
GPIO.setup(button_1, GPIO.IN) GPIO.setup(button_2, GPIO.IN) def download_file(): web_file = urllib2.urlopen(DUMMY_LINK) out_file = open('/pi/podcasts/', 'w') out_file.write(web_file.read()) out_file.close() if __name__ == '__main__': try: while True: # do main loop stuff button_1_input = GPIO.INPUT(button_1) button_2_input = GPIO.INPUT(button_2) if (button_1_input): print("%s" % button_1_input) button_1_last = last print("Button_1 pressed") if (GPIO.INPUT(button_2)): print("Button_2 pressed") time.sleep(0.001) # start button listening script from here? except KeyboardInterrupt: print("Measurement stopped by user") GPIO.cleanup()
from time import sleep import RPi.GPIO as GPIO SENSOR = 18 GPIO.setmode(GPIO.BCM) GPIO.setwarning = False GPIO.setup(SENSOR, GPIO.IN) while True: state = GPIO.INPUT(SENSOR) if state == False: print("gas deteected") else: print("gas not detected") sleep(0.5)
def UpDownTemp(): if GPIO.INPUT(19) == True: UpDown = +1 if GPIO.input(26) == True: UpDown = -1 return UpDown