def init(): GPIO.setmode(GPIO.BCM) GPIO.SETUP(22, gpio.IN) #input pour le pull a la pin 22 #SPI setup CLK = 40 MISO = 35 MOSI = 38 CS = 36 spi.open(1,2) #bus 1 device 0 spi.max_speed_hz = 7629
from firebase import firebase import time import threading from time import sleep import RPi.GPIO as GPIO FBConn = firebase.FirebaseApplication('https://medcare-c3184.firebaseio.com/', None) GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.SETUP(21, GPIO.IN, pull_up_down=GPIO.PUD_UP) buzzer = 23 GPIO.setup(buzzer, GPIO.OUT) previous = "null" while True: state = GPIO.input(21) print(state) if state == 0 and previous == "open" or state == 0 and previous == "null": pill = str("bad") data_to_upload = {'pillTaken': pill} result = FBConn.patch('/Update', data_to_upload) previous = "closed" GPIO.output(buzzer, GPIO.LOW)
#led pinout test import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) import time pins=[17,18,27,22] for i,pin in enumerate(pins): GPIO.SETUP(pin,GPIO.OUT) for j in range(i+1): GPIO.output(pin,1) time.sleep(0.5) GPIO.OUTPUT(pin,0) time.sleep(0.5) GPIO.cleanup()
# Servo Control import time import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.SETUP(32, GPIO.OUT) try: while True: GPIO.output(32, 1) time.sleep(0.0015) GPIO.output(7, 0) time.sleep(2) except KeyboardInterrupt: GPIO.cleanup
import os import glob import time import RPi.GPIO as GPIO from bluetooth import * os.system('modprobe w1-gpio') os.system('modprobe w1-therm') GPIO.setmode(GPIO.BCM) GPIO.SETUP(17, GPIO.OUT) base_dir = '/sys/bus/w1/devices/' device_folder = glob.glob(base_dir + '28*')[0] device_file = device_folder + '/w1_slave' def read_temp_raw(): f = open(device_file, 'r') lines = f.readlines() f.close() return lines def read_temp(): lines = read_temp_raw() while lines[0].strip()[-3:] != 'YES': time.sleep(0.2) lines = read_temp_raw() equals_pos = lines[1].find('t=') if equals_pos != -1:
#!/usr/bin/env python import RPi.GPIO as GPIO import time LedPin = 11 # Pin 11 GPIO.setmode(GPIO.BOARD) GPIO.SETUP(LedPin, GPIO.OUT) GPIO.output(LedPin, GPIO.HIGH) try: while True: print '...led on' GPIO.output(LedPin, GPIO.LOW) time.sleep(0.5) print '...led off' GPIO.output(LedPin, GPIO.HIGH) time.sleep(0.5) except KeybaordInterrupt: GPIO.output(LedPin, High) GPIO.cleanup()
def button_callback(channel): global light_on if light_on == False: GPIO.output(led_pin, 1) print("LED ON!") light_on = True else: GPIO.output(led_pin, 0) print("LED OFF!") light_on = False GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) button_pin = 15 led_pin = 4 light_on = False GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.SETUP(led_pin, GPIO.OUT) GPIO.add_event_detect(button_pin, GPIO.RISING, callback=button_callback, bouncetime=300) while 1: time.sleep(0.1)