[마이크로비트] 2컬러 LED(3mm) (센서 활용)
LED 동작 예제(5mm도 동일)
사용한 센서
회로도
블록 코드
자바 스크립트 코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | let red=pins.analogReadPin(AnalogPin.P0) let yellow=pins.analogReadPin(AnalogPin.P2) basic.forever(function(){ pins.analogWritePin(AnalogPin.P0,0) pins.analogWritePin(AnalogPin.P2,0) for(let i=0; i<=256; i++){ pins.analogWritePin(AnalogPin.P0,i) basic.pause(10) } for(let i=0; i<=256; i++){ pins.analogWritePin(AnalogPin.P0,255-i) basic.pause(10) } for(let i=0; i<=256; i++){ pins.analogWritePin(AnalogPin.P2,i) basic.pause(10) } for(let i=0; i<=256; i++){ pins.analogWritePin(AnalogPin.P2,255-i) basic.pause(10) } for(let i=0; i<=256; i++){ pins.digitalWritePin(DigitalPin.P0,i) pins.digitalWritePin(DigitalPin.P2,i) basic.pause(10) } for(let i=0; i<=256; i++){ pins.analogWritePin(AnalogPin.P0,255-i) pins.analogWritePin(AnalogPin.P2,255-i) basic.pause(10) } }) |