コード例 #1
0
ファイル: ledrgb.py プロジェクト: azogue/enerpi
def get_rgbled(verbose=True):
    """Tries to get gpiozero RGBLED object at pins PIN_R|G|B if WITH_RGBLED in config file"""
    led = None
    if WITH_RGBLED:
        try:
            from gpiozero import RGBLED
            from gpiozero.pins.rpigpio import RPiGPIOPin

            led = RGBLED(RPiGPIOPin(PIN_R), RPiGPIOPin(PIN_G), RPiGPIOPin(PIN_B), active_high=True)
            led.blink(.25, .25, on_color=(1, 1, 1), n=5)
        except (OSError, RuntimeError, ImportError) as e:
            log('** Not using RGBLED with GPIOZERO ({} [{}]). Check your "{}" file.'
                .format(e, e.__class__, CONFIG_FILENAME), 'warn', verbose)
    return led
コード例 #2
0
ファイル: ledServer.py プロジェクト: fedtemis/Fonograf
    def __init__(self):
        threading.Thread.__init__(self)
        self.color = '000000'
        self.red = 0
        self.green = 0
        self.blue = 0

        self.bRed = 0.4
        self.bGreen = 0
        self.bBlue = 0

        self.on = True
        self.blink = False
        self.RGB = RGBLED(22,23,24,False,(self.bRed, self.bGreen, self.bBlue))
コード例 #3
0
from gpiozero import RGBLED
import time
led = RGBLED(15, 14, 18)
while True:
    try:
        led.blue = 1
        for n in range(100):
            led.red = 0 + n / 100
            time.sleep(0.02)
            if led.red == 0.4:
                break

        for n in range(35):
            led.red = 0.4 - n / 100
            time.sleep(0.03)
            if led.red == 0.1:
                break

        for n in range(100):
            led.red = 0.1 + n / 80
            time.sleep(0.01)
            if led.red == 1:
                break
        g = 1
        for n in range(100):
            led.blue = 1 - n / 100
            time.sleep(0.01)
            if led.blue <= 0.15:
                led.green = 0 + (g / 100)
                time.sleep(0.02)
                g = g + 1
コード例 #4
0
from gpiozero import RGBLED
import psutil, time

myled = RGBLED(14,15,18)

while True:
    cpu = psutil.cpu_percent()
    r = cpu / 100.0
    g = (100 - cpu)/100.0
    b = 0
    myled.color = (r, g, b)
    time.sleep(0.1)
コード例 #5
0
          4                 B  x  x  x  x  x  x  x  x
"""

# LEDs on/off switch pin definitions
leds = [
    LED(18),  # 0
    LED(23),  # 1
    LED(24),  # 2
    LED(25),  # 3
    LED(12),  # 4
    LED(16),  # 5
    LED(20),  # 6
    LED(21)  # 7
]
# PWM color driving  pin definitions
rgb_driver = RGBLED(13, 19, 26)

# Balancing  factors for better color accuracy
scale = {"R": 0.7, "G": 0.8, "B": 1}


def light_standby():
    """Make the panel show a standby mode switching on all led and creating a pulse effect to """
    for led in leds:
        led.on()

    rgb_driver.pulse(on_color=(scale["R"], scale["G"], scale["B"]),
                     off_color=(0, 0, 0))


def light_arrow(direction: int, red: float, green: float, blue: float):
コード例 #6
0
ファイル: homekit.py プロジェクト: layetri/nightlight
import logging
import signal
import random

from pyhap.accessory import Accessory
from pyhap.const import CATEGORY_LIGHTBULB
import pyhap.loader as loader
from pyhap.accessory_driver import AccessoryDriver
from gpiozero import RGBLED
from colorzero import Color

led = RGBLED(26, 6, 5, active_high=True, initial_value=Color(130, 200, 40))
logging.basicConfig(level=logging.INFO, format="[%(module)s] %(message)s")


class Nightlight(Accessory):
    """Implementation of a mock light accessory."""

    category = CATEGORY_LIGHTBULB  # This is for the icon in the iOS Home app.

    def __init__(self, *args, **kwargs):
        """Here, we just store a reference to the on and brightness characteristics and
        add a method that will be executed every time their value changes.
        """
        # If overriding this method, be sure to call the super's implementation first.
        super().__init__(*args, **kwargs)

        # Setup the Bulb
        serv_light = self.add_preload_service(
            'Lightbulb', chars=['On', 'Hue', 'Saturation', 'Brightness'])
コード例 #7
0
ファイル: rgbled_test.py プロジェクト: sigmafish/lesson1
from gpiozero import RGBLED
from time import sleep

if __name__ == '__main__':
    # initialize the gpio pin
    rgbled = RGBLED(12, 20, 21)  #(r,g,b)
    rgb_color = [(1, 0, 0), (0, 1, 0), (0, 0, 1), (0, 0, 0)]

    i = 0
    mode = len(rgb_color) - 1

    while (i < mode * 5):
        ##        print(i)
        rgbled.color = rgb_color[i % mode]
        sleep(1)
        i += 1

    # turn off led
    rgbled.color = rgb_color[mode]
コード例 #8
0
from gpiozero import RGBLED
from time import sleep

led = RGBLED(red=21, green=20, blue=19)

while True:
    letra = input(
        """Ingresa la letra correspondiente al color que quieras encender:

    A = Azul
    V = Verde
    R = Rojo
    """)

    if letra == 'A':
        led.color = (1, 1, 0)
    elif letra == 'V':
        led.color = (1, 0, 1)
    elif letra == 'R':
        led.color = (0, 1, 1)
    elif letra == 'O':
        led.color = (1, 1, 1)
    else:
        print('Ingresa una letra valida')
コード例 #9
0
from gpiozero import RGBLED
import psutil, time
led = RGBLED(15, 14, 18)

while True:
    try:
        cpu = psutil.cpu_percent()
        r = cpu / 100.0
        g = (100 - cpu) / 100.0
        b = 0
        led.color = (r, g, b)
        time.sleep(0.1)

        temp = dict(psutil.sensors_temperatures())
        temp = list(temp['cpu_thermal'][0])
        temp = round(temp[1], 1)
        print(temp)
    except KeyboardInterrupt:
        break

led.off()
コード例 #10
0
from gpiozero import RGBLED
from time import sleep
led = RGBLED(red=17, green=18, blue=19)
delay = 0.02

while True:
    led.blink(on_time=0, off_time=0, \
              fade_in_time=2, fade_out_time=2, \
              on_color=(1,0,0), off_color=(0,0,0))
    sleep(4)

    led.blink(on_time=0, off_time=0, \
              fade_in_time=2, fade_out_time=2, \
              on_color=(0,1,0), off_color=(0,0,0))
    sleep(4)

    led.blink(on_time=0, off_time=0, \
              fade_in_time=2, fade_out_time=2, \
              on_color=(0,0,1), off_color=(0,0,0))
    sleep(4)
コード例 #11
0
ファイル: colorfader.py プロジェクト: helotism/show-cgfmgt
from gpiozero import RGBLED
from gpiozero import Button
from time import sleep
import random
from signal import pause
import os.path
import yaml

if ( os.path.isfile('config.yml')):
  with open("config.yml", "r") as configfile:
    cfg = yaml.load(configfile)
elif ( os.path.isfile('config_orig.yml')):
  with open("config.yml", "r") as configfile:
    cfg = yaml.load(configfile)


led = RGBLED(red=cfg['red_pin'], green=cfg['green_pin'], blue=cfg['blue_pin'])
button = Button(cfg['button_pin'])

colors = [ (1,0,0), (0,1,0), (1,1,0), (1,1,1) ]

#while True:
#  led.blink(on_time=1, off_time=1, fade_in_time=1, fade_out_time=1, on_color=random.choice(colors), off_color=(0, 0, 0), n=1, background=False)
#  sleep(1)

while True:
  led.color = random.choice(colors)
  sleep(2)

コード例 #12
0
#  */

from gpiozero import RGBLED
from gpiozero import Button
from signal import pause
import os.path
import yaml

if ( os.path.isfile('config.yml')):
  with open("config.yml", "r") as configfile:
    cfg = yaml.load(configfile)
elif ( os.path.isfile('config_orig.yml')):
  with open("config.yml", "r") as configfile:
    cfg = yaml.load(configfile)

led = RGBLED(red=cfg['red_pin'], green=cfg['green_pin'], blue=cfg['blue_pin'])
button = Button(cfg['button_pin'])

state = 'init'
led.color = (0,0,1)

if ( os.path.isfile('performance.yml')):
  with open("performance.yml", "r") as configfile:
    cfg = yaml.load(configfile)
elif ( os.path.isfile('performance_orig.yml')):
  with open("performance.yml", "r") as configfile:
    cfg = yaml.load(configfile)

if cfg['performance'] == "":
  speed=2
elif cfg['performance'] == "silver":
コード例 #13
0
ファイル: rgbled.py プロジェクト: Flye001/Pokedex
from gpiozero import RGBLED
from time import sleep

led = RGBLED(red=9, green=10, blue=11)

led.blue = 1
sleep(1)
led.blue = 0.5
sleep(1)
led.blue = 0
コード例 #14
0
ファイル: rgb_cpumon.py プロジェクト: topshed/rgb_cpumon
from gpiozero import RGBLED
import psutil, colorsys, time

myled = RGBLED(14,18,15)
            
while True:
    cpu = psutil.cpu_percent()
    r = cpu / 100.0 
    g = (100 - cpu)/100.0
    b = 0
    myled.color = (r,g,b)
    time.sleep(0.1)
コード例 #15
0
ファイル: myoh-rgb.py プロジェクト: cdn/MYOH
from gpiozero import RGBLED
from time import sleep

led = RGBLED(22,27,17)

led.on()
sleep(0.5)
led.off()
led.red = 1
sleep(0.5)
led.red =0
led.green=1
sleep(0.5)
led.green = 0
led.blue = 1
sleep(0.5)
led.blue=0


コード例 #16
0
ファイル: ledServer.py プロジェクト: fedtemis/Fonograf
class ledControl(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.color = '000000'
        self.red = 0
        self.green = 0
        self.blue = 0

        self.bRed = 0.4
        self.bGreen = 0
        self.bBlue = 0

        self.on = True
        self.blink = False
        self.RGB = RGBLED(22,23,24,False,(self.bRed, self.bGreen, self.bBlue))
    def convertColor(self):
        try:
            divider     = 256
            red         = float(int("0x"+self.color[0:2], 0))
            # red         = red-(red/2)

            green       = float(int("0x"+self.color[2:4], 0))
            green       = green-(green/2.5)

            blue        = float(int("0x"+self.color[4:6], 0))
            # blue        = blue-(blue/2)
            if red>=divider:
               red=divider
            if green>=divider:
               green=divider
            if blue>=divider:
               blue=divider
            self.red = red/divider
            self.green = green/divider
            self.blue = blue/divider
            return True
        except ValueError:
            return False
    def setColor(self, red, green, blue):
        self.RGB.color = (red,green,blue)
    def setHexColor(self, color):
        self.color = cleanColor(color)
        return self.convertColor()
    def loadAndSetColor(self, color):
        self.color = cleanColor(color)
        self.convertColor()
        self.setColor(self.red, self.green, self.blue)
        return
    def blinkLeds(self, interval, fadeTime, blinks, on):
        if not self.blink:
            Thread(target=self.blinkingThread, args=(interval,fadeTime,blinks,on, )).start()
            return True
        return False
    def blinkingThread(self, interval, fadeTime, blinks, on):
        fInterval = float(interval)
        fFadeTime = float(fadeTime)
        fBlinks = int(blinks)
        if not self.blink:
            self.blink = True
            blinker = self.RGB.blink(fInterval, fInterval, fFadeTime, fFadeTime, (self.red, self.green, self.blue), (self.bRed, self.bGreen, self.bBlue), fBlinks, False)
            self.blink = False
            blinker = None
        if on:
            self.setColor(self.red,self.green,self.blue)
        else:
            self.setColor(self.bRed, self.bGreen, self.bBlue)
    def rainbow(self):
        self.loadAndSetColor('#000000')
        time.sleep(0.5)
        self.loadAndSetColor('#110000')
        time.sleep(0.05)
        self.loadAndSetColor('#220000')
        time.sleep(0.05)
        self.loadAndSetColor('#330000')
        time.sleep(0.05)
        self.loadAndSetColor('#440000')
        time.sleep(0.05)
        self.loadAndSetColor('#550000')
        time.sleep(0.05)
        self.loadAndSetColor('#660000')
        time.sleep(0.05)
        self.loadAndSetColor('#770000')
        time.sleep(0.05)
        self.loadAndSetColor('#880000')
        time.sleep(0.05)
        self.loadAndSetColor('#990000')
        time.sleep(0.05)
        self.loadAndSetColor('#AA0000')
        time.sleep(0.05)
        self.loadAndSetColor('#BB0000')
        time.sleep(0.05)
        self.loadAndSetColor('#CC0000')
        time.sleep(0.05)
        self.loadAndSetColor('#DD0000')
        time.sleep(0.05)
        self.loadAndSetColor('#EE0000')
        time.sleep(0.05)
        self.loadAndSetColor('#FF0000')
        time.sleep(0.05)
        self.loadAndSetColor('#FF1100')
        time.sleep(0.05)
        self.loadAndSetColor('#FF2200')
        time.sleep(0.05)
        self.loadAndSetColor('#FF3300')
        time.sleep(0.05)
        self.loadAndSetColor('#FF4400')
        time.sleep(0.05)
        self.loadAndSetColor('#FF5500')
        time.sleep(0.05)
        self.loadAndSetColor('#FF6600')
        time.sleep(0.05)
        self.loadAndSetColor('#FF7700')
        time.sleep(0.05)
        self.loadAndSetColor('#FF8800')
        time.sleep(0.05)
        self.loadAndSetColor('#FF9900')
        time.sleep(0.05)
        self.loadAndSetColor('#FFAA00')
        time.sleep(0.05)
        self.loadAndSetColor('#FFBB00')
        time.sleep(0.05)
        self.loadAndSetColor('#FFCC00')
        time.sleep(0.05)
        self.loadAndSetColor('#FFDD00')
        time.sleep(0.05)
        self.loadAndSetColor('#FFEE00')
        time.sleep(0.05)
        self.loadAndSetColor('#FFFF00')
        time.sleep(0.05)
        self.loadAndSetColor('#EEFF00')
        time.sleep(0.05)
        self.loadAndSetColor('#DDFF00')
        time.sleep(0.05)
        self.loadAndSetColor('#CCFF00')
        time.sleep(0.05)
        self.loadAndSetColor('#BBFF00')
        time.sleep(0.05)
        self.loadAndSetColor('#AAFF00')
        time.sleep(0.05)
        self.loadAndSetColor('#AAFF00')
        time.sleep(0.05)
        self.loadAndSetColor('#99FF00')
        time.sleep(0.05)
        self.loadAndSetColor('#88FF00')
        time.sleep(0.05)
        self.loadAndSetColor('#77FF00')
        time.sleep(0.05)
        self.loadAndSetColor('#66FF00')
        time.sleep(0.05)
        self.loadAndSetColor('#55FF00')
        time.sleep(0.05)
        self.loadAndSetColor('#44FF00')
        time.sleep(0.05)
        self.loadAndSetColor('#33FF00')
        time.sleep(0.05)
        self.loadAndSetColor('#22FF00')
        time.sleep(0.05)
        self.loadAndSetColor('#11FF00')
        time.sleep(0.05)
        self.loadAndSetColor('#00FF00')
        time.sleep(0.05)
        self.loadAndSetColor('#00FF11')
        time.sleep(0.05)
        self.loadAndSetColor('#00FF22')
        time.sleep(0.05)
        self.loadAndSetColor('#00FF33')
        time.sleep(0.05)
        self.loadAndSetColor('#00FF44')
        time.sleep(0.05)
        self.loadAndSetColor('#00FF55')
        time.sleep(0.05)
        self.loadAndSetColor('#00FF66')
        time.sleep(0.05)
        self.loadAndSetColor('#00FF77')
        time.sleep(0.05)
        self.loadAndSetColor('#00FF88')
        time.sleep(0.05)
        self.loadAndSetColor('#00FF99')
        time.sleep(0.05)
        self.loadAndSetColor('#00FFAA')
        time.sleep(0.05)
        self.loadAndSetColor('#00FFBB')
        time.sleep(0.05)
        self.loadAndSetColor('#00FFCC')
        time.sleep(0.05)
        self.loadAndSetColor('#00FFEE')
        time.sleep(0.05)
        self.loadAndSetColor('#00FFFF')
        time.sleep(0.05)
        self.loadAndSetColor('#00EEFF')
        time.sleep(0.05)
        self.loadAndSetColor('#00DDFF')
        time.sleep(0.05)
        self.loadAndSetColor('#00CCFF')
        time.sleep(0.05)
        self.loadAndSetColor('#00BBFF')
        time.sleep(0.05)
        self.loadAndSetColor('#00AAFF')
        time.sleep(0.05)
        self.loadAndSetColor('#0099FF')
        time.sleep(0.05)
        self.loadAndSetColor('#0088FF')
        time.sleep(0.05)
        self.loadAndSetColor('#0077FF')
        time.sleep(0.05)
        self.loadAndSetColor('#0066FF')
        time.sleep(0.05)
        self.loadAndSetColor('#0055FF')
        time.sleep(0.05)
        self.loadAndSetColor('#0044FF')
        time.sleep(0.05)
        self.loadAndSetColor('#0033FF')
        time.sleep(0.05)
        self.loadAndSetColor('#0022FF')
        time.sleep(0.05)
        self.loadAndSetColor('#0011FF')
        time.sleep(0.05)
        self.loadAndSetColor('#0000FF')
        time.sleep(0.05)
        self.loadAndSetColor('#1100FF')
        time.sleep(0.05)
        self.loadAndSetColor('#2200FF')
        time.sleep(0.05)
        self.loadAndSetColor('#3300FF')
        time.sleep(0.05)
        self.loadAndSetColor('#4400FF')
        time.sleep(0.05)
        self.loadAndSetColor('#5500FF')
        time.sleep(0.05)
        self.loadAndSetColor('#6600FF')
        time.sleep(0.05)
        self.loadAndSetColor('#7700FF')
        time.sleep(0.05)
        self.loadAndSetColor('#8800FF')
        time.sleep(0.05)
        self.loadAndSetColor('#9900FF')
        time.sleep(0.05)
        self.loadAndSetColor('#AA00FF')
        time.sleep(0.05)
        self.loadAndSetColor('#BB00FF')
        time.sleep(0.05)
        self.loadAndSetColor('#CC00FF')
        time.sleep(0.05)
        self.loadAndSetColor('#DD00FF')
        time.sleep(0.05)
        self.loadAndSetColor('#EE00FF')
        time.sleep(0.05)
        self.loadAndSetColor('#FF00FF')
        time.sleep(0.05)
        self.loadAndSetColor('#FF00EE')
        time.sleep(0.05)
        self.loadAndSetColor('#FF00DD')
        time.sleep(0.05)
        self.loadAndSetColor('#FF00CC')
        time.sleep(0.05)
        self.loadAndSetColor('#FF00BB')
        time.sleep(0.05)
        self.loadAndSetColor('#FF00AA')
        time.sleep(0.05)
        self.loadAndSetColor('#FF0099')
        time.sleep(0.05)
        self.loadAndSetColor('#FF0088')
        time.sleep(0.05)
        self.loadAndSetColor('#FF0077')
        time.sleep(0.05)
        self.loadAndSetColor('#FF0066')
        time.sleep(0.05)
        self.loadAndSetColor('#FF0055')
        time.sleep(0.05)
        self.loadAndSetColor('#FF0044')
        time.sleep(0.05)
        self.loadAndSetColor('#FF0033')
        time.sleep(0.05)
        self.loadAndSetColor('#FF0022')
        time.sleep(0.05)
        self.loadAndSetColor('#FF0011')
        time.sleep(0.05)
        self.loadAndSetColor('#FF0000')
        time.sleep(0.05)
        self.loadAndSetColor('#EE0000')
        time.sleep(0.05)
        self.loadAndSetColor('#DD0000')
        time.sleep(0.05)
        self.loadAndSetColor('#CC0000')
        time.sleep(0.05)
        self.loadAndSetColor('#BB0000')
        time.sleep(0.05)
        self.loadAndSetColor('#AA0000')
        time.sleep(0.05)
        self.loadAndSetColor('#990000')
        time.sleep(0.05)
        self.loadAndSetColor('#880000')
        time.sleep(0.05)
        self.loadAndSetColor('#770000')
        time.sleep(0.05)
        self.loadAndSetColor('#660000')
        time.sleep(0.05)
        self.loadAndSetColor('#550000')
        time.sleep(0.05)
        self.loadAndSetColor('#440000')
        time.sleep(0.05)
        self.loadAndSetColor('#330000')
        time.sleep(0.05)
        self.loadAndSetColor('#220000')
        time.sleep(0.05)
        self.loadAndSetColor('#110000')
        time.sleep(0.05)
        self.loadAndSetColor('#000000')
        time.sleep(0.5)
        self.setColor(0.4,0,0)
コード例 #17
0
ファイル: rgbled.py プロジェクト: EdwardBetts/python-gpiozero
from gpiozero import RGBLED
from time import sleep

led = RGBLED(red=9, green=10, blue=11)

led.red = 1  # full red
sleep(1)
led.red = 0.5  # half red
sleep(1)

led.color = (0, 1, 0)  # full green
sleep(1)
led.color = (1, 0, 1)  # magenta
sleep(1)
led.color = (1, 1, 0)  # yellow
sleep(1)
led.color = (0, 1, 1)  # cyan
sleep(1)
led.color = (1, 1, 1)  # white
sleep(1)

led.color = (0, 0, 0)  # off
sleep(1)

# slowly increase intensity of blue
for n in range(100):
    led.blue = n/100
    sleep(0.1)
コード例 #18
0
from gpiozero import RGBLED
from guizero import App, Slider
from colorzero import Color

rgb_led = RGBLED(18, 23, 24)

red = 0
green = 0
blue = 0

def red_changed(value):
    global red
    red = int(value)
    rgb_led.color = Color(red, green, blue)

def green_changed(value):
    global green
    green = int(value)
    rgb_led.color = Color(red, green, blue)

def blue_changed(value):
    global blue
    blue = int(value)
    rgb_led.color = Color(red, green, blue)

app = App(title='RGB LED', width=500, height=400)

Slider(app, command=red_changed, end=255, width='fill', height=50).text_size = 30
Slider(app, command=green_changed, end=255, width='fill', height=50).text_size = 30
Slider(app, command=blue_changed, end=255, width='fill', height=50).text_size = 30
コード例 #19
0
#!/usr/bin/env python3

from gpiozero import RGBLED
from time import sleep

led = RGBLED(18, 23, 24) 

colours = [
    (1, 0, 0),
    (1, 0.55, 0),
    (0.7, 0.7, 0), 
    (0, 1, 0),
    (0, 0.7, 0.7),
    (0, 0, 1),
    (0.7, 0, 0.7)

]

def constrain(low, high, value):
    return max(low, min(high, value))

def fade_out(led, time):
    steps = 20
    delay = time / steps
    delta = max(led.red, led.green, led.blue) / steps

    while led.red > delta or led.green > delta or led.blue > delta:
        if led.red >= delta:
            led.red -= delta

        if led.green >= delta:
コード例 #20
0
from gpiozero import RGBLED
from colorzero import Color
from time import sleep

#define pins
led = RGBLED(green=10,red=9,blue=11,active_high=False) # common anode RBG LED!

led.on()
sleep(1)
led.off()

led.color = Color("yellow")
sleep(1)
led.color = Color("purple")
sleep(1)
led.toggle() #invert
sleep(1)
led.blink(on_time=1.5, off_time=0.5, fade_in_time=0.5, fade_out_time=0.5, on_color=(1, 0.3, 1), off_color=(0, 1, 0), n=10, background=False)


led.off()

print("done")
led.close()

コード例 #21
0
APPLAUSE_THRESHOLD = 100
# Raspberry GPIO where the RED pin of your LED strip is connected
RED_PIN = 9
# Raspberry GPIO where the GREEN pin of your LED strip is connected
GREEN_PIN = 10
# Raspberry GPIO where the BLUE pin of your LED strip is connected
BLUE_PIN = 11

##################


fk_url = "http://api.facebook.com/restserver.php?method=links.getStats&urls=" + FACEBOOK_PAGE_URL
yt_url = "https://www.googleapis.com/youtube/v3/channels?part=statistics&id=" + YOUTUBE_CHANNEL_ID + "&fields=items/statistics/subscriberCount&key=" + GOOGLE_API_KEY
insta_url = "https://api.instagram.com/v1/users/" + INSTAGRAM_USER_ID + "/?access_token=" + INSTAGRAM_ACCESS_TOKEN
likes = new_likes = subscribers = new_subscribers = followers = new_followers = 0
led = RGBLED(red=RED_PIN, green=GREEN_PIN, blue=BLUE_PIN)
green = red = blue = 0

while True:
    fk_response = requests.get(fk_url)
    yt_response = requests.get(yt_url)
    insta_response = requests.get(insta_url)

    if fk_response.status_code == 200:
        tree = ElementTree.fromstring(fk_response.content)
        new_likes = int(tree[0][5].text)

    if yt_response.status_code == 200:
        new_subscribers = int(yt_response.json()['items'][0]['statistics']['subscriberCount'])

    if insta_response.status_code == 200:
コード例 #22
0
ファイル: inittest_rgb.py プロジェクト: Scott3142/chemRPi
from gpiozero import MCP3208, RGBLED
from time import sleep

led = RGBLED(red=19,green=21,blue=26)

adc = MCP3208(channel=1)
led.color = (0,178/255,1)

while True:    
    voltage = 3.3*adc.value
    print(voltage)
    sleep(0.5)
コード例 #23
0
ファイル: PyDashPi.py プロジェクト: cazro/PyDashPi
    
    ### Styling
    ## Font
    camera.annotate_background = Color('black')
    camera.annotate_text_size = 16
    camera.vflip = True
    start = time.time()
    #camera.start_preview()
    filename = video_dir+'dashcam_'+datetime.now().strftime('%Y-%m-%d_%H.%M.%S')+'.h264'
    videos = deque([filename])
    camera.start_recording(filename,format='h264',resize=(vid_width,vid_height))
    rec_button = Button(4)
    stop_button = Button(25)
    rec_button.when_pressed = recbuttonpress
    stop_button.when_pressed = stopbuttonpress
    led = RGBLED(27,8,17)

    while not camera.closed:
        led.color = (1,0,1)
        if not shutdown:
            end = time.time() 
            seconds = end - start
            camera.annotate_text = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
           
            if  save == True:
                save = False
                print "Saving video"
                filename = video_dir+'dashcam_'+datetime.now().strftime('%Y-%m-%d_%H.%M.%S')+'.h264'
                camera.split_recording(filename)
                dst = video_store+datetime.now().strftime('%Y')+'/'+datetime.now().strftime('%b')+'/'+datetime.now().strftime('%d')+'/'
                if not os.path.exists(dst):
コード例 #24
0
import MPR121
from gpiozero import RGBLED
import subprocess
import pygame
from pygame.mixer import Sound
from glob import glob
from time import sleep

sensor = MPR121.begin()
sensor.set_touch_threshold(40)
sensor.set_release_threshold(20)

led = RGBLED(6, 5, 26, active_high=False)

electrodes = range(12)

# convert mp3s to wavs with picap-samples-to-wav
led.blue = 1
subprocess.call("picap-samples-to-wav tracks", shell=True)
led.off()

# initialize mixer and pygame
pygame.mixer.pre_init(frequency=44100, channels=64, buffer=1024)
pygame.init()

sounds = [Sound(path) for path in glob("tracks/.wavs/*.wav")]


def play_sounds_when_touched():
    if sensor.touch_status_changed():
        sensor.update_touch_data()
コード例 #25
0
ファイル: Example.py プロジェクト: fdelia/raspberry-backup
from Adafruit_BME280 import *
from time import sleep
from gpiozero import RGBLED

sensor = BME280(mode=BME280_OSAMPLE_8)
led = RGBLED(red=4, green=26, blue=19)
start_temp = False
counter = 0

while True:
	degrees = sensor.read_temperature()
	pascals = sensor.read_pressure()
	hectopascals = pascals / 100
	humidity = sensor.read_humidity()

	print 'Timestamp = {0:0.3f}'.format(sensor.t_fine)
	print 'Temp      = {0:0.3f} deg C'.format(degrees)
	print 'Pressure  = {0:0.2f} hPa'.format(hectopascals)
	print 'Humidity  = {0:0.2f} %'.format(humidity)
	print ' '
	
	if not start_temp and counter>3: start_temp = degrees
        counter += 1

	diff_temp = max(0, min(1, (degrees-start_temp)))
        #print(diff_temp)
	led.color = (diff_temp, 0,1-diff_temp)

	sleep(0.02)
from gpiozero import RGBLED, Button
from time import sleep
from random import uniform

# Declare RGBLED at GPIO 22, 17, and 27
# By default, the 'on' method of RGBLED will be a
# white light
led = RGBLED(red=22, green=17, blue=27)
red = [1.0, 0.0, 0.0]
green = [0.0, 0.0, 1.0]

# Declare buttons at GPIO 14 (top) and 15 (bottom)
top_button = Button(14)
bottom_button = Button(15)

# Assign player names to buttons
top_name = raw_input('Name of player using top button: ')
bottom_name = raw_input('Name of player using bottom button: ')


# Method to determine which player has pressed her button
def get_winner_name(button):
    if button.pin.number == 14:
        return top_name
    else:
        return bottom_name


# Method to print message when a button has been pressed
# Determines color of LED and prints message accordingly
def pressed(button):
コード例 #27
0
from gpiozero import RGBLED, MCP3008
from signal import pause

led = RGBLED(2, 3, 4)
red_pot = MCP3008(0)
green_pot = MCP3008(1)
blue_pot = MCP3008(2)

led.source = zip(red_pot.values, green_pot.values, blue_pot.values)

pause()
コード例 #28
0
#this code is meant to integrate hardware into a simple button flip code by
#adding an RGBLED and 3 buttons. This should allow the game to be plyed without
#a monitor
from time import sleep
from random import choice
from gpiozero import RGBLED, Button
from subprocess import check_call
coin = ("heads", "tails")  #creating the 'coin'
led = RGBLED(8, 7, 1)  #creating all of our objects representing the hardware
h = Button(2)
t = Button(3)
pwr_off = Button(14, hold_time=2)


def shutdown():  # this function will shutdown the Pi when called
    check_call(["sudo", "poweroff"])


def heads():
    global player  #Tried to initialize variable outside of function. Did not
    player = "heads"  #work. Variable scope different in python?


def tails():
    global player
    player = "tails"


def coinflip():
    flip = choice(coin)
    h.when_pressed = heads  #Assigning a button to be heads
コード例 #29
0
ファイル: tweetometer.py プロジェクト: topshed/tweetometer
#Tweet-o-meter: Add your own Twitter API developer keys (lines 9-12)
# and choose your own keyword/hashtag (line 56)
import time, sys
from textblob import TextBlob
from gpiozero import RGBLED
from twython import TwythonStreamer

# Add Python Developer App tokens and secret keys
APP_KEY ='ENTER APP KEY HERE' # <- CHANGE
APP_SECRET = 'ENTER APP SECRET HERE' # <- CHANGE
OAUTH_TOKEN = 'ENTER OAUTH_TOKEN HERE' # <- CHANGE
OAUTH_TOKEN_SECRET = 'ENTER OAUTH_TOKEN_SECRET HERE' # <- CHANGE

# Set our RGB LED pins
status_led = RGBLED(14,15,18, active_high=True)
# Set active_high to False for common anode RGB LED
status_led.off()
totals = {'pos':0,'neg':0,'neu':0}
colours = {'pos':(0,1,0),'neg':(1,0,0),'neu':(0,0,1)}

class MyStreamer(TwythonStreamer):
    def on_success(self,data): # When we get valid data
        if 'text' in data: # If the tweet has a text field
            tweet = data['text'].encode('utf-8')
            #print(tweet) # uncomment to display  each tweet
            tweet_pro = TextBlob(data['text']) # calculate sentiment
            # adjust value below to tune sentiment sensitivity
            if tweet_pro.sentiment.polarity > 0.1: # Positive
                print('Positive')
                status_led.blink(on_time=0.4, off_time=0.2, on_color=(0, 1, 0), n=1, background=False)
                totals['pos']+=1
コード例 #30
0
# Importamos la libreria GPIO
import RPi.GPIO as GPIO

# Importamos la libreria para el teclado
import curses

# Importamos la libreria del LED
from gpiozero import RGBLED

# Declaramos la entrada de teclado
key = curses.initscr()

# Declaramos el led
led = RGBLED(12, 16, 20)

# Definimos el modo BCH
GPIO.setmode(GPIO.BCM)

# Ahora definimos el pin GPIO 18 como salida
GPIO.setup(18, GPIO.OUT)

# Realizamos el ciclo
while True:

    tecla = key.getch()  # obtenemos la tecla presionada
    if tecla == 27:  # Teclas direccionales, que va a encender el LED Rojo
        led.on()
        led.off()
        led.color = (1, 0, 0)  # Rojo

    if tecla == 32:  # Tecla de espacio, que va a encender el LED Verde
コード例 #31
0
ファイル: main.py プロジェクト: Aaperezon/IoTPOBros_RobotCode
import requests
from gpiozero import RGBLED
from gpiozero import OutputDevice
import time
from AngleMeterAlpha import AngleMeterAlpha
from os import remove
from os import path
import json
import motorController
import PID
#CLASS VARIABLES
angleMeter = AngleMeterAlpha()
angleMeter.measure()
led = RGBLED(17, 27, 22)
statusLED = RGBLED(10, 9, 11)
#HOST TO CONNECT
ipHost = '192.168.1.103'
#JSON CONFIGURATION FOR PID
p = './Scripts/PID_Configuration.json'
#GLOBAL VARIABLES
id = 0
timeValue = 0
switchValue = 0
gyroX = 0.0
gyroY = 0.0
gyroZ = 0.0
anyChange = False


def Upload(url):
    try:
コード例 #32
0
ファイル: weather.py プロジェクト: fdelia/raspberry-backup
import forecastio
import datetime

from gpiozero import RGBLED, Button
from time import sleep
from signal import pause
from math import pow

# https://developer.forecast.io/docs/v2#forecast_call

led = RGBLED(red=4, green=26, blue=19)
#led2 = RGBLED(red=13, green=6, blue=5)

button = Button(18)
button2 = Button(23)
led.off()

api_key = "9c09fe99666a61bbd85aa2743387cd31"
lat = 47.3769
lng = 8.5417


def nextHours(hours):
	if led.is_lit:
		led.off()
		led2.off()
		return

	# till the forecast is loaded
	led.color = (0.2,0.2,0.2)
	led2.color = (0.2,0.2,0.2)
コード例 #33
0
ファイル: rgbled.py プロジェクト: claremacrae/raspi_code
from gpiozero import RGBLED
from time import sleep
led = RGBLED(red=17, green=18, blue=19)

# Change red brightness
led.red = 1
sleep(0.5)

led.red = 0.5
sleep(0.5)

led.red = 0.0
sleep(0.5)

# Change green brightness
led.green = 1
sleep(0.5)

led.green = 0.5
sleep(0.5)

led.green = 0.0
sleep(0.5)

# Change blue brightness
led.blue = 1
sleep(0.5)

led.blue = 0.5
sleep(0.5)