Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from microbit import *
- import radio
- radio.on() # 라디오 통신 켜기
- while True:
- msg = radio.receive() # 라디오를 통해 수신된 메세지를 msg변수에 저장
- if msg == 'temp':
- temp = temperature() # 온도 센서값을 temp라는 변수에 저장
- radio.send(str(temp)) # temp 변숫값을 문자로 바꿔 라디오 전송
- display.show('T') # 디스플레이에 'T' 표시
- sleep(3000) # 3초 지연
- if msg == 'light':
- light = display.read_light_level() # 조도 센서값을 light라는 변수에 저장
- radio.send(str(light)) # light 변숫값을 문자로 바꿔 라디오 전송
- display.show('L') # 디스플레이에 'L' 표시
- sleep(3000) # 3초 지연
- if msg == 'soil':
- soil_moisture = pin0.read_analog()
- # 0번핀에 연결된 토양 수분 센서값을 soil_moisture변수에 저장(범위 0~1023)
- radio.send(str(soil_moisture)) # soil_moisture 변숫값을 문자로 바꿔 라디오 전송
- display.show('S') # 디스플레이에 'S' 표시
- sleep(3000) # 3초 지연
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement