posted by nsakura 2010. 12. 2. 10:08


타이머 3개를 사용한 8진 카운터 입니다.

컴포넌트 및 와이어링.

configuration BlinkTimer {
}

implementation {

  components MainC, BlinkTimerM, LedsC, new TimerMilliC() as Timer0, new TimerMilliC() as Timer1, new TimerMilliC() as Timer2;
 
  BlinkTimerM.Boot -> MainC;
  BlinkTimerM.Leds -> LedsC;
  BlinkTimerM.Timer0->Timer0;
  BlinkTimerM.Timer1->Timer1;
  BlinkTimerM.Timer2->Timer2;
}

메인 프로그래.

module BlinkTimerM {
  uses {
 interface Boot;
 interface Timer<TMilli> as Timer0;
 interface Timer<TMilli> as Timer1;
 interface Timer<TMilli> as Timer2;
 interface Leds;
  }
}
implementation {

  event void Boot.booted() {
 call Timer0.startPeriodic(1000);
 call Timer1.startPeriodic(2000);
 call Timer2.startPeriodic(4000);
  }
  
  event void Timer0.fired()  {
    call Leds.led2Toggle();  
  }
 
  event void Timer1.fired()  {
    call Leds.led1Toggle();
  }

  event void Timer2.fired()  {
    call Leds.led0Toggle();    
  }

}

 R  sec  G  sec  Y   sec
 0  1  0  1  0   0 
 0  2  0  2  1  1
 0  3  1  1  0  0
 0  4  1  2  1  1
 1  1  0  1  0  0
 1  2  0  2  1  1
 1  3  1  1  0  0
 1  4  1  2  1  1