mech / Mbed 2 deprecated line_trace3

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
isshikiyuya
Date:
Mon Dec 10 19:00:48 2018 +0000
Commit message:
a

Changed in this revision

function.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/function.h	Mon Dec 10 19:00:48 2018 +0000
@@ -0,0 +1,47 @@
+#include "mbed.h"
+
+///////////////////////////////////////
+int count1 = 0;
+int count2 = 0;
+int distance1 = 0;
+int distance2 = 0;
+int distance = 0;
+
+void flip1() {
+    count1++;
+    distance1++;
+}
+
+void flip2() {
+    count2++;
+    distance2++;
+}
+
+
+
+/*
+class Sample{
+    private:
+        count;
+    public:
+        Sample();
+        void counter();
+        void counter2(int &num);
+};
+
+Sample::Sample()
+{
+    count=0;
+}
+
+void Sample::counter()
+{
+    count++;
+}
+
+void Sample::counter2(int& num)
+{
+    num+=1;
+}
+
+*/
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Dec 10 19:00:48 2018 +0000
@@ -0,0 +1,124 @@
+#include "function.h"
+
+PwmOut pwm11(D5);           //左正転
+PwmOut pwm12(D1);           //左逆転
+PwmOut pwm21(D6);           //右正転
+PwmOut pwm22(D9);           //右逆転
+DigitalOut LED(D2);
+InterruptIn button1(A1);    //フォトインタラプタ
+InterruptIn button2(A2);    //フォトインタラプタ
+AnalogIn   in1(A6);         //フォトリフレクタ左
+AnalogIn   in2(A4);         //フォトリフレクタ真ん中
+AnalogIn   in3(A3);         //フォトリフレクタ右
+
+float thr1 = 0.40f;
+float thr2 = 0.60f;
+float thr3 = 0.40f;
+int judge1 = 0;
+int judge2 = 0;
+int judge3 = 0;
+
+int main() {
+    pwm11.period(0.01f);  //100Hz
+    pwm12.period(0.01f);  //100Hz
+    pwm21.period(0.01f);  //100Hz
+    pwm22.period(0.01f);  //100Hz
+    button1.rise(&flip1);
+    button2.rise(&flip2);
+    int n;//3biteで状態を表現
+    
+    while(1) {
+        
+        if(  count1 + count2 > 43*2*12){ //200mm毎にLEDを点滅
+        LED = 1.0f;
+        wait(0.5f);
+        LED = 0;
+        count1 = 0;
+        count2 = 0;
+        }
+//////////////////floatのinをintのjudgeに変換
+        if(in1 > thr1){
+            judge1 = 1;
+            }
+         else{
+            judge1 = 0;
+            }
+            if(in2 > thr2){
+            judge2 = 1;
+            }
+         else{
+            judge2 = 0;
+            }
+            if(in3 > thr3){
+            judge3 = 1;
+            }
+         else{
+            judge3 = 0;
+            }
+/////////////////
+        n = judge1 + judge2*2 + judge3*4;
+   /*     distance = (distance1 + distance2) / 2;
+        if(ditance < 43*12*){
+            */
+            switch(n){
+              case(2)://白黒白進む
+              pwm11.write(0.60f);
+              pwm12.write(0.30f);
+              pwm21.write(0.60f);
+              pwm22.write(0.30f);
+              break;
+              
+              case(0)://白白白
+              pwm11.write(0.10f);
+              pwm12.write(0.10f);
+              pwm21.write(0.10f);
+              pwm22.write(0.10f);
+              break;
+              
+              
+            
+              case(1)://黒白白左回転
+              pwm11.write(0.30f);
+              pwm12.write(0.30f);
+              pwm21.write(0.60f);
+              pwm22.write(0.30f);
+              break;
+            
+              case(4)://白白黒右回転
+              pwm11.write(0.60f);
+              pwm12.write(0.30f);
+              pwm21.write(0.30f);
+              pwm22.write(0.30f);
+              break;
+              
+              case(3)://黒黒白左回転             
+              pwm11.write(0.30f);
+              pwm12.write(0.30f);
+              pwm21.write(0.60f);
+              pwm22.write(0.30f);
+              break;
+              
+              case(6)://白黒黒右回転
+              pwm11.write(0.60f);
+              pwm12.write(0.30f);
+              pwm21.write(0.30f);
+              pwm22.write(0.30f);
+              break;
+              
+              case(7)://黒黒黒走る
+              pwm11.write(0.60f);
+              pwm12.write(0.30f);
+              pwm21.write(0.60f);
+              pwm22.write(0.30f);
+              break;
+               
+              default://それ以外(ないけど)
+              pwm11.write(0.00f);
+              pwm12.write(0.00f);
+              pwm21.write(0.00f);
+              pwm22.write(0.00f);
+              break;
+              
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Dec 10 19:00:48 2018 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed/builds/a330f0fddbec
\ No newline at end of file