Esempio n. 1
0
def send_direction():
    """
    Send the direction which the probe is pointing to:
    direction_N, direction_NE, direction_E...
    """
    display.show(Image.ARROW_N)

    while True:
        sleep(100)
        if button_b.is_pressed():
            break # Back to the menu mode
        heading = compass.heading()
        if (heading > 337) or (heading <= 22):
            needle = "N"
        elif 22 < heading <= 67:
            needle = "NE"
        elif 67 < heading <= 112:
            needle = "E"
        elif 112 < heading <= 157:
            needle = "SE"
        elif 157 < heading <= 202:
            needle = "S"
        elif 202 < heading <= 247:
            needle = "SW"
        elif 257 < heading <= 292:
            needle = "W"
        elif 292 < heading <= 337:
            needle = "W"
        radio.send("dir_{}".format(needle))
    def findApproxFacingDirection(self):
        cardinal_direction = ""

        if compass.heading() > 315 or compass.heading() < 45:
            cardinal_direction = "N"
        elif compass.heading() > 225 and compass.heading() < 315:
            cardinal_direction = "W"
        elif compass.heading() > 135 and compass.heading() < 225:
            cardinal_direction = "S"
        elif compass.heading() > 45 and compass.heading() < 135:
            cardinal_direction = "E"

        return cardinal_direction
Esempio n. 3
0
 def get_data():
     x, y, z = accelerometer.get_values()
     return Data(
         Acc_X=x,
         Acc_Y=y,
         Acc_Z=z,
         # Acc_gesture=accelerometer.current_gesture(),
         Mag_X=compass.get_x(),
         Mag_Y=compass.get_x(),
         Mag_Z=compass.get_x(),
         Mag_heading=compass.heading())
Esempio n. 4
0
 
 a = button_a.was_pressed()
 b = button_b.was_pressed()
 if a == True and b == True:
     display.show(flash, delay=100, wait=False)
     sleep(random.randint(50, 350))
     microbit.display.clear()
     contValue = False
     
     
 elif a == True:
     display.show(flash, delay=100, wait=False)
     sleep(random.randint(50, 350))
     radio.send("allIn")
     while True:
         direction = compass.heading()
         soundPlay = False
         if button_a.was_pressed():
             display.show(flash, delay=100, wait=False)
             sleep(random.randint(50, 350))
             radio.send("end")
             break
         if pin0.is_touched():
             
             display.show(flash, delay=100, wait=False)
             sleep(random.randint(50, 350))
             soundPlay = True
         if soundPlay:
             choice = "1"
         else:
             choice = "0"
Esempio n. 5
0
        while button_a.is_pressed() or button_b.is_pressed():
            sleep(0.1)
        break

while True:

    while True:
        command = random.choice(commands)
        display.scroll(command[:2])

        start = running_time()
        diff = 0
        correct = False

        # Get current state for comparison
        start_bearing = compass.heading()
        start_x = accelerometer.get_x()
        start_y = accelerometer.get_y()
        while diff < WAIT_TIME:

            if command == "bop it":
                if button_a.is_pressed() and button_b.is_pressed():
                    correct = True
                    break
            elif command == "twist it":
                print(abs(compass.heading() - start_bearing))
                if abs(compass.heading() - start_bearing) >= 90:
                    correct = True
                    break
            elif command == "shake it":
                if accelerometer.current_gesture() == "shake":