SHOW:
|
|
- or go back to the newest paste.
| 1 | from microbit import * | |
| 2 | light5 = Image("99999:99999:99999:99999:99999") #5단계 가장 밝게
| |
| 3 | light4 = Image("77777:77777:77777:77777:77777") #4단계 밝게
| |
| 4 | light3 = Image("55555:55555:55555:55555:55555") #3단계 밝게
| |
| 5 | light2 = Image("33333:33333:33333:33333:33333") #2단계 밝게
| |
| 6 | light1 = Image("11111:11111:11111:11111:11111") #1단계 밝게
| |
| 7 | light0 = Image("00000:00000:00000:00000:00000") #LED 모두 끄기
| |
| 8 | ||
| 9 | while True: | |
| 10 | level = display.read_light_level() #빛 센서 측정값을 level 변수에 저장 | |
| 11 | if level < 10: #빛 센서값이 10미만이면 | |
| 12 | display.show(light5) #디스플레이에 light5 이미지 출력(가장 밝게) | |
| 13 | elif level < 50: #빛 센서값이 10이상이면서 50미만이면 | |
| 14 | display.show(light4) #디스플레이에 light4 이미지 출력(4단계 밝게) | |
| 15 | elif level < 100: #빛 센서값이 50이상이면서 100미만이면 | |
| 16 | display.show(light3) #디스플레이에 light3 이미지 출력(3단계 밝게) | |
| 17 | elif level < 150: #빛 센서값이 100이상이면서 150미만이면 | |
| 18 | display.show(light2) #디스플레이에 light2 이미지 출력(2단계 밝게) | |
| 19 | elif level < 200: #빛 센서값이 150이상이면서 200미만이면 | |
| 20 | display.show(light1) #디스플레이에 light1 이미지 출력(1단계 밝게) | |
| 21 | else: #그렇지 않으면 | |
| 22 | display.show(light0) #디스플레이에 light0 이미지 출력(LED 끄기) | |
| 23 | ||
| 24 | sleep(1000) #1초 지연 |