Пример #1
0
# 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


# Shows a band and goal with the given widths at the positions on the strip
Пример #2
0
# 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:
    sw = user_sw.read()
    a = button_a.read()
    b = button_b.read()