-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathSumo_Mode.ino
62 lines (54 loc) · 1.31 KB
/
Sumo_Mode.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//Motor A
int motorA1 = 2;
int motorA2 = 4;
int motorAenb = 3;
#define motorArpm 90 //Any value between 0 and 255
//Motor B
int motorB1 = 10;
int motorB2 = 11;
int motorBenb = 9;
#define motorBrpm 100 //Any value between 0 and 255
//IR sensor
#define IRsensor 12
void setup()
{
Serial.begin(9600);
pinMode(motorA1, OUTPUT);
pinMode(motorA2, OUTPUT);
pinMode(motorAenb, OUTPUT);
pinMode(motorB1, OUTPUT);
pinMode(motorB2, OUTPUT);
pinMode(motorBenb, OUTPUT);
pinMode(IRsensor, INPUT);
}
void loop()
{
int IRvalue = digitalRead(IRsensor);
if(IRvalue == HIGH)
{
analogWrite(motorAenb, 0);
analogWrite(motorBenb, 0);
delay(200);
digitalWrite(motorA1, HIGH);
digitalWrite(motorA2, LOW);
analogWrite(motorAenb, motorArpm);
digitalWrite(motorB1, LOW);
digitalWrite(motorB2, HIGH);
analogWrite(motorBenb, motorBrpm);
delay(1000);
digitalWrite(motorB1, HIGH);
digitalWrite(motorB2, LOW);
analogWrite(motorBenb, motorBrpm);
delay(400);
}
else
{
digitalWrite(motorA1, LOW);
digitalWrite(motorA2, HIGH);
analogWrite(motorAenb, motorArpm);
digitalWrite(motorB1, HIGH);
digitalWrite(motorB2, LOW);
analogWrite(motorBenb, motorBrpm);
}
Serial.println(IRvalue);
}