from microbit import * import math # 30.03.2021 compass.is_calibrated() sleep(2000) # -- COMMUNICATION - cannot be changed spd = 4 # comm speed min. 4 - max. speed def ispis(tekst): dd = len(tekst) if dd < 31: salji(tekst) else: salji(tekst[0:30] + "+") salji(tekst[30:dd]) def salji(tekst): global spd duz = len(tekst) buf = bytearray(duz) for n in range(0, duz): bb = ord(tekst[n : n + 1]) buf[n] = bb try: i2c.write(0x11, buf) sleep(duz * spd) except OSError: print("er: salji") #----- sleep(200) ispis("CLS") sleep(100) #------------------- pi = 3.1415 x1 = 57 y1 = 24 ispis("COMPASS;0;0") ispis("CIR;57;24;20;B") ispis("CIR;57;24;22;B") ispis("CIR;57;24;1;B;B") sleep(100) while True: xx = compass.heading() n = 360 - xx rad = (pi / 180) * n y2 = math.sin(rad)*18+y1 x2 = math.cos(rad)*18+x1 ispis("LIN;"+str(x1)+";"+str(y1)+";"+str(x2)+";"+str(y2)+";B") sleep(100) ispis("CIR;57;24;1;B;B") sleep(400) ispis("LIN;"+str(x1)+";"+str(y1)+";"+str(x2)+";"+str(y2)+";W") sleep(100)