안양어벤저스 / Mbed 2 deprecated Timer_copy

Dependencies:   mbed

Fork of Ticker_3 by Jiyoung Ahn

main.cpp

Committer:
ajy912
Date:
2017-10-15
Revision:
3:9be917b0d07a
Parent:
2:e94dce9a7464
Child:
4:af3ab097055c

File content as of revision 3:9be917b0d07a:

/* Ticker : 함수를 쓰는 시간에 시작하여 원하는 시간이 지나면 특정 함수를 호출하고 
다시 초기화 하여 원하는 시간이 되면 호출하는 것을 반복한다.*/

/*결과: red_LED 5초동안 깜빡이다가 green_LED 5초동안 깜빡이는 것을 반복*/


#include "mbed.h"

Ticker timer;
DigitalOut ledg(D3);
DigitalOut ledr(D2);

int flip=0;

void attime() {
   flip =!flip;
}

int main() {
    timer.attach(&attime,5); //메인 함수는 계속 실행이 되면서 5초 뒤에 attime을 호출한다. 반복적으로
    while(1) {
        if(flip==0)
        {
           ledr =! ledr;
           
        }
        
        else {
          
            ledg = !ledg;
            }
        
         wait(0.2);
          
             }
        
}