'Computer/Tiny OS'에 해당되는 글 6건

  1. 2010.12.02 [Tiny os] 5진 카운트 [타이머 한개]
  2. 2010.12.02 [Tiny os] 8진수 카운터 수정본 [타이머 한개]
posted by nsakura 2010. 12. 2. 09:36

8진 카운트에서 하나만 바꿔주면.. 5진카운터가 되죠. [타이머 하나]

module BlinkTimerM {
  uses {
 interface Boot;
 interface Timer<TMilli>;
 interface Leds;
  }
}
implementation {
  ncnt=0;
  event void Boot.booted() {
 call Timer.startPeriodic(1000);
  }
  
  event void Timer.fired()  {
 call Leds.led0Off();
 call Leds.led1Off();
 call Leds.led2Off();

    if(ncnt>3){
  call Leds.led0On();
 }
 if(ncnt%4>1){
  call Leds.led1On();
 }
 if(ncnt%2>0){
  call Leds.led2On();
 }
 
 ncnt++;

 if(ncnt==5){
  ncnt=0;
 }
   
  }

 
}

 R  G   Y   ncnt  G mod   Y mod  
 0  0  0  0  0  0
 0  0  1  1  1  1
 0  1  0  2  2  0
 0  1  1  3  3  1
 1  0  0  4  0  0
       5->0    





posted by nsakura 2010. 12. 2. 09:28


if 문이 너무 더러워서.. 수정합니다.

하나의 타이머로 작동

사실 시간부족으로 대충한걸 아직 까지 올려두었는데.. 헤헷`

module BlinkTimerM {
  uses {
 interface Boot;
 interface Timer<TMilli>;
 interface Leds;
  }
}
implementation {
  ncnt=0;
  event void Boot.booted() {
 call Timer.startPeriodic(1000);
  }
  
  event void Timer.fired()  {
 call Leds.led0Off();
 call Leds.led1Off();
 call Leds.led2Off();

    if(ncnt>3){
  call Leds.led0On();
 }
 if(ncnt%4>1){
  call Leds.led1On();
 }
 if(ncnt%2>0){
  call Leds.led2On();
 }
 
 ncnt++;

 if(ncnt==8){
  ncnt=0;
 }
   
  }
 
}

 R  G  Y  ncnt  G mod  Y mod
 0  0  0  0  0  0
 0  0  1  1  1  1
 0  1  0  2  2  0
 0  1  1  3  3  1
 1  0  0  4  0  0
 1  0  1  5  1  1
 1  1  0  6  2  0
 1  1  1  7  3  1
       8->0