def __init__(self, pin, in_out=OUTPUT, mode=BOOLEAN, initial=LOW, frequency=0): self.pin = pin self.in_out = in_out # if changing set initial state self.mode = mode if mode == BOOLEAN: GPIO.setup(pin, in_out, initial) elif mode == PWM: GPIO.PWM(pin, frequency)
def main(): """ Runs the main file :return: None """ cred = credentials.Certificate("firebase_SDK.json") firebase_admin.initialize_app( cred, { "databaseURL": "https://weblights-513e2.firebaseio.com/", 'databaseAuthVariableOverride': { 'uid': 'my-service-worker' } }) GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) pins = {"green": 22, "red": 17, "yellow": 27} request_numbers = 0 while true: print("Making request", request_numbers + 1) ref = db.reference("lights").get() request_numbers += 1 if ref["green"]: GPIO.output(pins["green"], GPIO.HIGH) else: GPIO.output(pins["green"], GPIO.LOW) if ref["red"]: GPIO.output(pins["red"], GPIO.HIGH) else: GPIO.output(pins["red"], GPIO.LOW) if ref["yellow"]: GPIO.output(pins["yellow"], GPIO.HIGH) else: GPIO.output(pins["yellow"], GPIO.LOW) sleep(0.5)
def init_heater(): GPIO.cleanup() GPIO.setmode(GPIO.BOARD) GPIO.setup(11, GPIO.OUT) return
class WaitForUserInput(Thread, koloreak): def run(self,koloreak): #Main on Thread GPIO.output(gorri, 1)
import random import time from threading import Thread from RPi.GPIO import GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(gorri, GPIO.OUT, initial = 0) GPIO.setup(hori, GPIO.OUT, initial = 0) GPIO.setup(urdin, GPIO.OUT, initial = 0) gorri = input(int("Gorriaren tokia") hori = input(int("horiaren tokia") urdin = input(int("urdinaren tokia") koloreak [gorri, hori,urdin] class WaitForUserInput(Thread, koloreak): def run(self,koloreak): #Main on Thread GPIO.output(gorri, 1) sleep(1) GPIO.output(gorri, 0) GPIO.output(urdin, 1) sleep(1) GPIO.output(urdin, 0) GPIO.output(hori, 1) sleep(1) def main(koloreak):
import requests from lxml import html import subprocess from RPi.GPIO import GPIO import time channel = 23 GPIO.setup(channel, GPIO.IN, pull_up_down=GPIO.PUD_UP) def submit_barcode(): subprocess.call(["raspistill", '-o', 'slika.jpg']) r = requests.post('http://zxing.org/w/decode', files={'file': ('koda.png', koda, 'image/png')}) if (r.text.split("<title>")[1].split("</title>")[0] == "Decode Succeeded"): print(r.text.split("Raw text</td><td><pre>")[1].split("</pre>")[0]) return r.text.split("Raw text</td><td><pre>")[1].split("</pre>")[0] else: print("slaba slika") while 1: if GPIO.input(channel) == GPIO.LOW: barcode = submit_barcode() r = requests.post('http://pohladi.ga/api/barcode', json={'barcode': barcode}) time.sleep(0.01)
from RPi.GPIO import GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setup(8, GPIO.OUT, initial=GPIO.LOW) if (True): GPIO.output(8, GPIO.HIGH) else: GPIO.output(8, GPIO.LOW)
def setupGpio(): GPIO.setmode(GPIO.BOARD)
from RPi.GPIO import GPIO import time #Pins RedLED = 26 AmberLED = 24 GreenLED = 22 GPIO.setup(RedLED, GPIO.OUT) GPIO.setup(AmberLED, GPIO.OUT) GPIO.setup(GreenLED, GPIO.OUT) while True: GPIO.output(RedLED, True) GPIO.output(AmberLED, True) GPIO.output(GreenRED, True) time.sleep(1) GPIO.output(RedLED, False) GPIO.output(AmberLED, False) GPIO.output(GreenLED, False) time.sleep(1)
def set_in_out(self, in_out): self.in_out = in_out GPIO.setup(self.pin, in_out)
def get_boolean(self): return GPIO.input(self.pin)
def set_boolean(self, state): GPIO.output(self.pin, state)