aaa

Dependencies:   mbed

Committer:
turnip
Date:
Sat Jun 01 03:06:00 2019 +0000
Revision:
0:9aec4ef78a5a
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
turnip 0:9aec4ef78a5a 1 #include "mbed.h"
turnip 0:9aec4ef78a5a 2 /*
turnip 0:9aec4ef78a5a 3 DigitalIn l1(PA_7,PullUp);
turnip 0:9aec4ef78a5a 4 DigitalIn l2(PA_6,PullUp);
turnip 0:9aec4ef78a5a 5 DigitalIn r1(PF_1,PullUp);
turnip 0:9aec4ef78a5a 6 DigitalIn r2(PA_0,PullUp);
turnip 0:9aec4ef78a5a 7 DigitalIn s1(PA_4,PullUp);
turnip 0:9aec4ef78a5a 8 DigitalIn s2(PA_1,PullUp);
turnip 0:9aec4ef78a5a 9 DigitalIn horyuu(PA_3,PullUp);
turnip 0:9aec4ef78a5a 10 */
turnip 0:9aec4ef78a5a 11
turnip 0:9aec4ef78a5a 12 PwmOut left1(PA_12);
turnip 0:9aec4ef78a5a 13 PwmOut left2(PB_0);
turnip 0:9aec4ef78a5a 14 PwmOut right1(PA_8);
turnip 0:9aec4ef78a5a 15 PwmOut right2(PF_0);
turnip 0:9aec4ef78a5a 16 /*
turnip 0:9aec4ef78a5a 17 PwmOut servo1(PA_11);
turnip 0:9aec4ef78a5a 18 PwmOut servo2(PB_5);
turnip 0:9aec4ef78a5a 19 */
turnip 0:9aec4ef78a5a 20 float max=0.7;
turnip 0:9aec4ef78a5a 21
turnip 0:9aec4ef78a5a 22 int main()
turnip 0:9aec4ef78a5a 23 {
turnip 0:9aec4ef78a5a 24 while(1) {
turnip 0:9aec4ef78a5a 25
turnip 0:9aec4ef78a5a 26 right1=0.6;
turnip 0:9aec4ef78a5a 27 right2=0;
turnip 0:9aec4ef78a5a 28 left1=0.6;
turnip 0:9aec4ef78a5a 29 left2=0;
turnip 0:9aec4ef78a5a 30
turnip 0:9aec4ef78a5a 31 /*if(l1.read()==0){
turnip 0:9aec4ef78a5a 32 wait(0.05);
turnip 0:9aec4ef78a5a 33 if(l1.read()==0){
turnip 0:9aec4ef78a5a 34 left1=max;
turnip 0:9aec4ef78a5a 35 left2=0;
turnip 0:9aec4ef78a5a 36 }
turnip 0:9aec4ef78a5a 37 }
turnip 0:9aec4ef78a5a 38 if(l2.read()==0){
turnip 0:9aec4ef78a5a 39 wait(0.05);
turnip 0:9aec4ef78a5a 40 if(l2.read()==0){
turnip 0:9aec4ef78a5a 41 left1=0;
turnip 0:9aec4ef78a5a 42 left2=max;
turnip 0:9aec4ef78a5a 43 }
turnip 0:9aec4ef78a5a 44 }
turnip 0:9aec4ef78a5a 45 if(r1.read()==0){
turnip 0:9aec4ef78a5a 46 wait(0.05);
turnip 0:9aec4ef78a5a 47 if(r1.read()==0){
turnip 0:9aec4ef78a5a 48 right1=max;
turnip 0:9aec4ef78a5a 49 right2=0;
turnip 0:9aec4ef78a5a 50 }
turnip 0:9aec4ef78a5a 51 }
turnip 0:9aec4ef78a5a 52 if(r2.read()==0){
turnip 0:9aec4ef78a5a 53 wait(0.05);
turnip 0:9aec4ef78a5a 54 if(r2.read()==0){
turnip 0:9aec4ef78a5a 55 right1=0;
turnip 0:9aec4ef78a5a 56 right2=max;
turnip 0:9aec4ef78a5a 57 }
turnip 0:9aec4ef78a5a 58 }
turnip 0:9aec4ef78a5a 59
turnip 0:9aec4ef78a5a 60 int count1=0;
turnip 0:9aec4ef78a5a 61 int old1=1;
turnip 0:9aec4ef78a5a 62 int now1=1;
turnip 0:9aec4ef78a5a 63
turnip 0:9aec4ef78a5a 64 if(s1.read()==0){
turnip 0:9aec4ef78a5a 65 old1=now1;
turnip 0:9aec4ef78a5a 66 now1=s1.read();
turnip 0:9aec4ef78a5a 67 if(now1 == 0 && old1 == 1) {
turnip 0:9aec4ef78a5a 68 wait(0.05);
turnip 0:9aec4ef78a5a 69 now1 = s1.read();
turnip 0:9aec4ef78a5a 70 if(now1 == 0){
turnip 0:9aec4ef78a5a 71 count1++;
turnip 0:9aec4ef78a5a 72 }
turnip 0:9aec4ef78a5a 73 }
turnip 0:9aec4ef78a5a 74 if(count1 == 1){
turnip 0:9aec4ef78a5a 75 servo1.pulsewidth_us(500);
turnip 0:9aec4ef78a5a 76 }else{
turnip 0:9aec4ef78a5a 77 servo1.pulsewidth_us(2400);
turnip 0:9aec4ef78a5a 78 count1=0;
turnip 0:9aec4ef78a5a 79 }
turnip 0:9aec4ef78a5a 80 }
turnip 0:9aec4ef78a5a 81
turnip 0:9aec4ef78a5a 82 int count2=0;
turnip 0:9aec4ef78a5a 83 int old2=1;
turnip 0:9aec4ef78a5a 84 int now2=1;
turnip 0:9aec4ef78a5a 85
turnip 0:9aec4ef78a5a 86 if(s2.read()==0){
turnip 0:9aec4ef78a5a 87 old2=now2;
turnip 0:9aec4ef78a5a 88 now2=s2.read();
turnip 0:9aec4ef78a5a 89 if(now2 == 0 && old2 == 1) {
turnip 0:9aec4ef78a5a 90 wait(0.05);
turnip 0:9aec4ef78a5a 91 now2 = s2.read();
turnip 0:9aec4ef78a5a 92 if(now2 == 0){
turnip 0:9aec4ef78a5a 93 count2++;
turnip 0:9aec4ef78a5a 94 }
turnip 0:9aec4ef78a5a 95 }
turnip 0:9aec4ef78a5a 96 if(count2 == 1){
turnip 0:9aec4ef78a5a 97 servo2.pulsewidth_us(500);
turnip 0:9aec4ef78a5a 98 }else{
turnip 0:9aec4ef78a5a 99 servo2.pulsewidth_us(2400);
turnip 0:9aec4ef78a5a 100 count2=0;
turnip 0:9aec4ef78a5a 101 }
turnip 0:9aec4ef78a5a 102 }
turnip 0:9aec4ef78a5a 103
turnip 0:9aec4ef78a5a 104 printf("motor=%f,%f,%f,%f\r\n",left1.read(),left2.read(),right1.read(),right2.read());
turnip 0:9aec4ef78a5a 105 */
turnip 0:9aec4ef78a5a 106 }
turnip 0:9aec4ef78a5a 107 }