085ccbfa
thubert
ajout des sources...
|
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
|
#define SERVO1 2
#define SERVO2 3
#define CYCLE 10
void setp() {
Serial.begin(9600);
pinMode(SERVO1, OTPT);
pinMode(SERVO2, OTPT);
}
void loop() {
int posx=90;
int posy=90;
while(1){
if (Serial.available()!=0){
char data=Serial.read();
delay(2);
while(Serial.available()==0){
switch(data){
case('h') : posx-=2;
if(posx>180)posx=180;
break;
case('b') : posx+=2;
if(posx<0)posx=0;
break;
case('g') : posy--;
if(posy>180)posy=180;
break;
case('d') : posy++;
if(posy<0)posy=0;
break;
}
if(posx>180)posx=180;
if(posx<0)posx=0;
if(posy>180)posy=180;
if(posy<0)posy=0;
setPosition(posx,posy);
}
}
}
}
void setPosition(int positx,int posity){
int tempx= map(positx,180,0,1550,900);
int tempy= map(posity,180,0,2400,700);
/*Serial.print(tempx);
Serial.print("<X Y>");
Serial.println(tempy);*/
digitalWrite(SERVO1,1);
delayMicroseconds(tempx);
digitalWrite(SERVO1,0);
digitalWrite(SERVO2,1);
delayMicroseconds(tempy);
digitalWrite(SERVO2,0);
delay(CYCLE);
}
|