-
Notifications
You must be signed in to change notification settings - Fork 0
/
ir_based_motor_control1.ino
96 lines (78 loc) · 1.36 KB
/
ir_based_motor_control1.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include<IRremote.h>
const int recvpin=6;
int val;
int n;
int m;
int a;
const int motor1 = 9;
const int motor2 = 10;
IRrecv irrecv(recvpin);
decode_results results;
void setup()
{
Serial.begin(9600);
Serial.println("Enabling IRin:");
irrecv.enableIRIn();
Serial.println("Enabled IRin:");
pinMode(motor1, OUTPUT);
pinMode(motor2, OUTPUT);
val=175;
a=0;
m=0;
n=0;
}
void loop()
{
if(irrecv.decode(&results))
{
Serial.println(results.value,DEC);
// play
if(results.value==16621663 && m==0)
{
// n= digitalRead(motor1);
// analogWrite(motor1, 0);
m=1;
a=1;
}
else if ( results.value==16621663 && m==1)
{
// n= digitalRead(motor1);
// analogWrite(motor1, 0);
m=0;
a=0;
analogWrite(motor1, 0);
analogWrite(motor2, 0);
}
if(results.value==16601263)
{
val=val+10;
}
if(results.value==16584943)
{
val=val-10;
}
if(results.value==16589023)
{
n=1;
}
if(results.value==16605343)
{
n=0;
}
if(a==1 && n==0)
{
analogWrite(motor1, val);
analogWrite(motor2, 0);
}
if(a==1 && n==1)
{
analogWrite(motor2, val);
analogWrite(motor1, 0);
}
Serial.println(m);
Serial.println(n);
Serial.println(a);
Serial.println(val);
irrecv.resume();
}
}