test

Dependencies:   mbed Encoder

Files at this revision

API Documentation at this revision

Comitter:
maxnagazumi
Date:
Mon Dec 21 09:42:00 2020 +0000
Parent:
0:3dee13ff6060
Commit message:
1221;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 3dee13ff6060 -r acb2ca86725f main.cpp
--- a/main.cpp	Tue Dec 15 06:05:50 2020 +0000
+++ b/main.cpp	Mon Dec 21 09:42:00 2020 +0000
@@ -1,17 +1,19 @@
 #include "mbed.h"
 #include "EC.h"
 #define RESOLUTION 500
-#define V_ARRAY_COUNT_MAX 300
+#define V_ARRAY_COUNT_MAX 400
 
 Serial pc(USBTX, USBRX);
 DigitalIn Button1(p15);
 DigitalIn Button2(p16);
-DigitalOut clutch(p19);
+//DigitalOut clutch(p19);
+DigitalOut air(p20);
 PwmOut motord(p25);
 PwmOut motoru(p26);
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
 DigitalOut led3(LED3);
+DigitalOut led4(LED4);
 Ec1multi ec(p27,p28,RESOLUTION);
 Timer timer;
 
@@ -20,12 +22,15 @@
     motoru.period_us(50);
     Button1.mode(PullUp);
     Button2.mode(PullUp);
-    clutch=0;//on
+    //clutch=0;//on
+    air=1;//off
     led1=1;
     led2=1;
     led3=1;
+    led4=1;
     motoru=0;
     int motor_state=2;
+    int led_state=0;
     int omega;
     int read_v_state=0;
     pc.printf("ready to fire");
@@ -39,7 +44,10 @@
         if(Button1==0){
             led1=1;
             led2=0;
-            clutch=0;   //on
+            led3=0;
+            led4=0;
+            //clutch=0;   //on
+            air=0;//on
             count=0;
             motoru=0;
             motor_state=0;
@@ -48,29 +56,66 @@
         if(Button2==0){
             led2=1;
             led1=0;
+            led3=0;
+            led4=0;
             motoru=0.5;
             motor_state=1;
             pc.printf("start loading\r\n");
-        } 
+        }
+        if (motor_state == 1)
+        {
+            switch (led_state)
+            {
+            case 0:
+                led1 = 1;
+                led2 = 0;
+                led3 = 0;
+                led4 = 0;
+                break;
+            case 50:
+                led1 = 0;
+                led2 = 1;
+                led3 = 0;
+                led4 = 0;
+                break;
+            case 100:
+                led1 = 0;
+                led2 = 0;
+                led3 = 1;
+                led4 = 0;
+                break;
+            case 150:
+                led1 = 0;
+                led2 = 0;
+                led3 = 0;
+                led4 = 1;
+                break;
+            }
+            led_state++;
+            if(led_state>200)led_state=0;
+        }
         if (count>4500&&read_v_state==0){
             motoru=0;
             wait(3);
-            clutch=1;   //off
+            //clutch=1;   //off
+            air=1;//off
             motor_state=0;
+            led1=0;
+            led2=0;
             led3=0;
+            led4=0;
             pc.printf("fire\r\n");
             read_v_state=1;
             timer.reset();
             timer.start();
         }
-
         ec.calOmega();
-        wait_ms(10);
+        wait_ms(1);
         if (read_v_state == 1)
         {
             if (v_array_count < V_ARRAY_COUNT_MAX)
             {
-                v_array[v_array_count][0] = omega * 0.02;
+                v_array[v_array_count][0] = omega * 0.01;
                 v_array[v_array_count][1] = timer.read();
                 v_array_count++;
             }
@@ -79,11 +124,7 @@
                 pc.printf("time\tspeed\r\n");
                 for (int j = 0; j < V_ARRAY_COUNT_MAX; j++)
                 {
-                    if (v_array[j][0] != 0)
-                    {
-                        pc.printf("%f\t", v_array[j][1]);
-                        pc.printf("%f\r\n", v_array[j][0]);
-                    }
+                        pc.printf("%f\t%f\r\n", v_array[j][1],v_array[j][0]);
                 }
                 read_v_state = 0;
             }