Ejemplo n.º 1
0
# -*- coding: utf-8-*-# Encoding cookie added by Mu Editor
# from microbit import *
from microbit import display, sleep, pin8, pin12
import tinybit
import music
import neopixel

np = neopixel.NeoPixel(pin12, 2)
np.clear()
tinybit.car_HeadRGB(0, 0, 0)
tinybit.init_IR(pin8)
tinybit.car_stop()
display.off()

speed = 100
a = 0
music.play('c')


while True:
    # print(hex(tinybit.get_IR(pin8)))
    value = tinybit.get_IR(pin8)
    value = value >> 8

    # default
    if value == -0x01:
        a = a + 1
        if (a > 3):
            tinybit.car_stop()
            a = 0
    # long pressed
Ejemplo n.º 2
0
# -*- coding: utf-8-*-# Encoding cookie added by Mu Editor
from microbit import display, Image, pin12
import tinybit
import random
import neopixel

np = neopixel.NeoPixel(pin12, 2)
np.clear()
tinybit.car_HeadRGB(0, 0, 0)
display.show(Image.HAPPY)

item = 0


while True:
    voice = tinybit.getVoicedata()
    if voice > 100:
        item = random.randint(1, 6)
        tinybit.car_HeadRGB(random.randint(0, 255),
                            random.randint(0, 255),
                            random.randint(0, 255))
        red = random.randint(0, 255)
        green = random.randint(0, 255)
        blue = random.randint(0, 255)
        np[0] = (red, green, blue)
        np[1] = (red, green, blue)
        np.show()

    if item == 1:
        display.show(Image.HEART)
    elif item == 2:
Ejemplo n.º 3
0
# -*- coding: utf-8-*-# Encoding cookie added by Mu Editor
from microbit import display, Image, pin12, sleep
import tinybit
import neopixel

np = neopixel.NeoPixel(pin12, 2)
np.clear()
tinybit.car_HeadRGB(0, 0, 0)
display.show(Image.HAPPY)
delay = 80

level_0 = Image("00000:00000:00000:00000:00000")
level_1 = Image("00000:00000:00000:00000:09990")
level_2 = Image("00000:00000:00000:00900:99999")
level_3 = Image("00000:00000:00000:09990:99999")
level_4 = Image("00000:00000:00900:99999:99999")
level_5 = Image("00000:00000:99999:99999:99999")
level_6 = Image("00000:09990:99999:99999:99999")
level_7 = Image("00900:99999:99999:99999:99999")
level_8 = Image("99999:99999:99999:99999:99999")

while True:
    voice = tinybit.getVoicedata()
    if voice < 10:
        tinybit.car_stop()
        np.clear()
        tinybit.car_HeadRGB(0, 0, 0)
        display.show(level_0)
    elif voice >= 10 and voice < 40:
        display.show(level_1)
        tinybit.car_HeadRGB(0, 0, 50)
Ejemplo n.º 4
0
# -*- coding: utf-8-*-# Encoding cookie added by Mu Editor
from microbit import display, Image, pin12
import tinybit
import neopixel

np = neopixel.NeoPixel(pin12, 2)
np.clear()
tinybit.car_HeadRGB(0, 0, 0)
display.show(Image.HEART)


while True:
    left = tinybit.traking_sensor_L()
    right = tinybit.traking_sensor_R()

    if left is False and right is False:
        tinybit.car_run(90)
    elif left is True and right is False:
        tinybit.car_spinleft(80)
    elif left is False and right is True:
        tinybit.car_spinright(80)
    else:
        tinybit.car_stop()