コード例 #1
0
ファイル: puzzled.py プロジェクト: emm-ess/puzzled
def main():

    try:
        mote = None
        try:
            mote = Mote()
            mote.configure_channel(1, 16, False)
            mote.configure_channel(2, 16, False)
            mote.configure_channel(3, 16, False)
            mote.configure_channel(4, 16, False)
            mote.clear()
        except:
            pass

        puzzled = Puzzled(mote)
        puzzled.start()

        if mote != None:
            for channel in range(1, 5):
                for pixel in range(16):
                    mote.set_pixel(channel, pixel, 0, 0, 0)
            mote.show()

        curses.nocbreak()
        screen.keypad(False)
        curses.echo()
        curses.endwin()
        quit()
    except:
        curses.nocbreak()
        screen.keypad(False)
        curses.echo()
        curses.endwin()
        print(sys.exc_info())
コード例 #2
0
def open_mote():
    m = Mote()

    for channel in range(1, 5):
        m.configure_channel(channel, 16, False)

    return m
コード例 #3
0
def run():
    """let's goooo"""
    mote = Mote()

    mote.configure_channel(1, 16, False)
    mote.configure_channel(2, 16, False)
    mote.configure_channel(3, 16, False)
    mote.configure_channel(4, 16, False)

    rand_cols = ColorRandom()

    patterns = [
        pattern_floodfill,
        pattern_scatter,
        pattern_race,
        pattern_horizflood,
        pattern_horizsnakeflood,
        pattern_snakeflood,
    ]
    black = lambda: ColorConstant([0, 0, 0])
    colors = [
        ColorRandom,
        lambda: ColorConstant(rand_cols.get(None)),
        lambda: ColorChannelConstant(rand_cols),
        lambda: ColorChannelFade(rand_cols.get(None), rand_cols.get(None)),
        lambda: ColorGlobalFade(rand_cols.get(None), rand_cols.get(None)),
        lambda: ColorPixelFade(rand_cols.get(None), rand_cols.get(None)),
        lambda: ColorHorizCenterFade(rand_cols.get(None), rand_cols.get(None)),
        lambda: ColorRadialFade(rand_cols.get(None), rand_cols.get(None)),
        lambda: ColorChequerboard(rand_cols),
    ]
    last_col_template = None
    last_pattern_template = None

    while True:
        pattern_template = choice(patterns)
        if pattern_template == last_pattern_template:
            continue
        pattern = pattern_template() if random() < 0.5 else pattern_reverse(
            pattern_template())

        color_template = black if (random() < 0.33 and last_col_template is not None) \
            else choice(colors)
        if color_template == last_col_template:
            continue
        color = color_template()

        for update in pattern:
            c = color.get(update)
            prev_c = mote.get_pixel(update[0], update[1])
            for step in range(8):
                step_c = lerp_cols(step / 7.0, prev_c, c)
                mote.set_pixel(update[0], update[1], step_c[0], step_c[1],
                               step_c[2])
                mote.show()
                time.sleep(0.03)

        last_col_template = color_template
        last_pattern_template = pattern_template
コード例 #4
0
class MoteController:
    def __init__(self):
        self.mote = Mote()

        gammaCorrection = False
        self.mote.configure_channel(1, 16, gammaCorrection)
        self.mote.configure_channel(2, 16, gammaCorrection)
        self.mote.configure_channel(3, 16, gammaCorrection)
        self.mote.configure_channel(4, 16, gammaCorrection)

    def run(self, programs):
        while True:
            for program in programs:
                program.run(self.mote)
コード例 #5
0
def setstick(s, r, g, b):
    mote = Mote()  # new instance of the Mote class, will do all the USB init
    state = getmotestate()
    for m in range(1, 4 + 1):
        mote.configure_channel(m, 16,
                               False)  # configure for use the Mote sticks
        setpixels(m, state[m - 1][0], state[m - 1][1], state[m - 1][2], mote)
    if s == 0:
        for st in range(1, 4 + 1):
            setpixels(st, r, g, b, mote)
            setmotestate(state, st, r, g, b)
    else:
        setpixels(s, r, g, b, mote)
        setmotestate(state, s, r, g, b)
    mote.show()
コード例 #6
0
def init_motes(colour, brightness):
    print("initialising Motes")
    #set
    mote = Mote()  # new instance of the Mote class, will do all the USB init
    for m in range(1, 4 + 1):
        mote.configure_channel(m, 16,
                               False)  # configure for use the Mote sticks
    #calculate colour for brightness
    # just first stick at the moment
    h, s, v = colorsys.rgb_to_hsv(colour[0][0], colour[0][1], colour[0][2])
    colour_new = [[0] * 3 for i in range(4)]
    colour_new[0][0], colour_new[0][1], colour_new[0][2] = rgb_to_decimal(
        colorsys.hsv_to_rgb(h, s, brightness))
    set_mote_sticks(mote, colour_new)
    return mote
コード例 #7
0
ファイル: mote.py プロジェクト: jtc42/unicornpi-server
class MoteLamp(BaseLamp):
    def __init__(self, channels=4, correction=[1., 1., 1.]):

        self.mote = Mote()

        for c in range(channels):
            self.mote.configure_channel(c + 1, 16, False)

        BaseLamp.__init__(self, correction=correction)

        self.channels = channels
        self.pixels = 16

        for channel in range(self.channels):
            self.mote.configure_channel(channel + 1, self.pixels, False)

        self.width = self.channels
        self.height = self.pixels

    # Clear all pixels
    def clear(self):
        self.mote.clear()
        self.mote.show()

    def show(self):
        self.mote.show()

    # Set a single pixel
    def set_pixel(self, x, y, r, g, b):
        r, g, b = self.apply_correction(r, g, b)
        self.mote.set_pixel(x + 1, y, r, g, b)

    # Set all pixels to RGB
    def set_all(self, r, g, b):
        self.color = (r, g, b)
        r, g, b = self.apply_correction(r, g, b)
        self.mote.set_all(r, g, b)

    # Set maximum global brightness
    def set_brightness(self, val):
        val = int(val)
        if 0 <= val <= 255:
            self.mote.set_brightness(
                val / 255)  # Set brightness through unicornhat library
            self.brightness = val  # Log user-selected brightness to a variable
            self.mote.show()
        else:
            logging.error("Brightness must be between 0 and 255")
コード例 #8
0
def setstick(s, b, i):
    mote = Mote()  # new instance of the Mote class, will do all the USB init
    state = getmotestate()
    if i != 0:
        b = getbrightness(state, s) + i
        if b < 0:
            b = 0
        elif b > 9:
            b = 9
    state = setbrightness(state, s, b, i)
    for m in range(1, 4 + 1):
        mote.configure_channel(m, 16,
                               False)  # configure for use the Mote sticks
        setpixels(m, state[m - 1][0], state[m - 1][1], state[m - 1][2], mote)
    mote.show()
    setmotestate(state, s, state[s - 1][0], state[s - 1][1], state[s - 1][2])
コード例 #9
0
from time import sleep

from mote import Mote
from bluezero import constants
from bluezero import tools
from bluezero import adapter
from bluezero import device
from bluezero.GATT import Characteristic

display_on = False
lights = Mote()

mote_pixels = 16
lights.configure_channel(1, mote_pixels, False)


def on_accel_change(iface, changed_props, invalidated_props):
    print('Accel!')
    global display_on
    if iface != constants.GATT_CHRC_IFACE:
        return

    if not len(changed_props):
        return

    accel_val = changed_props.get('Value', None)
    if not accel_val:
        return

    # Read button value
    x = abs(int.from_bytes(accel_val[0:1], byteorder='little', signed=True))
コード例 #10
0
ファイル: rgb.py プロジェクト: RogueM/mote
#!/usr/bin/env python

import sys
import time

from mote import Mote


mote = Mote()

mote.configure_channel(1, 16, False)
mote.configure_channel(2, 16, False)
mote.configure_channel(3, 16, False)
mote.configure_channel(4, 16, False)


def usage():
    print("Usage: {} <r> <g> <b>".format(sys.argv[0]))
    sys.exit(1)

if len(sys.argv) != 4:
    usage()

# Exit if non integer value. int() will raise a ValueError
try:
    r, g, b = [int(x) for x in sys.argv[1:]]
except ValueError:
    usage()

# Exit if any of r, g, b are greater than 255
if max(r,g,b) > 255:
コード例 #11
0
ファイル: fireworks.py プロジェクト: recantha/fireworks
import pygame
from mote import Mote
import time
from random import randint

file_rocket = 'rocket.mp3'
file_firecrackers = 'with-firecrackers.mp3'
pygame.init()
pygame.mixer.init()
pygame.mixer.music.load(file_rocket)

mote = Mote()
for i in range(1, 5):
    mote.configure_channel(i, 16, False)


def twinkle(channel, pixel):
    pygame.mixer.music.play()
    print("Bang!")

    for i in range(0, 100):
        r = randint(10, 255)
        g = randint(10, 255)
        b = randint(10, 255)

        mote.set_pixel(channel, pixel, r, g, b)
        mote.show()
        time.sleep(0.005)
    pygame.mixer.fadeout(1)
    time.sleep(1)
コード例 #12
0
    import requests
except ImportError:
    exit(
        "This script requires the requests module\nInstall with: sudo pip install requests"
    )

from mote import Mote

mote = Mote()

num_pixels = 16

transition_time = 1  # seconds
transition_step = 100

mote.configure_channel(1, num_pixels, False)
mote.configure_channel(2, num_pixels, False)
mote.configure_channel(3, num_pixels, False)
mote.configure_channel(4, num_pixels, False)

try:
    channels_colour_rgb = [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]
    channels_colour = [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]
    channels_colour_delta = [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]
    old_channels_colour = [[0, 1, 0], [0, 1, 0], [0, 1, 0], [0, 1, 0]]
    while True:
        r = requests.get('http://api.thingspeak.com/channels/1417/feed.json')
        j = r.json()
        f = j['feeds'][-8:]

        f = [element for index, element in enumerate(f) if index % 2 == 0]
コード例 #13
0
ファイル: server.py プロジェクト: shift/script.kodi.ambimote
#!/usr/bin/env python3
"""AmbiMote UDP Server."""
import argparse
import sys
import asyncio
import struct
from base64 import b16encode
from mote import Mote

mote = Mote()

mote.configure_channel(1, 16, True)
mote.configure_channel(2, 16, True)
mote.configure_channel(3, 16, True)
mote.configure_channel(4, 16, True)

try:
    import signal
except ImportError:
    signal = None


class UdpAmbiMoteProtocol:
    pix_no = 0

    def connection_made(self, transport):
        print('start', transport)
        self.transport = transport

    @staticmethod
    def parse_rgb(i):
コード例 #14
0
ファイル: Clear.py プロジェクト: DangerousDarlow/PimoroniMote
from mote import Mote

if __name__ == "__main__":
    mote = Mote()
    gammaCorrection = False
    mote.configure_channel(1, 16, gammaCorrection)
    mote.configure_channel(2, 16, gammaCorrection)
    mote.configure_channel(3, 16, gammaCorrection)
    mote.configure_channel(4, 16, gammaCorrection)
    mote.clear()
    mote.show()
コード例 #15
0
#!/usr/bin/env python

import colorsys
import math
import signal
import time
from random import randint, sample
import argparse
import sys

if sys.platform == 'darwin':
    from mote import Mote
    motephat = Mote()
    motephat.configure_channel(1, 16, False)
    motephat.configure_channel(2, 16, False)
else:
    import motephat
    motephat.set_brightness(1)

parser = argparse.ArgumentParser()
parser.add_argument("sequence",
                    choices=['sparkle', 'flash'],
                    help="Type of mote sequence to play.")
parser.add_argument("-i",
                    "--interval",
                    default=0.1,
                    type=float,
                    help="Interval between sparkles in seconds (default=0.1).")
parser.add_argument(
    "-d",
    "--density",
コード例 #16
0
from mote import Mote
import time
import random

m = Mote()
m.configure_channel(1, 16, True)
m.configure_channel(2, 16, False)
m.configure_channel(3, 16, False)
m.configure_channel(4, 16, False)

m.clear()

last_r = 0
last_g = 0
last_b = 0

while True:
    for c in range(1, 5):
        for p in range(16):
            while True:
                r = random.choice([0, 127, 255])
                g = random.choice([0, 127, 255])
                b = random.choice([0, 127, 255])
                if (r != g or r != b
                        or g != b) and (r != last_r and b != last_b
                                        and g != last_g):
                    break

            m.set_pixel(c, p, r, g, b)
            last_r = r
            last_g = g
コード例 #17
0
ファイル: image-paint.py プロジェクト: AleksHolland84/mote
#!/usr/bin/env python
# Adapted from Adafruit's dotstar python example
# https://github.com/adafruit/Adafruit_DotStar_Pi

from PIL import Image
from mote import Mote
mote = Mote()

NUMPIXELS = 16  # Number of LEDs in strip
FILENAME = "hello.png"  # Image file to load

mote.configure_channel(1, NUMPIXELS, False)
mote.configure_channel(2, 0, False)
mote.configure_channel(3, 0, False)
mote.configure_channel(4, 0, False)

# Load image in RGB format and get dimensions:
print("Loading...")
img = Image.open(FILENAME).convert("RGB")
pixels = img.load()
width, height = img.size
ratio = width / height
print("Image is {}x{}".format(width, height))

if height > NUMPIXELS:
    height = NUMPIXELS
    width = int(height * ratio)
    img.resize((width, height))
    print("Resized to {}x{}".format(width, height))

# Calculate gamma correction table, makes mid-range colors look 'right':
コード例 #18
0
ファイル: motemeter.py プロジェクト: clivemjeffery/soundlevel
import time
from mote import Mote

mote = Mote()
mote.configure_channel(1, 16, False)
mote.configure_channel(2, 16, False)
mote.configure_channel(3, 16, False)
mote.configure_channel(4, 16, False)
mote.clear()


def clamp16(n):
    return max(min(16, n), 0)


def moteset(n, r, g, b):
    # strip 1 (increasing pixels)
    r1 = clamp16(n)  # values between 1 and 16
    for pixel in range(r1):
        mote.set_pixel(1, pixel, r, g, b)
    # strip 2 (inc.)
    r2 = clamp16(n - 16)  # values between 17 and 32
    for pixel in range(r2):
        mote.set_pixel(2, pixel, r, g, b)
    # strip 3 (decreasing pixels)
    r3 = clamp16(n - 32)  # values between 33 and 48
    for pixel in range(15, 15 - r3, -1):
        mote.set_pixel(3, pixel, r, g, b)
    # strip 4 (dec.)
    r4 = clamp16(n - 48)  # values betwene 47 and 64
    for pixel in range(15, 15 - r4, -1):
コード例 #19
0
ファイル: soft-cheerlights.py プロジェクト: RogueM/mote
try:
    import requests
except ImportError:
    exit("This script requires the requests module\nInstall with: sudo pip install requests")

from mote import Mote


mote = Mote()

num_pixels = 16

transition_time = 1 # seconds
transition_step = 100

mote.configure_channel(1, num_pixels, False)
mote.configure_channel(2, num_pixels, False)
mote.configure_channel(3, num_pixels, False)
mote.configure_channel(4, num_pixels, False)

try:
    channels_colour_rgb = [[0,0,0], [0,0,0], [0,0,0], [0,0,0]]
    channels_colour = [[0,0,0], [0,0,0], [0,0,0], [0,0,0]]
    channels_colour_delta = [[0,0,0], [0,0,0], [0,0,0], [0,0,0]]
    old_channels_colour = [[0,1,0], [0,1,0], [0,1,0], [0,1,0]]
    while True:
        r = requests.get('http://api.thingspeak.com/channels/1417/feed.json')
        j = r.json()
        f = j['feeds'][-8:]

        f = [element for index, element in enumerate(f) if index%2==0]