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
| int inter=0;
int inter1=1;
double val;
double time;
double time1;
int a=0,b=0,angle;
void setup()
{
noInterrupts();
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
interrupts();
attachInterrupt(inter,stateChange,RISING);
attachInterrupt(inter1,stateChange1,FALLING);
Serial.begin(9600);
}
void loop()
{
val = analogRead(A0);
angle=map(val, 0, 1023, 0, 180);
Serial.println(angle);
if (a==1)
{val = analogRead(A0);
val = map(val, 0, 1023, 0, 9);
time=9-val;
time1=val;
digitalWrite(9,LOW);
delay(time1);
digitalWrite(9,HIGH);
delay(time);
digitalWrite(9,LOW);
a=0;
}
if(b==1)
{val = analogRead(A0);
val = map(val, 0, 1023, 0, 9);
time=9-val;
time1=val;
digitalWrite(10,LOW);
delay(time1);
digitalWrite(10,HIGH);
delay(time);
digitalWrite(10,LOW);
b=0;
}
}
void stateChange()
{
a=1;
}
void stateChange1()
{
b=1;
} |