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)
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 elif value == 0x10: tinybit.car_spinleft(speed, speed) # down elif value == 0x90: tinybit.car_back(speed, speed) # spinright elif value == 0x50: tinybit.car_spinright(speed, speed) # + elif value == 0x30: speed = speed + 40 if speed > 255: speed = 255 music.pitch(500) sleep(300) music.stop() else: music.pitch(226) sleep(300) music.stop()
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 while True: tinybit.car_run(150) display.show(Image.ARROW_S) sleep(1000) tinybit.car_back(150) display.show(Image.ARROW_N) sleep(1000) tinybit.car_left(150) display.show(Image.ARROW_E) sleep(1000) tinybit.car_right(150) display.show(Image.ARROW_W) sleep(1000) tinybit.car_spinleft(150) display.show(Image.ARROW_E) sleep(1000) tinybit.car_spinright(150) display.show(Image.ARROW_W) sleep(1000) tinybit.car_stop() display.clear() sleep(1000)