Exemplo n.º 1
0
def sensors(**args):
    while True:
        with bhi160.BHI160Orientation(**args) as s:
            yield s, "Orientation"
        with bhi160.BHI160Accelerometer(**args) as s:
            yield s, "Accel"
        with bhi160.BHI160Gyroscope(**args) as s:
            yield s, "Gyro"
        with bhi160.BHI160Magnetometer(**args) as s:
            yield s, "Magnetic"
Exemplo n.º 2
0
        [34, 54, 28, 8, 28, 54, 34, 0], [57, 61, 5, 5, 63, 62, 0, 0],
        [50, 38, 46, 58, 50, 38, 0, 0], [16, 16, 124, 238, 130, 130, 0, 0],
        [0, 0, 0, 238, 238, 0, 0, 0], [130, 130, 238, 124, 16, 16, 0, 0],
        [64, 192, 128, 192, 64, 192, 128, 0], [14, 30, 50, 98, 50, 30, 14, 0]]

masks = [2**n for n in range(7, -1, -1)]

try:
    with open('pov_word', 'r') as f:
        msg_word = f.read()
except:
    msg_word = 'BOLLOCKS'

msg = list(map(ord, msg_word))

bhi = bhi160.BHI160Accelerometer(sample_rate=16, sample_buffer_len=1)


def pov_char(char, reverse=False):
    if reverse:
        col_seq = font[char][::-1]
    else:
        col_seq = font[char]
    for col in col_seq:
        for i in range(8):
            if masks[i] & col:
                leds.prep(i + 1, color.GREEN)
            else:
                leds.prep(i + 1, color.BLACK)
        leds.update()
        utime.sleep(0.0025)
Exemplo n.º 3
0
import displaybuffer
import utime
import bhi160

disp = displaybuffer.open()
column = 0
lasttiltx = 0
lasttilty = 0
bhi = bhi160.BHI160Accelerometer()

for i in range(40):
    disp.setbuff(i, i, 0xFF, 0xFF)

while True:
    step = 0

    sensorData = bhi.read()
    #print(sensorData)
    if sensorData:
        tiltx = sensorData[0].x
        tilty = sensorData[0].y
    else:
        tiltx = lasttiltx
        tilty = lasttilty

    res = 0
    if tilty > 0.2:
        res = disp.driftsouth()
    elif tilty < -0.2:
        res = disp.driftnorth()
    if tiltx > 0.2:
Exemplo n.º 4
0
import bhi160
import buttons
import display
import leds
import utime

# init
bhi = bhi160.BHI160Accelerometer(sample_rate=4)
disp = display.open()
leds.clear()
highest = 0

while True:
    # reset if button pressed
    pressed = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT)
    if pressed & buttons.BOTTOM_LEFT != 0: highest = 0

    # read accel
    samples = bhi.read()
    if len(samples) == 0:
        utime.sleep(0.25)
        continue

    for val in samples:
        complete = abs(val.x) + abs(val.y) + abs(val.z) - 1
        if complete > highest: highest = complete

    # update display
    disp.clear()
    disp.print("Slap force:", posy=0, fg=[255, 255, 255])
    disp.print("<- reset", posy=60, fg=[255, 0, 0])
Exemplo n.º 5
0
import bhi160
import display
import utime
import buttons
import leds
import os

from color import Color

disp = display.open()
sensor = 0

sensors = [
    # {"sensor": bhi160.BHI160Orientation(), "name": "Orientation"},
    {
        "sensor": bhi160.BHI160Accelerometer(),
        "name": "Accelerometer"
    },
    {
        "sensor": bhi160.BHI160Gyroscope(),
        "name": "Gyroscope"
    },
]

subtractors = [0.5, 128]

battery_color_good = [0, 230, 0]
battery_color_ok = [255, 215, 0]
battery_color_bad = [255, 0, 0]

Exemplo n.º 6
0
STATUS_COLORS = [
    color.RED,
    # Orange
    color.RED * 0.5 + color.YELLOW * 0.5,
    color.YELLOW,
    color.GREEN,
]

with contextlib.ExitStack() as cx:
    disp = cx.enter_context(display.open())

    args = {"sample_rate": 10, "sample_buffer_len": 20}

    sensor_iter = itertools.cycle([
        (cx.enter_context(bhi160.BHI160Orientation(**args)), "Orientation"),
        (cx.enter_context(bhi160.BHI160Accelerometer(**args)), "Accel"),
        (cx.enter_context(bhi160.BHI160Gyroscope(**args)), "Gyro"),
        (cx.enter_context(bhi160.BHI160Magnetometer(**args)), "Magnetic"),
    ])
    sensor, sensor_name = next(sensor_iter)

    for ev in simple_menu.button_events(timeout=0.1):
        # Pressing the bottom right button cycles through sensors
        if ev == buttons.BOTTOM_RIGHT:
            sensor, sensor_name = next(sensor_iter)

        samples = sensor.read()
        if not samples:
            continue

        sample = samples[-1]
Exemplo n.º 7
0
accel_x_trig = 0
accel_y_comp = GT
accel_y_trig = 7
accel_z_comp = DC
accel_z_trig = 0

# internal variables - do not change
start_time = 0
led_on = False
led_time = 0
blink_on = False
leds.set_powersave(eco=True)
disp = display.open()
pressed = buttons.read(buttons.TOP_RIGHT)
gyrodev = bhi160.BHI160Gyroscope(sample_rate=10)
acceldev = bhi160.BHI160Accelerometer(sample_rate=10)
gyro_str_format = "% 6d"
accel_str_format = "% 6.1f"
gyro_str = ""
accel_str = ""
act_gyro_str = ""
act_accel_str = ""

bufferdepth = int(sumtime / looptime)
gyro = ThreeAxisBuffer.ThreeAxisBuffer(bufferdepth, gyro_x_max, gyro_y_max,
                                       gyro_z_max)
accel = ThreeAxisBuffer.ThreeAxisBuffer(bufferdepth, accel_x_max, accel_y_max,
                                        accel_z_max)

null_sample = ThreeAxisBuffer.ThreeAxis(0, 0, 0)