タームAのプログラム

Dependencies:   mbed

Committer:
12f2025e
Date:
Thu Sep 29 07:23:54 2016 +0000
Revision:
0:a1535b0b1c12
???A??????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
12f2025e 0:a1535b0b1c12 1 //リフト上げ条件センサ2つ
12f2025e 0:a1535b0b1c12 2
12f2025e 0:a1535b0b1c12 3 #include "mbed.h"
12f2025e 0:a1535b0b1c12 4
12f2025e 0:a1535b0b1c12 5 DigitalIn in1(PTE21);//左
12f2025e 0:a1535b0b1c12 6 DigitalIn in2(PTE20);//左中
12f2025e 0:a1535b0b1c12 7 DigitalIn in3(PTE23);//右中
12f2025e 0:a1535b0b1c12 8 DigitalIn in4(PTE22);//右
12f2025e 0:a1535b0b1c12 9
12f2025e 0:a1535b0b1c12 10 DigitalOut led1(PTB8);//左
12f2025e 0:a1535b0b1c12 11 DigitalOut led2(PTB9);//左中
12f2025e 0:a1535b0b1c12 12 DigitalOut led3(PTB10);//右中
12f2025e 0:a1535b0b1c12 13 DigitalOut led4(PTB11);//右
12f2025e 0:a1535b0b1c12 14
12f2025e 0:a1535b0b1c12 15 BusOut cmotor(PTA1,PTA2);
12f2025e 0:a1535b0b1c12 16 PwmOut vc(PTD4);
12f2025e 0:a1535b0b1c12 17 BusOut lmotor(PTC0,PTC7);
12f2025e 0:a1535b0b1c12 18 PwmOut vl(PTA12);
12f2025e 0:a1535b0b1c12 19 BusOut rmotor(PTC6,PTC5);
12f2025e 0:a1535b0b1c12 20 PwmOut vr(PTA4);
12f2025e 0:a1535b0b1c12 21
12f2025e 0:a1535b0b1c12 22 int main() {
12f2025e 0:a1535b0b1c12 23 while(1) {
12f2025e 0:a1535b0b1c12 24 if(in1 == 1)//黒の時光る 1:白 0:黒
12f2025e 0:a1535b0b1c12 25 led1 = 0;//1:光る 0:光らない
12f2025e 0:a1535b0b1c12 26 else
12f2025e 0:a1535b0b1c12 27 led1 = 1;
12f2025e 0:a1535b0b1c12 28
12f2025e 0:a1535b0b1c12 29 if(in2 == 1)
12f2025e 0:a1535b0b1c12 30 led2 = 0;
12f2025e 0:a1535b0b1c12 31 else
12f2025e 0:a1535b0b1c12 32 led2 = 1;
12f2025e 0:a1535b0b1c12 33
12f2025e 0:a1535b0b1c12 34 if(in3 == 1)
12f2025e 0:a1535b0b1c12 35 led3 = 0;
12f2025e 0:a1535b0b1c12 36 else
12f2025e 0:a1535b0b1c12 37 led3 = 1;
12f2025e 0:a1535b0b1c12 38
12f2025e 0:a1535b0b1c12 39 if(in4 == 1)
12f2025e 0:a1535b0b1c12 40 led4 = 0;
12f2025e 0:a1535b0b1c12 41 else
12f2025e 0:a1535b0b1c12 42 led4 = 1;
12f2025e 0:a1535b0b1c12 43
12f2025e 0:a1535b0b1c12 44 ///////////////////////
12f2025e 0:a1535b0b1c12 45 if(in2 == 0 && in3 == 0)
12f2025e 0:a1535b0b1c12 46 {
12f2025e 0:a1535b0b1c12 47 lmotor = 0;
12f2025e 0:a1535b0b1c12 48 vl = 0.0f;
12f2025e 0:a1535b0b1c12 49 rmotor = 1;
12f2025e 0:a1535b0b1c12 50 vr = 0.1f;
12f2025e 0:a1535b0b1c12 51 }
12f2025e 0:a1535b0b1c12 52 else if(in2 == 0 && in3 == 1)
12f2025e 0:a1535b0b1c12 53 {
12f2025e 0:a1535b0b1c12 54 lmotor = 0;
12f2025e 0:a1535b0b1c12 55 vl = 0.0f;
12f2025e 0:a1535b0b1c12 56 rmotor = 1;
12f2025e 0:a1535b0b1c12 57 vr = 0.1f;
12f2025e 0:a1535b0b1c12 58 }
12f2025e 0:a1535b0b1c12 59 else if(in2 == 1 && in3 == 0)
12f2025e 0:a1535b0b1c12 60 {
12f2025e 0:a1535b0b1c12 61 lmotor = 1;
12f2025e 0:a1535b0b1c12 62 vl = 0.1f;
12f2025e 0:a1535b0b1c12 63 rmotor = 1;
12f2025e 0:a1535b0b1c12 64 vr = 0.1f;
12f2025e 0:a1535b0b1c12 65 }
12f2025e 0:a1535b0b1c12 66 else
12f2025e 0:a1535b0b1c12 67 {
12f2025e 0:a1535b0b1c12 68 lmotor = 1;
12f2025e 0:a1535b0b1c12 69 vl = 0.1f;
12f2025e 0:a1535b0b1c12 70 rmotor = 0;
12f2025e 0:a1535b0b1c12 71 vr = 0.0f;
12f2025e 0:a1535b0b1c12 72 }
12f2025e 0:a1535b0b1c12 73
12f2025e 0:a1535b0b1c12 74 if(in1 == 0 && in4 == 0)
12f2025e 0:a1535b0b1c12 75 {
12f2025e 0:a1535b0b1c12 76 cmotor = 1;
12f2025e 0:a1535b0b1c12 77 vc = 0.5f;
12f2025e 0:a1535b0b1c12 78 lmotor = 0;
12f2025e 0:a1535b0b1c12 79 vl = 0.0f;
12f2025e 0:a1535b0b1c12 80 rmotor = 0;
12f2025e 0:a1535b0b1c12 81 vr = 0.0f;
12f2025e 0:a1535b0b1c12 82 wait(0.5);
12f2025e 0:a1535b0b1c12 83 cmotor = 0;
12f2025e 0:a1535b0b1c12 84 vc = 0.0f;
12f2025e 0:a1535b0b1c12 85 lmotor = 0;
12f2025e 0:a1535b0b1c12 86 vl = 0.0f;
12f2025e 0:a1535b0b1c12 87 rmotor = 0;
12f2025e 0:a1535b0b1c12 88 vr = 0.0f;
12f2025e 0:a1535b0b1c12 89 wait(10);
12f2025e 0:a1535b0b1c12 90 }
12f2025e 0:a1535b0b1c12 91 }
12f2025e 0:a1535b0b1c12 92 }