cansat_B 2019 / Mbed 2 deprecated tougou-no3

Dependencies:   mbed

Revision:
5:9b5899b06e2e
Parent:
4:75090ff74dd0
Child:
6:cf43f62b1e75
--- a/main.cpp	Thu Nov 28 08:59:56 2019 +0000
+++ b/main.cpp	Fri Nov 29 19:08:28 2019 +0000
@@ -2,23 +2,29 @@
 #include "JPEGCamera.h"
 #include "us015.h"
 #include "TB6612.h"
+#include <stdio.h>
+#include <base64.h>
+
 DigitalOut myled(LED1);
 US015 hs(p12,p11);
 DigitalIn thermo(p20);
-DigitalOut Sb612switch(p15);//焦電スイッチ
+DigitalOut Sb612switch(p15);         //焦電スイッチ
 DigitalOut Ultra(p12);
-Serial pc(USBTX,USBRX); // tx, rx
-JPEGCamera camera(p9, p10); // TX, RX
-TB6612 left(p25,p17,p16);//モーターピン
-TB6612 right(p26,p19,p18);//モーターピン
+Serial pc(USBTX,USBRX);              // tx, rx
+JPEGCamera camera(p9, p10);          // TX, RX
+TB6612 left1(p25,p17,p16);            //モーターピン
+TB6612 right1(p26,p19,p18);           //モーターピン
+Serial xbee(p13,p14);                //xbee
+
 int main(){
   int i=1;
   float th;
   Timer tm;
   for(i=0;i<3;i++){
   pc.printf("start\r\n");
-  left = 100; //左モーター100%
-  right = 100;//右モーター100%
+  
+  left1 = 100; //左モーター100%
+  right1 = 100;//右モーター100%
  
     Sb612switch=0; //焦電off
     Ultra=1;//超音波on
@@ -32,8 +38,8 @@
          printf("distance=%d\r\n",distance);//距離出力
         
         if(distance<=2000){//超音波反応
-         left = 0; //左モーター0%
-         right = 0;//右モーター0%
+         left1 = 0; //左モーター0%
+         right1 = 0;//右モーター0%
          printf("停止\n\r");
          wait(5.0);
          
@@ -53,11 +59,15 @@
                Timer timer;
                timer.start();
                camera.setPictureSize(JPEGCamera::SIZE320x240);
+               
+               FILE *fp;
+               base64 *bs;
+               int c;
 
-            
+            for (int r = 0; r < 1; r++) {
                if (camera.isReady()) {
                  char filename[32];
-                 sprintf(filename, "/local/pict%03d.jpg",i);
+                 sprintf(filename, "/local/pict%03d.jpg",r);
                  printf("Picture: %s ", filename);
                  if (camera.takePicture(filename)) { 
                   while (camera.isProcessing()) {
@@ -73,23 +83,39 @@
                
                printf("time = %f\n", timer.read());
                
+       
+               
+               xbee.printf("xbee connected!\r\n");
+               bs = new base64();
+               bs->Encode("/local/pict000.jpg","/local/data000.txt");
+               
+               if((fp=fopen("/local/data000.txt","r"))!=NULL)
+               {
+                   pc.printf("ok\r\n");
+                   while((c=fgetc(fp))!=EOF){
+                       xbee.printf("%c",c);
+                    }
+                    fclose(fp);
+                }
+                }
+               
               }else{//焦電反応なしの場合
               printf("not found!\r\n");
                
-               left = 70; //左モーター10%
-               right = 100;//右モーター100%(右折)
+               left1 = 70; //左モーター10%
+               right1 = 100;//右モーター100%(右折)
                Sb612switch=0;
                Ultra=1;
                detected=false;
                printf("右折\n\r");
                wait(3.0);
-               left = 100; //左モーター100%
-               right = 100;//右モーター100%
+               left1 = 100; //左モーター100%
+               right1 = 100;//右モーター100%
               }           
        }else{//超音波distance>2000
           printf("safety zone\r\n");
-          left = 100; //左モーター100%
-          right = 70;//右モーター70%(左折)
+          left1 = 100; //左モーター100%
+          right1 = 70;//右モーター70%(左折)
           printf("左折\r\n");
          }
 
@@ -100,4 +126,5 @@
 
  
   }
+  
  
\ No newline at end of file