소스 코드 예시
from microbit import *
while True:
sleep(100)
degrees = compass.heading()
if degrees < 45 or degrees > 315:
display.show('N')
elif degrees < 135:
display.show('E')
elif degrees < 225:
display.show('S')
else:
display.show('W')
소스 코드 예시
from microbit import *
compass.calibrate()
while True:
needle = ((15 - compass.heading()) // 30) % 12
display.show(Image.ALL_CLOCKS[needle])
소스 코드 예시
from microbit import *
compass.calibrate()
while True:
heading = compass.heading()
if heading < 45 or heading > 315:
display.show(Image.HAPPY)
else:
display.show(Image.SAD)
소스 코드 예시
from microbit import *
if compass.is_calibrated() == False:
compass.calibrate()
x = 2
y = 2
while True:
get_x = compass.get_x()
if get_x < -100:
if x != 4:
x = x + 1
elif get_x > 100:
if x != 0:
x = x - 1
get_y = compass.get_y()
if get_y < -100:
if y != 4:
y = y + 1
elif get_y > 100:
if y != 0:
y = y - 1
display.clear()
display.set_pixel(x,y,9)
sleep(100)
댓글 없음:
댓글 쓰기