Dependencies:   mbed

main.cpp

Committer:
takeuchi
Date:
2012-07-12
Revision:
0:f7ec9f29e766

File content as of revision 0:f7ec9f29e766:

// CW03
// ._ moji hantei

#include "mbed.h"
#include "TextLCD0420.h"

#define ON 1
#define OFF 0
#define XON 0
#define XOFF 1
#define XHI 0
#define XLOW 1
#define HI 1
#define LOW 0

DigitalOut mled1(LED1);
DigitalOut mled2(LED2);
DigitalOut mled3(LED3);
DigitalOut mled4(LED4);
DigitalIn CW(p5);
DigitalIn SP_SELECT(p6);
DigitalIn GENGO_MODE(p7);
DigitalIn GENGO_SELECT(p8);

TextLCD lcd(p24, p25, p26, p27, p28, p29, p30,20,4); // rs, rw, e, d0, d1, d2, d3

int min_ms,max_ms;


void set_speed(){
  if(SP_SELECT==HI){
    min_ms=30;
    max_ms=90;
    lcd.locate(5,0);
    lcd.printf("H");
  }
  else if(SP_SELECT==LOW){
    min_ms=70;
    max_ms=210;
    lcd.locate(5,0);
    lcd.printf("L");
  }
}  

int main() {      
  
  int i,j;
  int scount,tan_sum,tanten;  
  
  i=0;
  j=0;
  tanten=80;
  tan_sum=0;
  
  lcd.cls();
  lcd.printf("*CW03");    
  set_speed();
  lcd.printf("\n");
    
  while(1){
        while(CW==XLOW){
        }
        
        scount=0;  
        mled1=ON;
        while(CW==XHI){
          wait_ms(1);
          scount++;
        }
        mled1=OFF;
        
        if(min_ms < scount && scount < max_ms){ 
          lcd.printf(".");
          tan_sum=tan_sum+scount;
          j++;
        }
        else if ( scount > tanten*2.0){
          lcd.printf("_");
          tan_sum=tan_sum+scount/3;
          j++;
        }
        
        scount=0;
        while(CW==XLOW){
          wait_ms(1);
          scount++;
          if(scount > tanten*10){
            break;
          }
        }                
        
        if(scount > tanten*2){
          lcd.printf(" ");
        }
        
        if(j==10){
          tanten=tan_sum/10;
          lcd.printf(" %3d ",tanten);
          tan_sum=0;
          j=0;
        }
  }//while 1
}//main