Ch3_3. 타이머로 LED 깜박이는시간 조절하기
학습 내용
mbed의 타이머기능을 이용하여 LED를 점등 시간을 조절하는 제어를 학습하게됩니다.
배선도
회로도
배선 사진
Flow Chart
코딩
#include "mbed.h" Ticker timer; DigitalOut led1(p6); DigitalIn button1(p16); DigitalIn button2(p17); void attime() { led1 = !led1; } int main() { volatile unsigned long Loop; int Cycle = 1; unsigned long data; data = 1 / Cycle; while(1) { button1.mode(PullUp); button2.mode(PullUp); timer.attach(&attime, data); if(button1 == 0) { Cycle++; for(Loop = 0; Loop < 200000; Loop++); } else if(button2 == 0) { Cycle--; for(Loop = 0; Loop < 200000; Loop++); } if(Cycle <= 0) { Cycle = 1; } } }
라이브러리
학습 참고
Please log in to post comments.