Example #1
0
def runorientation():
    global right
    global DispPosition
    global Orientation
    global samples
    while True:
        pressed = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT)

        if pressed & buttons.BOTTOM_LEFT != 0:
            DispPosition[0] = midpointX
            DispPosition[1] = midpointY

        if pressed & buttons.BOTTOM_RIGHT != 0:
            calibrate()
            vibra.vibrate(10)

        if len(samples) > 0:
            Value = [0, 0, 0]
            sample = samples[0]  # take the first sample
            Value[1] = -(Orientation[1]) + sample.y  # + (int(counter/10))# y
            Value[2] = -(Orientation[2]) + sample.z  # + (int(counter/10))# x
            if Value[2] < -2:  # Check if orientation is right and normalize x data
                set_X(int(-Value[2]))
                right = True
            if Value[2] > 2:  # Check if orientation is left and normalize x data
                set_X(int(-Value[2]))
                right = False
            if (sample.y < -2) or (sample.y > 2):  # normalize y data
                set_Y(int(-Value[1]))

        draw_cat(DispPosition[0], DispPosition[1])
        # check_Border()
        play()
Example #2
0
 def run(self):
     while True:
         self.draw()
         utime.sleep_ms(sleep_time_ms)
         b_pressed = buttons.read(buttons.BOTTOM_LEFT
                                  | buttons.BOTTOM_RIGHT)
         alive = self.step(b_pressed)
         if not alive:
             vibra.vibrate(100)
             self.disp.rect(0,
                            0,
                            physical_width,
                            physical_height,
                            col=color.RED)
             self.disp.print("DED", bg=color.RED)
             self.disp.print("Length: {}".format(len(self.pos)),
                             bg=color.RED,
                             posy=30)
             self.disp.update()
             utime.sleep_ms(1000)
             buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT
                          | buttons.TOP_RIGHT)  # clear the queue
             while True:
                 b_pressed = buttons.read(buttons.BOTTOM_LEFT
                                          | buttons.BOTTOM_RIGHT
                                          | buttons.TOP_RIGHT)
                 if b_pressed:
                     break
             break
Example #3
0
def leds_on():
    vibra.vibrate(60)
    leds.set_all([[255, 180, 0], [255, 180, 0], [255, 180, 0], [255, 180, 0],
                  [255, 180, 0], [255, 180, 0], [255, 180, 0], [255, 180, 0],
                  [255, 180, 0], [255, 180, 0], [255, 180, 0]])
    disp.backlight(100)
    disp.clear(color.YELLOW)
    disp.update()
Example #4
0
def calibrate():
    global Orientation
    # samples = sensors[sensor]["sensor"].read()
    if len(samples) > 0:
        vibra.vibrate(40)
        sample = samples[0]
        Orientation[2] = sample.z
        Orientation[1] = sample.y
        with display.open() as disp:
            disp.clear()
            disp.print("Calibration successful", posy=20)
            disp.update()
    utime.sleep(1)
Example #5
0
def process_covid_data(mac, service_data, rssi, flags):
    global vib_mode
    global packet_count

    if vib_mode in [MODE_ON_RX, MODE_BOTH]:
        vibra.vibrate(10)

    if vib_mode in [MODE_ON_NEW_MAC, MODE_BOTH] and mac not in seen:
        vibra.vibrate(100)

    if led_mode in [MODE_ON_RX, MODE_BOTH]:
        leds.flash_rocket(0, 31, 20)

    if led_mode in [MODE_ON_NEW_MAC, MODE_BOTH] and mac not in seen:
        leds.flash_rocket(1, 31, 200)

    packet_count += 1

    # try to produce a small int
    last_rx_time = time.time() - t0
    if mac in seen:
        print(bytes2hex(mac, ":"), rssi, bytes2hex(service_data), flags,
              seen[mac][1] + 1)
        seen[mac][0] = int(last_rx_time)
        seen[mac][1] += 1  # increase counter
        seen[mac][2][0] = max(seen[mac][2][0], rssi)
        seen[mac][2][1] = (seen[mac][2][1] + rssi) / 2
        seen[mac][2][2] = min(seen[mac][2][2], rssi)
        seen[mac][3][1] = time.unix_time()
    else:
        print(bytes2hex(mac, ":"), rssi, bytes2hex(service_data), flags, "1")
        # The elements are
        # - last rx time
        # - seen count
        # - rssi
        #   - max
        #   - avg
        #   - min
        # - timestamps
        #   - first seen
        #   - last seen
        # - flags
        # - service data
        seen[mac] = [
            int(last_rx_time), 1, [rssi, rssi, rssi],
            [time.unix_time(), time.unix_time()], flags, service_data
        ]
    # disp.print("Left=Lower", posy=-10, fg=[0, 255, 255])
    # stuff_in_string = f"Vibe Speed \n  {vibration_speed}."
    stuff_in_string = "Vibe Speed \n  {vibration_speed}."
    disp.print(stuff_in_string, posy=0, fg=[0, 255, 255])


def goSlower():
    if vibration_speed > 1:
        vibration_speed = vibration_speed - 1


def goFaster():
    vibration_speed = vibration_speed + 1


while True:
    disp.clear()
    headline()
    v = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT)
    if v == 0:
        button_pressed = False
    if not button_pressed and v & buttons.BOTTOM_LEFT != 0:
        button_pressed = True
        goSlower()
    if not button_pressed and v & buttons.BOTTOM_RIGHT != 0:
        button_pressed = True
        goFaster()

    vibra.vibrate(100)
    utime.sleep_ms(vibration_speed)