1
2
3int ForwordSignal=A1;
4int BackwordSignal=A4;
5int LEDs=3;
6int ForwordMotor=4;
7int BackwordMotor=12;
8int code1;
9int cod2;
10int FM=0;
11int BM=0;
12int state=0;
13int testRelay=8;
14
15
16
17void setup() {
18
19 Serial.begin(9600);
20 pinMode(ForwordSignal,INPUT);
21 pinMode(BackwordSignal,INPUT);
22 pinMode(ForwordMotor,OUTPUT);
23 pinMode(BackwordMotor,OUTPUT);
24 pinMode(LEDs,OUTPUT);
25 pinMode(testRelay,OUTPUT);
26
27
28}
29
30void loop() {
31 FM=analogRead(ForwordSignal);
32 BM=analogRead(BackwordSignal);
33
34 Serial.println("B");
35 Serial.println("----");
36 Serial.println("F");
37
38 if(FM>200)
39 {
40 digitalWrite(ForwordMotor,HIGH);
41 digitalWrite(BackwordMotor,LOW);
42 digitalWrite(testRelay,LOW);
43
44 state=1;
45 Serial.print("FM is");
46 Serial.println(FM);
47
48 }else if(BM>200)
49 {
50 digitalWrite(BackwordMotor,HIGH);
51 digitalWrite(ForwordMotor,LOW);
52 ;
53
54 Serial.print("BM is");
55 Serial.println(BM);
56
57 state=2;
58 }else{digitalWrite(ForwordMotor,HIGH);
59 digitalWrite(BackwordMotor,HIGH);
60 digitalWrite(testRelay,HIGH);
61
62 };
63
64
65
66}