def _setup_hardware(self):
        """ Create instances of all peripherals needed. """
        self._main_LED = gpiozero.RGBLED(12,13,19,pwm=True)

        self._piezo = gpiozero.PWMOutputDevice(18,frequency=400)

        self._button = gpiozero.Button(4,hold_time=3,hold_repeat=False,pull_up=True)
        self._button.when_pressed = self._on_button_press
        self._button.when_released = self._on_button_release
        self._button.when_held = self._on_button_hold
    def _setup_hardware(self):
        """ Create instances of all peripherals needed. """
        # TODO: Ensure the following peripherals are correctly connected
        self._main_LED = gpiozero.RGBLED(12,13,19,pwm=True)

        self._piezo = gpiozero.PWMOutputDevice(18,frequency=400)

        self._sensor_adc = gpiozero.MCP3002(port=0,device=0,channel=0)

        self._button = gpiozero.Button(4,hold_time=3,hold_repeat=False,pull_up=True)
        self._button.when_pressed = self._on_button_press
        self._button.when_released = self._on_button_release
        self._button.when_held = self._on_button_hold
Exemple #3
0
# example code for raspberry pi portal
# assumes a button for GPIO
# written for LinkedIn Learning - Raspberry Pi Weekly
# Author: Mark Niemann-Ross ([email protected])
# thanks to https://www.stuffaboutcode.com/p/minecraft-api-reference.html

from mcpi import minecraft, block, vec3
import gpiozero
from colorzero import Color
from time import sleep
from signal import pause

mc = minecraft.Minecraft.create()
led = gpiozero.RGBLED(red=21, green=20, blue=16)
button = gpiozero.Button(26)

class portalStateObject:
    
    oneDefined = False
    twoDefined = False
    
    # keeps track of the state of two portals.
    # try if (portalState.oneDefined): etc
    def __init__(self):
        self.oneDefined = False
        self.twoDefined = False
    
    def setPortal(self, portalNumber, trueOrFalse):
        if (portalNumber == 1):
            self.oneDefined = trueOrFalse
        elif (portalNumber == 2):
Exemple #4
0
        time.sleep(1 / speed)


if not dry_run:
    gpiozero.AngularServo.move = move
    servo = gpiozero.AngularServo(4,
                                  min_angle=0,
                                  max_angle=90,
                                  initial_angle=None,
                                  pin_factory=PiGPIOFactory())
    switch = gpiozero.Button(27)
    breakwire = gpiozero.Button(22)
    switch.when_pressed = lambda: set_position(90)
    switch.when_released = lambda: set_position(0)
    breakwire.when_released = lambda: stop(True)
    LED = gpiozero.RGBLED(24, 23, 18)
position = None
shutdown = False  # whether to shut down after exit. Var will be set by function call
shutdown_hook = None  # hacky global to store the server shutdown function in at the soonest request
project_dir = '/home/pi/Documents/SRP_RI/'


def stop(_shutdown=False):
    global shutdown
    shutdown = _shutdown
    #print('shutting down?', shutdown)
    #request.environ.get('werkzeug.server.shutdown')()  # stop Flask server, does not work outside request
    shutdown_hook()


def set_position(angle):
Exemple #5
0
import gpiozero
import time
import os
import AudioProcessing
import Recording

led = gpiozero.RGBLED(red=9, green=10, blue=11)
led.color = (1,0,0)

mic = gpiozero.Button(2)
buzzer = gpiozero.LED(18)

if mic.is_pressed:
    buzzer.on()
    time.sleep(1)
    buzzer.off()
    record()
    if AudioProcessing.sample_recognize(/Users/Saif/Documents/GitHub/LiteOwl/input.wav) = "owl":
            for n in range(100):
            led.color = (1, n/100, n / 100);
            time.sleep(100)
    elif AudioProcessing.sample_recognize(/Users/Saif/Documents/GitHub/LiteOwl/input.wav) = "blue":
            led.color = (1, 1, 1)
            time.sleep(100)

os.remove("input.wav")
Exemple #6
0
STOPPED = 0
STARTING = 1
INITIALISING = 2
RUNNING = 3
ERROR = 4

RED = (1, 0, 0)
AMBER = (1, 0.1, 0)
YELLOW = (1, 0.24, 0)
GREEN = (0, 1, 0)
BLUE = (0, 0, 1)
PURPLE = (1, 0, 1)

BLACK = (0, 0, 0)

led = gpiozero.RGBLED(22, 27, 17)

state = STOPPED
delay = 1 / 5  #Hz

display = Display()


def get_throttle_count():
    netstat = run(['/bin/netstat', '-t', '--numeric-ports'], stdout=PIPE)

    c = 0
    if netstat.stdout:
        for l in netstat.stdout.splitlines():
            if b':12090' in l and l.endswith(b'ESTABLISHED'):
                c += 1
Exemple #7
0
import gpiozero as gpio
import serial
import pygame
from time import sleep
'''
ser = serial.Serial ("/dev/ttyS0", 9600)
'''
switch = gpio.Button(18)
switch.when_pressed = set_state(1)
switch.when_released = set_state(0)
breathLED = gpio.RGBLED(3, 4, 5)
motor_relay = gpio.DigitalOutputDevice(6)
is_active = 1

music_state = 0
music_volume = 3  #0-7


def toggle_motor_relay():
    global motor_relay
    if motor_relay.value:
        motor_relay.off()
    else:
        motor_relay.on()


def set_state(val):
    global is_active
    global motor_relay
    state = val
    print(val)
import gpiozero
import time

singleLED = gpiozero.PWMLED(14)
rgbLED = gpiozero.RGBLED(16, 20, 21)

# turn on the RGB LED
rgbLED.color = (1, 0, 0)  # red
time.sleep(1)
rgbLED.color = (0, 1, 0)  # green
time.sleep(1)
rgbLED.color = (0, 0, 1)  # blue
time.sleep(1)
rgbLED.color = (1, 1, 1)  # bright white
time.sleep(1)
rgbLED.color = (.01, .01, .01)  # dim white
time.sleep(1)
rgbLED.off()

# turn on LED
singleLED.value = .01  # dim
time.sleep(1)
singleLED.value = 1  # bright
time.sleep(1)
singleLED.off()

# blink clock
import datetime
timenow = datetime.datetime.now()
rgbLED.color = (timenow.hour / 24, timenow.minute / 60, timenow.second / 60)
singleLED.pulse(background=True)  # single LED pulses the seconds
Exemple #9
0
 def __init__(self):
     self.led = gpiozero.RGBLED(19, 20, 21, active_high=False)
     self.button = gpiozero.Button(16, hold_time=5, hold_repeat=False)
Exemple #10
0
import time

from gpiozero.pins.pigpio import PiGPIOFactory
import gpiozero

factory = PiGPIOFactory()

color_pin_dict = {"Red": 16, "Blue": 20, "Green": 21}  #, "Norm_Closed": 19}
gps_button_pin_dict = {"Sensor": 26}
running = True

# Set up LED in global space so callbacks can use it
gps_btn_led = gpiozero.RGBLED(color_pin_dict["Red"],
                              color_pin_dict["Green"],
                              color_pin_dict["Blue"],
                              active_high=False,
                              initial_value=(0, 0, 0),
                              pwm=True,
                              pin_factory=factory)


# Callbacks
def gps_btn_callback():
    print("Button pressed")
    # Purple
    gps_btn_led.color = .3, 0, .5


# ToDo: Add poweroff callback

Exemple #11
0
SKRIPTPFAD = os.path.abspath(os.path.dirname(__file__))
LOGGER = setup_logging.create_logger("picoffee", 10, SKRIPTPFAD)

db.database.initialize(db.peewee.SqliteDatabase(os.path.join(SKRIPTPFAD, 'db_coffee.db3'), **{}))

# GPIO Buttons
TASTERMINUS = xgpiozero.Button(12, pull_up=None, active_state=False)
TASTERPLUS = xgpiozero.Button(16, pull_up=None, active_state=False)
TASTERMENUE = xgpiozero.Button(20, pull_up=None, active_state=False)
TASTEROK = xgpiozero.Button(21, pull_up=None, active_state=False)
MAHLWERK = xgpiozero.Button(7, pull_up=None, active_state=False)
WASSER = xgpiozero.Button(5, pull_up=None, active_state=False)

# GPIO Output
TASTEN_FREIGABE = gpiozero.DigitalOutputDevice(6, initial_value=False)
RGBLED = gpiozero.RGBLED(13, 26, 19, active_high=True, initial_value=(1, 0, 0))

PIN_RST = 25
PIN_CE = 0
PIN_IRQ = 24


class Display:
    def __init__(self):
        self.lcd = CharLCD(i2c_expander='PCF8574', address=0x27, port=1, cols=16, rows=2, dotsize=8, charmap='A02',
                           auto_linebreaks=True, backlight_enabled=True)
        self.displayinhalt = None
        self.displayhistory = []

    def display_schreiben(self, zeile1, zeile2=None):
        self.__set_displayinhalt(zeile1, zeile2)
Exemple #12
0
 def _create_led(self):
     return gpiozero.RGBLED(*self.pins, active_high=self.active_high)
Exemple #13
0
logger.setLevel(logging.DEBUG)
# add the handlers to the logger
logger.addHandler(console_handler)
logger.addHandler(except_handler)
logger.addHandler(file_handler)

# log initial message
logger.info('Start of the log of {}'.format(conf.name))

# in case the pin number is None (null in json), a dummy object is assigned
hatch = (gpiozero.Servo(
    conf.hatch_pin, conf.hatch_closed, pin_factory=PiGPIOFactory())
         if conf.hatch_pin else dummy.Output('hatch'))
buzzer = (BeepingTonalBuzzer(conf.buzzer_pin, octaves=4)
          if conf.buzzer_pin else dummy.Output('buzzer'))
status_LED = (gpiozero.RGBLED(*conf.status_LED_pins, pwm=True)
              if all(conf.status_LED_pins) else dummy.Output('status_LED'))
arm_switch = (gpiozero.Button(conf.arm_switch_pin)
              if conf.arm_switch_pin else dummy.Input('arm_switch'))
breakwire = (gpiozero.Button(conf.breakwire_pin)
             if conf.breakwire_pin else dummy.Input('breakwire'))
gpiobjects = [hatch, buzzer, status_LED, arm_switch]

imu = altimu10v5.IMU()
# automatic dummy assignment if the sensors are not present, to allow for easier testing
if sensors_present():
    baro = Sensor('baro', conf.sensor_intervals['baro'],
                  imu.lps25h.get_barometer_raw)
    acc = Sensor('acc', conf.sensor_intervals['acc'],
                 imu.lsm6ds33.get_accelerometer_raw)
    gyro = Sensor('gyro', conf.sensor_intervals['gyro'],