Advertisement
cmass

무선 센서 장치(수신기) UP

Oct 23rd, 2019
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. from microbit import *
  2. import radio
  3. radio.on()  # 라디오 통신 켜기
  4.  
  5. while True:
  6.     msg = radio.receive()       # 라디오를 통해 수신된 메세지를 msg변수에 저장
  7.     if msg == 'temp':
  8.         temp = temperature()    # 온도 센서값을 temp라는 변수에 저장
  9.         radio.send(str(temp))   # temp 변숫값을 문자로 바꿔 라디오 전송
  10.         display.show('T')       # 디스플레이에 'T' 표시
  11.         sleep(3000)             # 3초 지연
  12.  
  13.     if msg == 'light':
  14.         light = display.read_light_level()  # 조도 센서값을 light라는 변수에 저장
  15.         radio.send(str(light))              # light 변숫값을 문자로 바꿔 라디오 전송
  16.         display.show('L')                   # 디스플레이에 'L' 표시
  17.         sleep(3000)                         # 3초 지연
  18.  
  19.     if msg == 'soil':
  20.         soil_moisture = pin0.read_analog()
  21.         # 0번핀에 연결된 토양 수분 센서값을 soil_moisture변수에 저장(범위 0~1023)
  22.         radio.send(str(soil_moisture))      # soil_moisture 변숫값을 문자로 바꿔 라디오 전송
  23.         display.show('S')                   # 디스플레이에 'S' 표시
  24.         sleep(3000)                         # 3초 지연
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement