Exemple #1
0
GOAL_PIXEL_WIDTH = BAND_PIXEL_WIDTH + 2.0
GOAL_BRIGHTNESS = 0.1

# The percentage of the new angle (between 0.0 and 1.0) to apply to the last angle
# Has the effect of smoothing out the reading, at the cost of making it slower to react
SMOOTHING_FACTOR = 0.1

# Pick *one* LED type by uncommenting the relevant line below:

# APA102 / DotStar™ LEDs
led_strip = plasma.APA102(NUM_LEDS, 0, 0, plasma2040.DAT, plasma2040.CLK)

# WS2812 / NeoPixel™ LEDs
# led_strip = plasma.WS2812(NUM_LEDS, 0, 0, plasma2040.DAT)

user_sw = Button(plasma2040.USER_SW, repeat_time=0)
button_a = Button(plasma2040.BUTTON_A, repeat_time=0)
button_b = Button(plasma2040.BUTTON_B, repeat_time=0)
led = RGBLED(plasma2040.LED_R, plasma2040.LED_G, plasma2040.LED_B)

PINS_PLASMA2040 = {"sda": plasma2040.SDA, "scl": plasma2040.SCL}

i2c = PimoroniI2C(**PINS_PLASMA2040)
msa = BreakoutMSA301(i2c)

ANGLE, VELOCITY = range(2)


# Maps a value from one range to another
def map(x, in_min, in_max, out_min, out_max):
    return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
Exemple #2
0
# The speed that the LEDs will start cycling at
DEFAULT_SPEED = 10

# How many times the LEDs will be updated per second
UPDATES = 60

# Pick *one* LED type by uncommenting the relevant line below:

# APA102 / DotStar™ LEDs
# led_strip = plasma.APA102(NUM_LEDS, 0, 0, plasma2040.DAT, plasma2040.CLK)

# WS2812 / NeoPixel™ LEDs
led_strip = plasma.WS2812(NUM_LEDS, 0, 0, plasma2040.DAT)

user_sw = Button(plasma2040.USER_SW)
button_a = Button(plasma2040.BUTTON_A)
button_b = Button(plasma2040.BUTTON_B)
led = RGBLED(plasma2040.LED_R, plasma2040.LED_G, plasma2040.LED_B)
sense = Analog(plasma2040.CURRENT_SENSE, plasma2040.ADC_GAIN,
               plasma2040.SHUNT_RESISTOR)

# Start updating the LED strip
led_strip.start()

speed = DEFAULT_SPEED
offset = 0.0

count = 0
# Make rainbows
while True:
    YELLOW = display.create_pen(255, 216, 0)
    GREEN = display.create_pen(0, 121, 64)
    INDIGO = display.create_pen(36, 64, 142)
    VIOLET = display.create_pen(115, 41, 130)
    PINK = display.create_pen(255, 175, 200)
    BLUE = display.create_pen(116, 215, 238)
    LITEYL = display.create_pen(200, 200, 0)
    MAGENTA = display.create_pen(255, 33, 140)
    CYAN = display.create_pen(33, 177, 255)
    col_base = [display.create_pen(0, 0, 255)] * 10
# Buttons
if osname.find('Tufty 2040') > 0:
    button_a = Pin(7, Pin.IN, Pin.PULL_DOWN)
    button_b = Pin(8, Pin.IN, Pin.PULL_DOWN)
    button_c = Pin(9, Pin.IN, Pin.PULL_DOWN)
    button_up = Button(22, invert=False)
    button_down = Button(6, invert=False)
    BACKL = 0.5
    display.set_backlight(BACKL)
else:
    button_b = Pin(6, Pin.IN, Pin.PULL_UP)
    button_c = Pin(7, Pin.IN, Pin.PULL_UP)
    STblank = PWM(Pin(backlight, Pin.OUT))  # re-define
    STblank.freq(500)
    STblank.duty_u16(20000)
    BACKL = 20000
    if osname.find('fake') > 0:
        WHITE = display.create_pen(220, 220, 255)

set_clock = False
Cur = 4  # minute
Exemple #4
0
# Micropython - see https://learn.pimoroni.com/article/plasma-2040
#
# adapted from examples on that page

import plasma
from plasma import plasma2040
from pimoroni import RGBLED, Button

NUM_LEDS = 50

led = RGBLED(plasma2040.LED_R, plasma2040.LED_G, plasma2040.LED_B)
led.set_rgb(0, 0, 0)

button_a = Button(plasma2040.BUTTON_A)
button_b = Button(plasma2040.BUTTON_B)
button_boot = Button(plasma2040.USER_SW)

led_strip = plasma.WS2812(NUM_LEDS, 0, 0, plasma2040.DAT)

led_strip.start()

while True:
    if button_a.read():
        for i in range(NUM_LEDS):
            led_strip.set_rgb(i, 255, 0, 0)
        led.set_rgb(255, 0, 0)
    if button_b.read():
        for i in range(NUM_LEDS):
            led_strip.set_rgb(i, 0, 255, 0)
        led.set_rgb(0, 255, 0)
    if button_boot.read():
import time

# Import plasma2040
from plasma import plasma2040

# Import helpers for RGB LEDs and Buttons
from pimoroni import RGBLED, Button

led = RGBLED(plasma2040.LED_R, plasma2040.LED_G, plasma2040.LED_B)
led.set_rgb(0, 0, 0)

user_sw = Button(plasma2040.USER_SW)
button_a = Button(plasma2040.BUTTON_A)
button_b = Button(plasma2040.BUTTON_B)

while True:
    if user_sw.read():
        print("Pressed User SW - {}".format(time.ticks_ms()))
        led.set_rgb(255, 0, 0)
    if button_a.read():
        print("Pressed A - {}".format(time.ticks_ms()))
        led.set_rgb(0, 255, 0)
    if button_b.read():
        print("Pressed B - {}".format(time.ticks_ms()))
        led.set_rgb(0, 0, 255)
Exemple #6
0
PRESSURE_HUE_START = 0.333
PRESSURE_HUE_END = 0.0

# The start and end hues for the humidity range
HUMIDITY_HUE_START = 0.333
HUMIDITY_HUE_END = 0.667

# Pick *one* LED type by uncommenting the relevant line below:

# APA102 / DotStar™ LEDs
# led_strip = plasma.APA102(NUM_LEDS, 0, 0, plasma2040.DAT, plasma2040.CLK)

# WS2812 / NeoPixel™ LEDs
led_strip = plasma.WS2812(NUM_LEDS, 0, 0, plasma2040.DAT)

button_a = Button(plasma2040.BUTTON_A, repeat_time=0)
button_b = Button(plasma2040.BUTTON_B, repeat_time=0)
led = RGBLED(plasma2040.LED_R, plasma2040.LED_G, plasma2040.LED_B)

PINS_PLASMA2040 = {"sda": plasma2040.SDA, "scl": plasma2040.SCL}

i2c = PimoroniI2C(**PINS_PLASMA2040)
bme = BreakoutBME68X(i2c)

ALL, TEMPERATURE, PRESSURE, HUMIDITY = range(4)


# Maps a value from one range to another
def map(x, in_min, in_max, out_min, out_max):
    return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min