this is made by seminal03_2015_SIT_mechanical_engineering

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 /*センサ安定時間*/
00004 #define INIT 30.0
00005 /*ノイズ検出用*/
00006 #define NOISE 0.5
00007 /*センサ再読み取り時間*/
00008 #define DELAY 0.5
00009 
00010 Serial pc(USBTX, USBRX); 
00011 
00012 Ticker flipper;
00013 Timer t1;
00014 Timer t2;
00015 DigitalIn pA (p19);
00016 DigitalIn pB (p20);
00017 DigitalOut led1 (LED1);
00018 DigitalOut led2 (LED2);
00019 
00020 void flip(){
00021     led1 = !led1;
00022     }
00023 
00024 //VAout hosei 
00025 int main(void)
00026 {
00027     flipper.attach(&flip,0.3);     
00028     wait(INIT);
00029     flipper.detach();
00030     
00031     double valpA;
00032 //    double valpB;
00033     double timehigh;
00034     double timelow; 
00035     double t;
00036     
00037     double sumvalA;   
00038 
00039     int a = 0;
00040   
00041     printf("high time no sokutei\n");
00042     while(1)
00043     {
00044         while(pA == 1){}
00045         while(pA != 1){}        
00046         t1.start();
00047         while(pA == 1){}
00048         t=t1.read();
00049         pc.printf("t1=%f\n",t);
00050         while(a == 0 || t >0.5)
00051         {
00052             if(pA != 1 )
00053             {
00054                 t2.start();
00055                 while(pA != 1){}
00056                 t2.stop();
00057                 timelow = t2.read();
00058                 pc.printf("lowtime=%f\n",timelow);
00059                 if(timelow > 0.4){
00060                     t1.stop();
00061                     timehigh = t1.read() - t2.read();
00062                     pc.printf("timehigh = %f\n",timehigh);
00063                     a ++;
00064                 }else{
00065                     pc.printf("continue\r\n");
00066                 }
00067             t2.reset();
00068             t = t1.read();
00069             }
00070         }
00071         t1.reset();
00072     }
00073 /*  
00074     while(1){  
00075     if(pA == 1){
00076         valpA = pA.read();
00077         pc.printf("%2.1f\n",valpA);
00078     }
00079     wait(1);
00080     }
00081 */
00082 /*     
00083 
00084 int main() {
00085     
00086     int a = 0;
00087     int b = 0;
00088     int plus = 0;
00089 //    int minus = 0;
00090 //    int sum = 0;    
00091     led1 = 0;
00092     led2 = 0;
00093     led3 = 0;
00094     led4 = 0;
00095     
00096 
00097     pc.printf("a=%d b=%d\n",a,b);
00098     
00099 //    t.start(); //60sごとにループを抜ける
00100 
00101         while(t != 60){
00102             if(pA){
00103                 wait(NOISE);
00104                 if(pA){ 
00105                     a ++;
00106                     pc.printf("a=%d\n",a);
00107                     wait(DELAY);
00108                     if(pB){
00109                         wait(NOISE);
00110                         if(pB){
00111                             b ++;
00112                             pc.printf("b=%d\n",b);
00113                             wait(DELAY);
00114                             plus ++;
00115                             pc.printf("plus=%d\n",plus);
00116                         }
00117                     }
00118                 }
00119             wait(DELAY);
00120             }
00121         }
00122     
00123 }
00124 */
00125 }