2025년 4월 8일 화요일

가속도 센서




소스 코드 예시
from microbit import *
import music

while True:
    music.pitch(accelerometer.get_y(), 10)



소스 코드 예시
from microbit import *

while True:
    gesture = accelerometer.current_gesture()
    if gesture == "face up":
       display.show(Image.HAPPY)
    else:
        display.show(Image.ANGRY)



소스 코드 예시
from microbit import *

while True:
    reading = accelerometer.get_x()
    if reading > 20:
        display.show("R")
    elif reading < -20:
        display.show("L")
    else:
        display.show("-")



소스 코드 예시
from microbit import *
import random

dice1 = Image("00000:00000:00900:00000:00000")
dice2 = Image("90000:00000:00000:00000:00009")
dice3 = Image("90000:00000:00900:00000:00009")
dice4 = Image("90009:00000:00000:00000:90009")
dice5 = Image("90009:00000:00900:00000:90009")
dice6 = Image("90909:00000:00000:00000:90909")
dice = [dice1, dice2, dice3, dice4, dice5, dice6]

while True:
    if accelerometer.was_gesture("shake"):
        display.show(random.choice(dice))



소스 코드 예시
from microbit import *
import random

weather_forecasts = [
"Sunny with a high of 25°C",
"Cloudy with a chance of rain",
"Rain showers expected",
"Clear skies tonight",
"Stormy weather approaching",
"Snow likely in the evening",
"Partly cloudy with mild temperatures",
"High winds throughout the day",
"Foggy conditions in the morning",
"Thunderstorms in the afternoon",
]

while True:
    display.show(Image.CLOUD)
    if accelerometer.was_gesture("shake"):
        display.clear()
        sleep(1000)
        display.scroll(random.choice(weather_forecasts))





댓글 없음:

댓글 쓰기