Testing for publishing

Dependencies:   mbed

Committer:
atalkingdog
Date:
Sun May 23 16:37:52 2021 +0000
Revision:
1:e8cbe60decea
Parent:
0:7b3def60ac72
dd

Who changed what in which revision?

UserRevisionLine numberNew contents of line
atalkingdog 0:7b3def60ac72 1 #include "mbed.h"
atalkingdog 0:7b3def60ac72 2
atalkingdog 1:e8cbe60decea 3 DigitalIn r1Ray(D2);//RaySensor
atalkingdog 1:e8cbe60decea 4 DigitalIn r2Ray(D3);
atalkingdog 1:e8cbe60decea 5 DigitalIn mRay(D4);
atalkingdog 1:e8cbe60decea 6 DigitalIn l2Ray(D11);
atalkingdog 1:e8cbe60decea 7 DigitalIn l1Ray(D6);
atalkingdog 1:e8cbe60decea 8 DigitalOut RA(D7);//DCMotocontroler
atalkingdog 1:e8cbe60decea 9 DigitalOut RB(D12);
atalkingdog 1:e8cbe60decea 10 DigitalOut LA(D9);
atalkingdog 1:e8cbe60decea 11 DigitalOut LB(D10);
atalkingdog 1:e8cbe60decea 12 PwmOut Right(A5);
atalkingdog 1:e8cbe60decea 13 PwmOut Left(A6);
atalkingdog 1:e8cbe60decea 14 DigitalOut text(D13);
atalkingdog 1:e8cbe60decea 15 void judgement();
atalkingdog 1:e8cbe60decea 16 void turnRight();
atalkingdog 1:e8cbe60decea 17 void turnLeft();
atalkingdog 1:e8cbe60decea 18 void moveForward();
atalkingdog 1:e8cbe60decea 19 void rush();
atalkingdog 1:e8cbe60decea 20 void rightMoto(int,int);
atalkingdog 1:e8cbe60decea 21 void leftMoto(int,int);
atalkingdog 0:7b3def60ac72 22
atalkingdog 0:7b3def60ac72 23 int main() {
atalkingdog 1:e8cbe60decea 24 while ((r1Ray == 0)||(r2Ray == 0))
atalkingdog 1:e8cbe60decea 25 judgement();
atalkingdog 1:e8cbe60decea 26 turnRight();
atalkingdog 1:e8cbe60decea 27 while (((r1Ray == 0)||(r2Ray == 0))||((l1Ray == 0)||(l2Ray == 0)))
atalkingdog 1:e8cbe60decea 28 judgement();
atalkingdog 1:e8cbe60decea 29 rush();
atalkingdog 1:e8cbe60decea 30 while (((r1Ray == 0)||(r2Ray == 0))||((l1Ray == 0)||(l2Ray == 0)))
atalkingdog 1:e8cbe60decea 31 judgement();
atalkingdog 1:e8cbe60decea 32 rush();
atalkingdog 1:e8cbe60decea 33 while ((r1Ray == 0)||(r2Ray == 0))
atalkingdog 1:e8cbe60decea 34 judgement();
atalkingdog 1:e8cbe60decea 35 turnRight();
atalkingdog 1:e8cbe60decea 36 while (((r1Ray == 0)||(r2Ray == 0))||((l1Ray == 0)||(l2Ray == 0)))
atalkingdog 1:e8cbe60decea 37 judgement();
atalkingdog 1:e8cbe60decea 38 rush();
atalkingdog 1:e8cbe60decea 39 while ((r1Ray == 0)||(r2Ray == 0))
atalkingdog 1:e8cbe60decea 40 judgement();
atalkingdog 1:e8cbe60decea 41 turnRight();
atalkingdog 1:e8cbe60decea 42 while ((r1Ray == 0)||(r2Ray == 0))
atalkingdog 1:e8cbe60decea 43 judgement();
atalkingdog 1:e8cbe60decea 44 turnRight();
atalkingdog 1:e8cbe60decea 45 while (((r1Ray == 0)||(r2Ray == 0))||((l1Ray == 0)||(l2Ray == 0)))
atalkingdog 1:e8cbe60decea 46 judgement();
atalkingdog 1:e8cbe60decea 47 rush();
atalkingdog 1:e8cbe60decea 48 }
atalkingdog 1:e8cbe60decea 49 void rightMoto(int a,int b){
atalkingdog 1:e8cbe60decea 50 switch (a)
atalkingdog 1:e8cbe60decea 51 {
atalkingdog 1:e8cbe60decea 52 case 1:
atalkingdog 1:e8cbe60decea 53 RB = 1;
atalkingdog 1:e8cbe60decea 54 RA = 0;
atalkingdog 1:e8cbe60decea 55 break;
atalkingdog 1:e8cbe60decea 56 case -1:
atalkingdog 1:e8cbe60decea 57 RB = 0;
atalkingdog 1:e8cbe60decea 58 RA = 1;
atalkingdog 1:e8cbe60decea 59 break;
atalkingdog 1:e8cbe60decea 60 case 0:
atalkingdog 1:e8cbe60decea 61 RB = 1;
atalkingdog 1:e8cbe60decea 62 RA = 1;
atalkingdog 1:e8cbe60decea 63 break;
atalkingdog 1:e8cbe60decea 64 }
atalkingdog 1:e8cbe60decea 65 Right.period(0.1);
atalkingdog 1:e8cbe60decea 66 Right = (float)b/100;
atalkingdog 1:e8cbe60decea 67 }
atalkingdog 1:e8cbe60decea 68 void leftMoto(int a,int b){
atalkingdog 1:e8cbe60decea 69 switch (a)
atalkingdog 1:e8cbe60decea 70 {
atalkingdog 1:e8cbe60decea 71 case 1:
atalkingdog 1:e8cbe60decea 72 LB = 1;
atalkingdog 1:e8cbe60decea 73 LA = 0;
atalkingdog 1:e8cbe60decea 74 break;
atalkingdog 1:e8cbe60decea 75 case -1:
atalkingdog 1:e8cbe60decea 76 LB = 0;
atalkingdog 1:e8cbe60decea 77 LA = 1;
atalkingdog 1:e8cbe60decea 78 break;
atalkingdog 1:e8cbe60decea 79 case 0:
atalkingdog 1:e8cbe60decea 80 LB = 1;
atalkingdog 1:e8cbe60decea 81 LA = 1;
atalkingdog 1:e8cbe60decea 82 break;
atalkingdog 1:e8cbe60decea 83 }
atalkingdog 1:e8cbe60decea 84 Left.period(0.1);
atalkingdog 1:e8cbe60decea 85 Left = (float)b/100;
atalkingdog 1:e8cbe60decea 86 }
atalkingdog 1:e8cbe60decea 87 void moveForward(){
atalkingdog 1:e8cbe60decea 88 rightMoto(1,70);
atalkingdog 1:e8cbe60decea 89 leftMoto(1,70);
atalkingdog 1:e8cbe60decea 90 }
atalkingdog 1:e8cbe60decea 91 void judgement(){
atalkingdog 1:e8cbe60decea 92 if (r1Ray == 1)
atalkingdog 1:e8cbe60decea 93 {
atalkingdog 1:e8cbe60decea 94 rightMoto(1,30);
atalkingdog 1:e8cbe60decea 95 leftMoto(1,80);
atalkingdog 1:e8cbe60decea 96 }
atalkingdog 1:e8cbe60decea 97 else if (l1Ray == 1)
atalkingdog 1:e8cbe60decea 98 {
atalkingdog 1:e8cbe60decea 99 rightMoto(1,80);
atalkingdog 1:e8cbe60decea 100 leftMoto(1,30);
atalkingdog 1:e8cbe60decea 101 }
atalkingdog 1:e8cbe60decea 102 else if (r2Ray == 1)
atalkingdog 1:e8cbe60decea 103 {
atalkingdog 1:e8cbe60decea 104 rightMoto(1,50);
atalkingdog 1:e8cbe60decea 105 leftMoto(1,70);
atalkingdog 1:e8cbe60decea 106 }
atalkingdog 1:e8cbe60decea 107 else if (l2Ray == 1)
atalkingdog 1:e8cbe60decea 108 {
atalkingdog 1:e8cbe60decea 109 rightMoto(1,70);
atalkingdog 1:e8cbe60decea 110 leftMoto(1,50);
atalkingdog 1:e8cbe60decea 111 }
atalkingdog 1:e8cbe60decea 112 else
atalkingdog 1:e8cbe60decea 113 {
atalkingdog 1:e8cbe60decea 114 moveForward();
atalkingdog 0:7b3def60ac72 115 }
atalkingdog 0:7b3def60ac72 116 }
atalkingdog 1:e8cbe60decea 117 void turnLeft(){
atalkingdog 1:e8cbe60decea 118 rightMoto(1,70);
atalkingdog 1:e8cbe60decea 119 leftMoto(0,0);
atalkingdog 1:e8cbe60decea 120 wait(0.4);
atalkingdog 1:e8cbe60decea 121
atalkingdog 1:e8cbe60decea 122 }
atalkingdog 1:e8cbe60decea 123 void turnRight(){
atalkingdog 1:e8cbe60decea 124 rightMoto(0,0);
atalkingdog 1:e8cbe60decea 125 leftMoto(1,70);
atalkingdog 1:e8cbe60decea 126 wait(0.4);
atalkingdog 1:e8cbe60decea 127 }
atalkingdog 1:e8cbe60decea 128 void rush(){
atalkingdog 1:e8cbe60decea 129 moveForward();
atalkingdog 1:e8cbe60decea 130 wait(0.3);
atalkingdog 1:e8cbe60decea 131 }