def run_L(): display.show(show_L) global b if b == 1: sleep(1000) tinybit.car_run(speed_run) sleep(1000) tinybit.car_spinleft(speed_spin) sleep(400) tinybit.car_run(speed_run) sleep(1000) tinybit.car_stop() global b b = 0
def dodge(): # turn dodge_f = random.choice([tinybit.car_turnright, tinybit.car_turnleft]) dodge_f(200) time.sleep(0.1) # stop tinybit.car_run(0) # escape while (not tinybit.traking_sensor_L()) or (not tinybit.traking_sensor_R()): tinybit.car_run(100) tinybit.car_back(200) time.sleep(0.1) tinybit.car_run(0)
def run_Z(): display.show(show_Z) global b if b == 1: sleep(1000) tinybit.car_run(speed_run) sleep(1000) tinybit.car_spinright(speed_spin) sleep(500) tinybit.car_run(speed_run) sleep(1300) tinybit.car_spinleft(speed_spin) sleep(600) tinybit.car_run(speed_run) sleep(1300) tinybit.car_stop() global b b = 0
# default if value == -0x01: a = a + 1 if (a > 3): tinybit.car_stop() a = 0 # long pressed elif value == 0xff: a = 0 else: # off if value == 0x00: tinybit.car_HeadRGB(0, 0, 0) # up elif value == 0x80: tinybit.car_run(speed, speed) # light elif value == 0x40: tinybit.car_HeadRGB(255, 255, 255) # left elif value == 0x20: tinybit.car_left(speed) # buzzer elif value == 0xa0: music.pitch(698) sleep(400) music.stop() # right elif value == 0x60: tinybit.car_right(speed) # spinleft
from microbit import sleep, display, Image, pin12 import tinybit import music import neopixel np = neopixel.NeoPixel(pin12, 2) np.clear() tinybit.car_HeadRGB(0, 0, 0) while True: distance = tinybit.ultrasonic() if distance < 20: sleep(10) distance = tinybit.ultrasonic() if distance < 20: tinybit.car_stop() display.show(Image.NO) tinybit.car_HeadRGB(255, 0, 0) tinybit.car_back(100) music.pitch(523) sleep(500) tinybit.car_spinright(100) music.pitch(0) sleep(500) else: tinybit.car_HeadRGB(0, 255, 0) tinybit.car_run(100) music.pitch(0) display.show(Image.ARROW_S)
# -*- coding: utf-8-*-# Encoding cookie added by Mu Editor from microbit import display, Image, sleep import tinybit display.show(Image.HAPPY) while True: tinybit.car_run(0, 0) sleep(1000) tinybit.car_run(50, 50) sleep(1000) tinybit.car_run(100, 100) sleep(1000) tinybit.car_run(150, 100) sleep(1000) tinybit.car_run(200, 200) sleep(1000) tinybit.car_run(255, 255) sleep(1000)
def push(): display.show("P") tinybit.car_run(190) time.sleep(1) tinybit.car_run(0)
# -*- coding: utf-8-*-# Encoding cookie added by Mu Editor from microbit import display, Image import tinybit display.show(Image.ARROW_S) tinybit.car_run(150)
# -*- 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()