Exemple #1
0
from mindwave import BluetoothHeadset


def GetColorsForAttentionLevel(attention):
    redlevel = int((point.attention - 33) * 255 / 33.0)
    redlevel = max(min(redlevel, 255), 0)
    bluelevel = 255 - redlevel
    return redlevel, 0, bluelevel


led_strip = LedStrip("/dev/spidev0.0", 20)
# Set lights to a soft white to indicate the program is starting,
# but not reading your mind yet.
led_strip.setAll((64, 64, 64))
led_strip.update()
headset = BluetoothHeadset()
while True:
    point = headset.readDatapoint()
    if not point or not point.clean():
        print(
            "Not getting clean data yet. If you see this at startup, wait ~20s. "
            "If it persists, adjust the headset for a better fit.")
        led_strip.setAll((64, 64, 64))
        led_strip.update()
        continue
    print "Attention:", point.attention
    r, g, b = GetColorsForAttentionLevel(point.attention)
    print "Coloring LEDS to RGB:", (r, g, b)
    led_strip.setAll((g, b, r))  # LED strip uses funky ordering
    led_strip.update()