Ejemplo n.º 1
0
def ledUpdateLoop():
    RED = gpiozero.PWMLED(2)
    GREEN = gpiozero.PWMLED(0)
    while True:
        stat = get_status({})['danger_coeff']
        RED.value = stat
        GREEN.value = 1.0 - stat
        sleep(0.1)
Ejemplo n.º 2
0
def led_pwm():
    red_led = gz.PWMLED(14)
    yellow_led = gz.PWMLED(15)
    green_led = gz.PWMLED(18)

    while True:
        for k in range(10):
            red_led.value = k / 10
            time.sleep(0.5)
Ejemplo n.º 3
0
    def __init__(self,
                 leftOn=17,
                 leftDir=27,
                 rightOn=23,
                 rightDir=24,
                 modePin=22):
        # Motor Stuff
        self.leftMotor = gpiozero.PWMLED(leftOn, frequency=50)
        self.leftDir = gpiozero.LED(leftDir)

        self.rightMotor = gpiozero.PWMLED(rightOn, frequency=50)
        self.rightDir = gpiozero.LED(rightDir)

        self.mode = gpiozero.LED(modePin)
        self.mode.on()
Ejemplo n.º 4
0
    def __init__(self):
        if rpi.RPI_REVISION == 1:
            i2c_bus = 0
        else:
            i2c_bus = 1

        self.bus = SMBus(i2c_bus)
        self.bus.write_i2c_block_data(0x54, 0x00, [0x01])
        self.bus.write_byte_data(0x54, 0x13, 0xFF)
        self.bus.write_byte_data(0x54, 0x14, 0xFF)
        self.bus.write_byte_data(0x54, 0x15, 0xFF)

        self.sun1 = gpiozero.PWMLED(4)
        self.sun2 = gpiozero.PWMLED(17)
        self.sun3 = gpiozero.PWMLED(27)
Ejemplo n.º 5
0
	def __init__(self, name, args={}, debug_pref=False):
		super().__init__(name, args, debug_pref)
		self._type = 'led'
		if 'gpio_pin' not in args:
			raise AttributeError("GPIO pin required for {} {}".format(self.type, self.name))
		self._connection = gpiozero.PWMLED(self._gpio_pin)
		self.off()
Ejemplo n.º 6
0
    def __init__(
        self,
        contactSwitch=[2, 3],
        ledVolume=4,
        potVolume=17,
        motorDirection=[18, 23, 24],
        muteSwitch=25,
    ):
        self.contactSwitch = [
            gpiozero.Button(contactSwitch[0], bounce_time=self.BOUNCE_TIME),
            gpiozero.Button(contactSwitch[1], bounce_time=self.BOUNCE_TIME)
        ]
        self.ledVolume = gpiozero.PWMLED(ledVolume)
        self.potVolume = gpiozero.MCP3008(channel=potVolume)

        # TODO program motorDirection[2] for PWM speed control
        # see L298N motor driver documentation for details
        self.motorDirection = [
            gpiozero.Motor(motorDirection[0], motorDirection[1], pwm=False),
            gpiozero.PWMOutputDevice(motorDirection[2])
        ]
        # This is a toggle switch not a button
        self.muteSwitch = gpiozero.Button(muteSwitch,
                                          bounce_time=self.BOUNCE_TIME)

        self.strikeState = 'idle'
Ejemplo n.º 7
0
def hack(repeat, hacked_ip):
    # pi = pigpio.pi(hacked_ip,8888)
    # pigpio.pi('soft', 8888)
    factory = PiGPIOFactory(host=hacked_ip)
    led7 = gpiozero.PWMLED(4, active_high=False, pin_factory=factory)

    for loop in range(0, repeat):
        while not button.is_pressed:
            led7.value = 1
            time.sleep(.5)
            led7.value = 0
            time.sleep(.5)
Ejemplo n.º 8
0
#!/usr/bin/env python3

# import packages
import gpiozero
import time

#Hacking Rock
from gpiozero import LED
from gpiozero.pins.pigpio import PiGPIOFactory
from gpiozero.tools import all_values

led1 = gpiozero.PWMLED(6, active_high=False)
led2 = gpiozero.PWMLED(13, active_high=False)
led3 = gpiozero.PWMLED(12, active_high=False)
led4 = gpiozero.PWMLED(26, active_high=False)
led5 = gpiozero.PWMLED(20, active_high=False)
led6 = gpiozero.PWMLED(21, active_high=False)
button = gpiozero.Button(16)


# POWERING UP
def turn_on(repeat):
    for loop in range(0, repeat):
        for b in range(10):
            led1.value = b * 0.1
            time.sleep(.025)
            while button.is_pressed:
                pass
        for b in range(10):
            led2.value = b * 0.1
            time.sleep(.025)
Ejemplo n.º 9
0
from subprocess import check_call
#button for skipping back one track
trackbackbutton = gpiozero.Button(2)
#button for play/pause control
playpausebutton = gpiozero.Button(3)
#button for skipping forwards one track
trackforwardsbutton = gpiozero.Button(4)
#button to stop the music and set track = 0
stopbutton = gpiozero.Button(5)
#button to shutdown the pi
shutdownbutton = gpiozero.Button(6)
#button to change the led mode
ledbutton = gpiozero.Button(7)

#LED setup
led1 = gpiozero.PWMLED(9)
led2 = gpiozero.PWMLED(10)
led3 = gpiozero.PWMLED(11)
led4 = gpiozero.PWMLED(12)
led5 = gpiozero.PWMLED(13)
led6 = gpiozero.PWMLED(14)
led7 = gpiozero.PWMLED(15)
led8 = gpiozero.PWMLED(16)
led9 = gpiozero.PWMLED(17)
led10 = gpiozero.PWMLED(18)
led11 = gpiozero.PWMLED(19)
led12 = gpiozero.PWMLED(20)
led13 = gpiozero.PWMLED(21)
led14 = gpiozero.PWMLED(22)
led15 = gpiozero.PWMLED(23)
led16 = gpiozero.PWMLED(24)
Ejemplo n.º 10
0
# encoding: utf-8
import gpiozero
import time

led = gpiozero.PWMLED(27)
ldr = gpiozero.LightSensor(17)

while True:
    if ldr.value >= 0.75:
        led.value = 0  # ne sveti
    elif ldr.value < 0.75 and ldr.value >= 0.5:
        led.value = 0.5  # sveti na pol
    else:
        led.value = 1  # sveti
    time.sleep(1)
Ejemplo n.º 11
0
import time
from time import sleep
import os
import matplotlib.pyplot as plt
#import pandas as pd
import numpy as np
import gpiozero as io
from gpiozero.tones import Tone 
from smbus2 import SMBusWrapper, i2c_msg               #for i2c devices
import Adafruit_DHT
import Adafruit_Python_SSD1306                                #oled




fan = io.PWMLED(21)


for i in range(10):
    fan.value = i*0.1
    sleep(10)

sleep(10)
fan.value = 0
Ejemplo n.º 12
0
def PWMLED(pin):
    return gpiozero.PWMLED(pin) if gpiozero else DummyLED()
Ejemplo n.º 13
0
# keep blue led for pwm below

#------------------------------

# PWM


def gpioOutPwm_h(val, pin, gpioObj):  # generic pwm write scaled 0-100
    val = int(val[0])
    if val < 0 or val > 100:
        print("Pls set slider scale 0-100")
    else:
        gpioObj.value = val / 100.0  # gpiozero pwm uses 0.0- 1.0


ledB = GPIO.PWMLED(16)  # blue led  controlled from 0-100 slider at app
blynk.add_virtual_pin(8, None, gpioOutPwm_h, ledB)

#---------------------------------

# ... and the blue PWMLED pwm value is read & sent back to gauge
#      on vpin 9 (0.0 -1.0)
blynk.add_virtual_pin(9, gpioRead_h, None, ledB)

#-------------------------------

# terminal from APP into python interpreter
_last_cmd = ""


def pyterminal_h(value, pin, st):
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
Ejemplo n.º 15
0
def heat_brew(heater_obj):
    # Turn on brew heater e.g. led
    # Dummy function since no real heater is used
    heater = heater_obj
    # pulse led to simulate a heating element
    for i in range(10):
        heater.value = i*0.1
        time.sleep(LED_PULSE_INTERVAL)
    for i in range(10, 0, -1):
        heater.value = i*0.1
        time.sleep(LED_PULSE_INTERVAL)
        heater.value = 0

if __name__ == "__main__":
    # flash led as sign of start
    led = gpiozero.PWMLED(HEATER_PIN)
    #led = led()

    led.value = 1
    time.sleep(1)
    led.value = 0.1
    time.sleep(1)
    led.value = 1
    time.sleep(1)
    led.value = 0

    # Commented out for testing purposes
    tmp117 = connect_temp_sensor()
    samples = connect_bubble_sensor()

    print("Add device to database")
Ejemplo n.º 16
0
 def __init__(self):
     self._led = gpiozero.PWMLED(pin=self.LED_PIN, initial_value=0)
     self._led_state = 0
Ejemplo n.º 17
0
import gpiozero

motorPins = [15, 24, 18, 16, 25]
motors = []

for i in range(0, len(motorPins)): motors.append(gpiozero.PWMLED(motorPins[i], initial_value = 0))

def value(id, amount):
    # The value is negated due to the fact that the vibrators get lighter as the distance sensors lose proximity.
    motors[id].value = 1 - amount
Ejemplo n.º 18
0
import signal
import sys
import requests
import subprocess
import time
import RPi.GPIO as GPIO
import gpiozero
import board
import digitalio
import adafruit_character_lcd.character_lcd as characterlcd

# Setup GPIO peripherals with gpiozero
button = gpiozero.Button(6)
shutdown_button = gpiozero.Button(3)
manual_stop_button = gpiozero.Button(4)
red_LED = gpiozero.PWMLED(17)
green_LED = gpiozero.PWMLED(27)
blue_LED = gpiozero.PWMLED(22)

# Setup LCD with digitalio
lcd_rs = digitalio.DigitalInOut(board.D13)
lcd_en = digitalio.DigitalInOut(board.D21)
lcd_d4 = digitalio.DigitalInOut(board.D19)
lcd_d5 = digitalio.DigitalInOut(board.D16)
lcd_d6 = digitalio.DigitalInOut(board.D26)
lcd_d7 = digitalio.DigitalInOut(board.D20)
lcd_coloumns = 16
lcd_rows = 2
lcd = characterlcd.Character_LCD_Mono(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_coloumns, lcd_rows)

# Define function to handle interrupt signal
Ejemplo n.º 19
0
 def on_start(self):
     self.LED = gpiozero.PWMLED(self.settings.pin)
Ejemplo n.º 20
0
import RPi.GPIO
import RPLCD
import gpiozero
from itertools import chain, repeat
import time

_width = 20
_width1 = 21
_lcd = RPLCD.CharLCD(pin_rs=25,
                     pin_rw=22,
                     pin_e=24,
                     pins_data=[3, 15, 2, 14],
                     numbering_mode=RPi.GPIO.BCM)
_lcd.clear()

_green = gpiozero.PWMLED(21)
_red = gpiozero.PWMLED(20)


def write(line1, line2, align1="<", align2="<"):
    display_line1 = ("{: " + align1 + str(_width) +
                     "}").format(line1)[:_width1]
    display_line2 = ("{: " + align2 + str(_width) +
                     "}").format(line2)[:_width1]
    text = display_line1 + display_line2
    _lcd.clear()
    _lcd.write_string(text)


def scroll_top(text,
               prepad=0,
Ejemplo n.º 21
0
 def _init_led(self):
     self.gpio_red = gpiozero.PWMLED(self.pin_id_red)
     self.gpio_green = gpiozero.PWMLED(self.pin_id_green)
     self.gpio_blue = gpiozero.PWMLED(self.pin_id_blue)
     self._put_color(0,0,0)     
Ejemplo n.º 22
0
# 2.py
# 結果: LEDが徐々に明るくなり、今度は徐々に暗くなり、を繰り返す

import time

import gpiozero as gz

output_pin: int = 23
interval_sec: int = 1
delta_brightness: float = 0.01
wait_sec: float = 0.5

led: gz.LED = gz.PWMLED(output_pin)

brightness: float = led.value
should_add_brightness: bool = True

while (True):

    if (should_add_brightness):
        brightness += delta_brightness
    else:
        brightness -= delta_brightness

    if (brightness > 1):
        should_add_brightness = False
        brightness = 1
        time.sleep(wait_sec)
    elif (brightness < 0):
        should_add_brightness = True
        brightness = 0
Ejemplo n.º 23
0
ADNS3080_FRAME_PERIOD_MIN_BOUND_UPPER = 0x1c
ADNS3080_SHUTTER_MAX_BOUND_LOWER = 0x1e
ADNS3080_SHUTTER_MAX_BOUND_UPPER = 0x1e
ADNS3080_SROM_ID = 0x1f
ADNS3080_OBSERVATION = 0x3d
ADNS3080_INVERSE_PRODUCT_ID = 0x3f
ADNS3080_PIXEL_BURST = 0x40
ADNS3080_MOTION_BURST = 0x50
ADNS3080_SROM_LOAD = 0x60
ADNS3080_PRODUCT_ID_VAL = 0x17

# Setup the connection to the optical flow sensor
opti_flow_sensor = gpiozero.SPIDevice(port=0, device=0)
opti_flow_reset = gpiozero.LED(PIN_SENSOR_RESET)
opti_flow_cs = gpiozero.LED(PIN_SENSOR_CS)
led_lighting = gpiozero.PWMLED(pin=PIN_LIGHTING)

# Setup the ROS publisher
rospy.init_node('holly_optical_flow')  # public display name of the publisher
rate = rospy.Rate(15)  # 15hz

# setup publisher and classes
odomPub = rospy.Publisher('optical_flow/odom', Odometry, queue_size=10)
msg = Odometry()

qualityPub = rospy.Publisher('optical_flow/quality', Float32, queue_size=1)
qualityMsg = Float32()

pivoting = False

import gpiozero, readtemp
from time import sleep

# Minimum and maximum temperatures
# Try changing these!
cold=22
hot=32

# Which pins are the LEDs connected to?
blueled=gpiozero.PWMLED(23)
redled=gpiozero.PWMLED(24)

# Turn on the LEDs
blueled.on()
redled.on()

while True:
  # Find the temperature
  temp=readtemp.readtemp()

  # Calculate a value between 0 and 1 representing hotness
  hotness=(temp-cold)/(hot-cold)
  if hotness>1:
    hotness=1
  if hotness<0:
    hotness=0
  print ( "Temp: {}c - Hotness {}".format(temp,hotness) )

  # Set the brightness of the LEDs
  blueled.value=1-hotness
  redled.value=hotness
Ejemplo n.º 25
0
import gpiozero

### Assign GPIO pins ###
freq = 100
motor1AGpio = gpiozero.PWMLED(22, frequency=freq)
motor1BGpio = gpiozero.PWMLED(27, frequency=freq)
motor2AGpio = gpiozero.PWMLED(4, frequency=freq)
motor2BGpio = gpiozero.PWMLED(17, frequency=freq)


class control:
    turnValue = 0
    speedValue = 0

    @staticmethod
    def turn(turnValue):
        control.turnValue = turnValue

        control.outputGpio()

    @staticmethod
    def speed(speedValue):
        control.speedValue = speedValue

        control.outputGpio()

    @staticmethod
    def outputGpio():
        motor1Value = 0
        motor2Value = 0
Ejemplo n.º 26
0
import gpiozero

from time import sleep

leftMotor = gpiozero.PWMLED(23, frequency=50)
leftDir = gpiozero.LED(24)

while True:
    count = 1
    up = True
    dir = True
    leftDir.off()
    print("Start")
    while dir == True:
        leftMotor.value = count / 100.0
        print(leftMotor.value)
        if up:
            count += 1
        else:
            count -= 1
        if (count == 100):
            up = False
        elif (count == 0):
            dir = False
            count = 1
        sleep(0.03)
    sleep(2)
    leftDir.on()
    up = False
    count = 99
    print("Switch")
Ejemplo n.º 27
0

lastValues = []


def thread_run():
    global lastValues
    while True:
        value = getValue()

        # keep track of last values to give the feel that the light is actually a coil-based light.
        lastValues = lastValues[0:3]
        lastValues.insert(0, value)
        value = sum(lastValues) / len(lastValues)

        value *= value  # adapt for non-linear dim of LEDs
        led.value = value
        time.sleep(1 / 25)


try:
    led = gpiozero.PWMLED(myUtil.ledPin)

    thread = threading.Thread(target=thread_run, daemon=True)
    thread.name = "led"
    thread.start()
except gpiozero.exc.BadPinFactory as e:
    elog(
        "LED GPIO could not be initialized. You are probably not running on a RasPi, so we disable the LED feature."
    )
Ejemplo n.º 28
0
Archivo: zanke.py Proyecto: zalenka/rpi
# encoding: utf-8
import gpiozero
import time

pin17 = gpiozero.PWMLED(17)

while True:  # zanka, ki zagotovi ponavljanje kode v nedogled
    svetilnost = 0
    while svetilnost < 1:
        svetilnost = round(svetilnost, 1)
        pin17.value = svetilnost
        svetilnost = svetilnost + 0.1
        time.sleep(0.5)
    while svetilnost > 0.1:
        svetilnost = round(svetilnost, 1)
        pin17.value = svetilnost
        svetilnost = svetilnost - 0.1
        time.sleep(0.5)
Ejemplo n.º 29
0
 def _create_led(self):
     return gpiozero.PWMLED(self.pin, active_high=self.active_high)