Пример #1
0
    def __init__(self, lcd_rs, lcd_e, lcd_data, buzzer_pin, red_led_pin,
                 yellow_led_pin, green_led_pin, button_pins, fm_username: str,
                 fm_key: str, spot_client: str, spot_secret: str,
                 spot_refresh: str):
        self.lcd = CharLCD(numbering_mode=GPIO.BCM,
                           cols=lcd_width,
                           rows=2,
                           pin_rs=lcd_rs,
                           pin_e=lcd_e,
                           pins_data=lcd_data,
                           auto_linebreaks=True)
        self.lcd.cursor_mode = 'hide'
        self.leds = TrafficLights(red=red_led_pin,
                                  yellow=yellow_led_pin,
                                  green=green_led_pin,
                                  pwm=True)

        self.buzzer = TonalBuzzer(buzzer_pin)
        self.buzzer_lock = Lock()

        self.notif_button = Button(button_pins[0])
        self.notif_button.when_activated = self.handle_notif_click

        self.button2 = Button(button_pins[1])
        self.button2.when_activated = lambda: self.queue_text('hey', 'hey')

        self.button3 = Button(button_pins[2])
        self.button4 = Button(button_pins[3])
        self.button4.when_held = self.handle_network_hold

        self.location = DisplayLocation.home

        self.pulled_idle_text = dict()

        self.notification_queue = Queue()
        self.display_queue = Queue()
        self.display_thread = Thread(target=self.display_worker,
                                     name='display',
                                     daemon=True)

        self.network_active = True

        self.rsession = Session()
        self.fmnet = FMNetwork(username=fm_username, api_key=fm_key)
        self.spotnet = SpotNetwork(
            NetworkUser(client_id=spot_client,
                        client_secret=spot_secret,
                        refresh_token=spot_refresh)).refresh_access_token()

        self.network_pull_thread = Thread(target=self.network_pull_worker,
                                          name='puller',
                                          daemon=True)
Пример #2
0
def flashing_LED():
    lights = TrafficLights(2, 3, 4)
    lights.green.on()

    for i in range(2):
        time.sleep(10)
        lights.green.off()
        lights.amber.on()
        time.sleep(1)
        lights.amber.off()
        lights.red.on()
        time.sleep(10)
        lights.amber.on()
        time.sleep(1)
        lights.green.on()
        lights.amber.off()
        lights.red.off()
Пример #3
0
 def __init__(self):
     self.semaforo = TrafficLights(4, 3, 2)
Пример #4
0
 def _set_up_traffic_lights(self):
     self.traffic_lights = TrafficLights(*self.config.traffic_lights_pins)
Пример #5
0
#PROGRAM DONE BY CEBASTIAN SANTIAGO
#simple traffic light sequence with a buzzer and green light red and yellow light using the raspberry pi Gpio pins
from time import sleep
from gpiozero import Button, TrafficLights, Buzzer

buzzer = Buzzer(15)
lights = TrafficLights(25, 8, 7)

button = Button(21)

while True:
    button.wait_for_press()
    lights.green.on()
    sleep(5)
    lights.green.off()
    lights.amber.on()
    sleep(5)
    lights.amber.off()
    lights.red.on()
    buzzer.on()
    sleep(5)
    lights.red.off()
    buzzer.off()
Пример #6
0
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 17 22:59:34 2018

@author: Gregor
"""

from gpiozero import TrafficLights
from time import sleep

lights = TrafficLights(2, 3, 4)

lights.green.on()

while True:
    sleep(10)
    lights.green.off()
    lights.amber.on
    sleep(1)
    lights.amber.off()
    lights.red.on
    sleep(10)
    lights.amber.on
    sleep(1)
    lights.green.on()
    lights.amber.off()
    lights.red.off
    
Пример #7
0
from gpiozero import TrafficLights
from time import sleep

semaforo1 = TrafficLights(2, 3, 4)  #red, yellow, green
semaforo2 = TrafficLights(17, 27, 22)


def cond1():  #semaro1=verde; s2=vml
    semaforo1.green.on()
    semaforo1.amber.off()
    semaforo1.red.off()

    semaforo2.green.off()
    semaforo2.amber.off()
    semaforo2.red.on()


def cond2():  #semaro1 amarelo; s2=vml
    semaforo1.green.off()
    semaforo1.amber.on()
    semaforo1.red.off()

    semaforo2.green.off()
    semaforo2.amber.off()
    semaforo2.red.on()


def cond3():  #semaro1 vermelho; s2=verde
    semaforo1.green.off()
    semaforo1.amber.off()
    semaforo1.red.on()
Пример #8
0
import json
import requests
from datetime import date, timedelta, datetime  # Time is important
import logging
from apscheduler.schedulers.blocking import BlockingScheduler
from gpiozero import TrafficLights
Ampel1 = TrafficLights(4, 3, 2) #ampel eins defenieren

Ampel2 = TrafficLights(22 ,27,17)  # ampel zwei defenieren

Ampel3 = TrafficLights(26, 19, 13)  # ampel drei defenieren

logging.basicConfig(filename='Requests.log', level=logging.INFO,format='%(message)s')  # logging conf
def Corona_ampel():
    # get the API data.
    r = requests.get('https://www.berlin.de/lageso/gesundheit/infektionsepidemiologie-infektionsschutz/corona/tabelle-indikatoren-gesamtuebersicht/index.php/index/today.json')

    abfrage = ("Daten abgefragt: " + datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
    logging.info(abfrage)
    print("Daten abgefragt: " + datetime.now().strftime('%Y-%m-%d %H:%M:%S'), "\n") # Get the date for the Request, so the printout is more organiesd even after a longer time of running.

    print("Daten vom:", r.json()['index'][0]['datum'], "\n") # Get the date for the Data thats being used, so the printout is more organiesd even after a longer time of running.

    raw = ("Raw Data: ", r.json()['index'][0])  # print the latest info in the terminal.
    logging.info(raw)


    # 7 tage inzidenz abfragen
    tage = float(r.json()['index'][0]['7_tage_inzidenz'])
    if tage >= 30:  # wenn über 30
        data = ("7_tage_inzidenz -", float(r.json()['index'][0]['7_tage_inzidenz']), "- ROT")
Пример #9
0
    def __init__(self):

        self.status = "GREEN"  # This will be used for stack lights.
        self.stackLight = "YELLOW"  # When initialising
        try:
            self.stack = TrafficLights(
                2, 3, 4)  # Set up the hardware for the traffic lights
            self.stacklightsAvailable = True
        except:
            print("Skipping stacklights - unsupported on this OS")
            self.stacklightsAvailable = False
        self.updateStackLight()

        self.timer = _interactionTimer(self)
        self.output = _outputManager(self)
        self.sfx = _soundController(self)

        self.event = _event(self)

        self.name = self.output.getConfig('DEFAULT', 'name')
        self.location = self.output.getConfig('DEFAULT', 'location')
        self.version = 'Chaotic Cabbage'  # Taken from https://www.michaelfogleman.com/phrases/

        self.recognised = {  # regexes which differentiate the recognised codes exactly
            'bcc':
            re.compile(
                r'^bc\d+$'
            ),  # https://pythex.org/?regex=%5Ebc%5Cd%2B%24&test_string=bc365939269%0Abcs%0A5429bc97870%0ABC111%0Abcb5689&ignorecase=0&multiline=1&dotall=0&verbose=0
            'operation':
            re.compile(
                r'^op\d+$'
            ),  # https://pythex.org/?regex=%5Eop%5Cd%2B%24&test_string=op90%0Aopop%0A78o9%0Ao3p4p5o%0A247&ignorecase=1&multiline=1&dotall=0&verbose=0
            'employee':
            re.compile(
                r'^20\d{2}(0[1-9]|1[0-2])(0[1-9]|1[0-9]|2[1-9]|3[0-1])\d+$'
            ),  # https://pythex.org/?regex=%5E20%5Cd%7B2%7D(0%5B1-9%5D%7C1%5B0-2%5D)(0%5B1-9%5D%7C1%5Cd)%5Cd%2B%24&test_string=2019010203%0A2010030410%0A2010011209%0A200464531%0A19990203%0Aemp987902u2&ignorecase=1&multiline=1&dotall=0&verbose=0
            'combo':
            re.compile(r'^cmb-(?P<bcc>bc\d+)\|(?P<op>op\d+)\|act-(?P<act>\w+)$'
                       ),  # DEPRECATED IN FAVOUR OF REDUCED COMBO CODES
            'reducedcombo':
            re.compile(
                r'^(?P<bcc>\d+)\.(?P<op>\d+)\.(?P<act>[abcd])$'
            ),  # https://pythex.org/?regex=%5Ecmb-(%3FP%3Cbcc%3Ebc%5Cd%2B)%5C%7C(%3FP%3Cop%3Eop%5Cd%2B)%5C%7C(%3FP%3Cact%3Eact-%5Cw%2B)&test_string=cmb-bc239587485%7Cop78%7Cact-bgn1&ignorecase=1&multiline=1&dotall=0&verbose=0
            'actprefix':
            re.compile(
                r'^act-\w+$'
            ),  # https://pythex.org/?regex=%5Eact-%5Cw%2B%24&test_string=actact%0Aact-ok%0Aact-35294-%0Aact%0Atca34&ignorecase=1&multiline=1&dotall=0&verbose=0
            'ctrlprefix':
            re.compile(
                r'^ctrl-\w+$'
            ),  # https://pythex.org/?regex=%5Ectrl-%5Cw%2B%24&test_string=ctrl-exit%0Actrlctrl%0Actrl90%0Actrl-act-&ignorecase=1&multiline=1&dotall=0&verbose=0
            'scrapprefix':
            re.compile(r'^scrp-\w+$'),
            'nameprefix':
            re.compile(r'^name-\w+$'),
            'locationprefix':
            re.compile(r'^loc-\w+$'),
            'langprefix':
            re.compile(r'^lang-\w+$'),
            'logging':
            re.compile(r'^log-(?P<flag>\d)$'),
            'easter':
            re.compile(r'^egg-(?P<type>\w+)$'),
            'maintain':
            re.compile(r'^mech-(?P<name>\w+)$'),
            'ftpserver':
            re.compile(r'^ftpserver-(?P<ip>.+)$'),
            'ftplocalpath':
            re.compile(r'^ftplocalpath-(?P<localpath>.+)$'),
            'ipstring':
            re.compile(r'^.*\s*inet\s(?P<ip>\d+\.\d+\.\d+\.\d+)\s*.*')
        }

        self.output.terminalOutput("\n\nStation ~{}~ is now active\n\n".format(
            self.name),
                                   style="SUCCESS")

        self.updateStatus(self, "GREEN")
Пример #10
0
from gpiozero import TrafficLights
from time import sleep

lights = TrafficLights(14, 15, 18)

while True:
    lights.red.on()
    sleep(.5)
    lights.red.off()
    lights.amber.on()
    sleep(.5)
    lights.amber.off()
    lights.green.on()
    sleep(.5)
    lights.green.off()
Пример #11
0
def SetRYG(red, yellow, green):
  if not green:
    lights.green.off()
  else:
    lights.green.on()
  if not red:
    lights.red.off()
  else:
    lights.red.on()
  if not yellow:
    lights.yellow.off()
  else:
    lights.yellow.on()


lights = TrafficLights(16, 20, 21)

while True:
  sleep(10)
  SetRYG(red=True, yellow=False, green=False)
  sleep(5)
  SetRYG(red=True, yellow=True, green=False)
  sleep(1)
  SetRYG(red=False, yellow=False, green=True)
  sleep(4)
  for i in range(3):
    SetRYG(red=False, yellow=False, green=False)
    sleep(1)
    SetRYG(red=False, yellow=False, green=True)
    sleep(1)
  SetRYG(red=False, yellow=True, green=False)
Пример #12
0
from gpiozero import Button, TrafficLights, Buzzer

button = Button(3)
tr1 = TrafficLights(25, 8, 7)
tr2 = TrafficLights(16, 20, 21)
buzzer = Buzzer(15)

while True:
    tr2.on()
    buzzer.off()
    button.wait_for_press()

    tr2.off()
    #buzzer.on(245)
    button.wait_for_release()
    semaforo.red.off()
    semaforo.green.on()
    sleep(2)
    semaforo.green.off()
    semaforo.red.on()


def requisitar_travessia():
    global requisicao_travessia
    requisicao_travessia = True


# Main
requisicao_travessia = False

semaforo_carro = TrafficLights(4, 3, 2)
semaforo_pedestre = TrafficLights(27, 5, 17)

semaforo_pedestre.red.on()

button = Button(22, pull_up=True)
button.when_pressed = requisitar_travessia

while True:
    verde_a_vermelho_carro(semaforo_carro)

    sleep(1.5)
    if requisicao_travessia:
        verde_a_vermelho_pedestre(semaforo_pedestre)
        requisicao_travessia = False
    sleep(1.5)
Пример #14
0
from gpiozero import TrafficLights, Button
from time import sleep

tl1 = TrafficLights(13, 19, 26)
tl2 = TrafficLights(21, 20, 16)
tl3 = TrafficLights(10, 9, 11)
tl4 = TrafficLights(7, 8, 25)
cross1 = TrafficLights(2, 3, 4)
cross2 = TrafficLights(18, 15, 14)
btn = Button(5)

def pressed():
    print("Don't push the button!")

btn.when_pressed = pressed

while True:
    tl1.red.on()
    sleep(1)
    tl1.amber.on()
    btn.press() # for demo purposes
    sleep(1)
    tl1.off()
    tl1.green.on()
    sleep(3)
    tl1.off()
    tl1.amber.on()
    sleep(1)
    tl1.off()

while True:
Пример #15
0
from gpiozero import LED, Button, TrafficLights, Buzzer
from time import sleep

button = Button(17)
#led = LED(6)
lights = TrafficLights(25, 5, 6)
buzzer = Buzzer(13)

while True:
#    led.blink(0.1,0.2)  #on 0.1s and off 0.2s
#    button.wait_for_press()
#    print("Pressed")
#    led.off()
#    button.wait_for_release()
#    print("Released")
#    led.off()

#    lights.on()
#    lights.blink()
#    buzzer.beep()
#    buzzer.off()
#    button.wait_for_press()
#    lights.blink()
#    buzzer.blink()
#    button.wait_for_release()
#    lights.off()
#    buzzer.off()

#    button.wait_for_press()
    lights.green.on()
    sleep(1)
Пример #16
0
from guizero import App, Text, PushButton
from gpiozero import TrafficLights
from time import sleep
# Set the pins the traffic light uses on the raspberry pi
lights = TrafficLights(22, 27, 17)
#Defines The Function Which Declares What The Program Should do For the traffic light loop
def traffic_lights_loop():
    lights.green.off()
    sleep(0.5)
    lights.amber.on()
    sleep(0.5)
    lights.amber.off()
    lights.red.on()
    sleep(0.5)
    lights.amber.on()
    sleep(2)
    lights.red.off()
    lights.amber.off()
    lights.green.on()
    sleep(10)
    lights.off()

#Sets app Title bar labelAnd sets the  layout type
app = App("Traffic Lights controller", layout="grid")
#Creates button grid for Individual red light controller
Text(app, "Red", grid=[0, 0])
PushButton(app, command=lights.red.on, text="on", grid=[1, 0])
PushButton(app, command=lights.red.off, text="off", grid=[2, 0])
PushButton(app, command=lights.red.blink, text="blink", grid=[3, 0])

Text(app, "Amber", grid=[0, 1])
from gpiozero import TrafficLights
from time import sleep

lights = TrafficLights(23, 12, 21)

lights.green.on()

while True:
    sleep(10)
    lights.green.off()
    lights.amber.on()
    sleep(1)
    lights.amber.off()
    lights.red.on()
    sleep(10)
    lights.amber.on()
    sleep(1)
    lights.green.on()
    lights.amber.off()
    lights.red.off()
Пример #18
0
from gpiozero import Button, TrafficLights
from time import sleep

button = Button(2)
lights = TrafficLights(17, 27, 22)

while True:

    lights.green.on()
    sleep(4)
    lights.off()

    lights.amber.on()
    sleep(2)
    lights.off()

    lights.red.on()
    sleep(4)
    lights.off()
Пример #19
0
from gpiozero import Button, TrafficLights, Buzzer
from time import sleep

button = Button(21)
lights = TrafficLights(25, 16, 12)
buzzer = Buzzer(18)

while True:
    button.wait_for_press()
    lights.green.on()
    sleep(1)
    lights.green.off()
    sleep(1)
    lights.amber.on()
    sleep(1)
    lights.amber.off()
    sleep(1)
    lights.red.on()
    sleep(1)
    lights.amber.on()
    sleep(1)
    lights.off()
    lights.green.on()
    sleep(1)
    lights.off()
 def __init__(self):
     self.traffic_light = TrafficLights(2, 3, 4)
     self.button = Button(14)
Пример #21
0
# See:
# https://gpiozero.readthedocs.io/en/stable/recipes.html#traffic-lights
# To restart after changing:
#   sudo systemctl restart traffic

from gpiozero import TrafficLights, Button
from time import sleep
from signal import pause
import random

RED = 27
YELLOW = 22
GREEN = 17
BUTTON_PIN = 4

lights = TrafficLights(RED, YELLOW, GREEN, pwm=True)
button = Button(BUTTON_PIN)

def main():
    button.when_pressed = lights.on
    button.when_released = lights.off
    lights.source = traffic_light_sequence()
    try:
        pause()
    except KeyboardInterrupt:
        quit()


def traffic_light_sequence():
    while True:
        yield (0, 0, 1) # green
Пример #22
0
from gpiozero import TrafficLights
from time import sleep
from signal import pause

lights = TrafficLights(2, 3, 4)

def traffic_light_sequence():
    while True:
        yield (0, 0, 1) # green
        sleep(10)
        yield (0, 1, 0) # amber
        sleep(1)
        yield (1, 0, 0) # red
        sleep(10)
        yield (1, 1, 0) # red+amber
        sleep(1)

lights.source = traffic_light_sequence()

pause()
Пример #23
0
# Demo program to use Traffic pHAT with GPIO Zero
#This demo program shows you how to use each LED, and turns each one on in sequence every second.
from gpiozero import TrafficLights
from time import sleep

traffic = TrafficLights(23, 24, 25)

while True:
    traffic.red.on()
    sleep(1)
    traffic.red.off()
    traffic.amber.on()
    sleep(1)
    traffic.amber.off()
    traffic.green.on()
    sleep(1)
    traffic.green.off()
Пример #24
0
from gpiozero import TrafficLights
from time import sleep
from signal import pause

lights = TrafficLights(23, 18, 22)

def traffic_light_sequence():
    while True:
        yield (0, 0, 1) # green
        sleep(10)
        yield (0, 1, 0) # amber
        sleep(1)
        yield (1, 0, 0) # red
        sleep(10)
        yield (1, 1, 0) # red+amber
        sleep(1)

lights.source = traffic_light_sequence()

pause()
from gpiozero import Button, TrafficLights, Buzzer
from time import sleep

lButton = Button(3)
rButton = Button(2)

tr1 = TrafficLights(7, 8, 25)
tr2 = TrafficLights(21, 20, 16)

left_light_sequence = False

tr1.green.on()
tr1.amber.off()
tr1.red.off()

tr2.green.off()
tr2.amber.off()
tr2.red.on()


def lightSequence1():
    tr2.green.off()
    tr2.amber.on()
    sleep(3)
    tr2.amber.off()
    tr2.red.on()
    sleep(3)

    tr1.red.off()
    tr1.green.on()
    left_light_sequence = True
Пример #26
0
# Simulating a full traffic lights system

from gpiozero import TrafficLights
from time import sleep

# Create a lights object
lights = TrafficLights(5, 6, 13)

lights.green.on()

while True:
    sleep(10)
    lights.green.off()
    lights.amber.on()  # amber allows to switch lights continuously
    sleep(1)
    lights.amber.off()
    lights.red.on()
    sleep(10)
    lights.amber.on()
    sleep(1)
    lights.green.on()
    lights.amber.off()

    # or use
    # yield (0, 0, 1)
    # sleep(10)
    # yield (0, 1, 0) amber
    # sleep(1)
    # yield (1, 0, 0)
    # sleep(10)
    # yield (1, 0, 0) amber then green
Пример #27
0
from gpiozero import TrafficLights
from time import sleep

lights = [
    TrafficLights(),
    TrafficLights(),
    TrafficLights(),
    TrafficLights()
]

lights[0].green.on()
lights[1].red.on()
lights[2].red.on()
lights[3].red.on()

for i in range(4):
    sleep(1)
    lights[i].amber.on()
    sleep(0.5)
    lights[i].red.on()
    lights[(i+1)%4].green.on()
Пример #28
0
from gpiozero import TrafficLights
from time import sleep
from signal import pause

lights = TrafficLights(16, 20, 21)


def traffic_light_sequence():
    while True:
        yield (0, 0, 1)  # green
        sleep(10)
        yield (0, 1, 0)  # amber
        sleep(1)
        yield (1, 0, 0)  # red
        sleep(10)
        yield (1, 1, 0)  # red+amber
        sleep(1)


lights.source = traffic_light_sequence()

pause()
Пример #29
0
 def __init__(self):
     self.semaforo = TrafficLights(27, 14, 17)
Пример #30
0
from gpiozero import TrafficLights
from time import sleep
from signal import pause


lights = TrafficLights(2,3,4)
'''
Connect RED LED to GPIO2
Connect AMBER LED to GPIO3
Connect GREEN LED to GPIO4
Connect GND frpm Pie to -ves of all LEDS
'''

def traffic_light_sequence():
    while True:
        yield (0,0,1) #green
        sleep(10)
        yield(0,1,0) #amber
        sleep(1)
        yield(1,0,0) #red
        sleep(10)
        yield(1,1,0)
        sleep(1)


lights.source = traffic_light_sequence()

pause()
        
        
Пример #31
0
from gpiozero import Button, TrafficLights, Buzzer
from time import sleep
lights = TrafficLights(25, 8, 7)

button = Button(21)
buzzer= Buzzer(15)


while True:
      button.wait_for_press()
      lights.green.on()
      sleep(1)
      lights.amber.on()
      sleep(1)
      lights.red.on()
      sleep(1)
      lights.off()
      buzzer.beep()
    lights.amber.on()
    time.sleep(cycle_time)

    # Green
    lights.red.off()
    lights.amber.off()
    lights.green.on()
    time.sleep(cycle_time)

    # Amber
    lights.green.off()
    lights.amber.on()
    time.sleep(cycle_time)

    # Red
    lights.amber.off()
    lights.red.on()
    time.sleep(cycle_time)


lights = TrafficLights(17, 27, 22)

while True:
    british_lights_cycle(lights, 0.75)
    lights.off()
    time.sleep(0.75)

lights.off()

print "done!"