0

I have a type error but can't seem to fix it.

from microbit import *
import random
import radio

radio.on()

randomnummer = 0

while True:
    if accelerometer.current_gesture("shake"):
        #geschud (feelsgoodman)
        randomnummer = random.randint(0,2)

        #output test
        display.show(str(randomnummer))
        sleep(1000)
        display.clear()

        if randomnummer == 0:
            #vuur jammie
            #display.show(Image.HAPPY) als test
            display.show(Image.HAPPY)

        elif randomnummer == 1:
            #grasjes
            #display.show(Image.ANGRY) als test
            display.show(Image.ANGRY)

        elif randomnummer == 2:
            #watra
            #display.show(Image.HEART) als test
            display.show(Image.HEART)

        else:
            #error omg
            #display.show(Image.SAD) als test
            display.show(Image.SAD)

    else:
        #niet geschud (feelsbadman)
        display.show("-")


sleep(500)

The radio isn't yet implemented, but I get the error on the line:

if accelerometer.current_gesture("shake"):

I hope some of you might see the mistake I just made here.

4

1 回答 1

1

accelerometer.current_gesture() 是一个返回当前手势名称的函数,而不是比较它。您应该自己进行比较:

if accelerometer.current_gesture() == "shake":

我个人对 microbit 一无所知,但你可以尝试一下,如果它有效,那么一切都很好。

于 2019-02-05T16:27:07.247 回答