기본 구성 분석 (module)
module BlinkM { <- 모듈을 정의.
provides { <- 나를 콘트롤 할 것.
interface StdControl;
}
uses { <- 내가 사용할 것들.
interface Timer;
interface Leds;
}
}
implementation {
int i=0; <- 전역변수
command result_t StdControl.init() { <- 초기화
call Leds.init();
return SUCCESS;
}
command result_t StdControl.start() { <- 시작
return call Timer.start(TIMER_REPEAT, 1000);
}
command result_t StdControl.stop() { <- 종료
call Leds.init();
return call Timer.stop();
}
event result_t Timer.fired() { <- 타이머가 호출되면 실행 (기본적으로 무한 루프)
call Leds.blueOff();
call Leds.redOff();
call Leds.yellowOff();
if((i%2)==1)
call Leds.blueOn();
if((i/2)>=1 && (i/2)%2!=0)
call Leds.redOn();
if((i/4)>=1)
call Leds.yellowOn();
i++;
if(i==8)
i=0;
return SUCCESS;
}
}