Commit 085ccbfab0c2cb82e7a6028ed6a486e871ccdedc
1 parent
0a7a4359
ajout des sources arduino
Showing
1 changed file
with
57 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,57 @@ |
1 | +#define SERVO1 2 | |
2 | +#define SERVO2 3 | |
3 | +#define CYCLE 10 | |
4 | + | |
5 | +void setp() { | |
6 | + Serial.begin(9600); | |
7 | + pinMode(SERVO1, OTPT); | |
8 | + pinMode(SERVO2, OTPT); | |
9 | +} | |
10 | + | |
11 | +void loop() { | |
12 | + int posx=90; | |
13 | + int posy=90; | |
14 | + while(1){ | |
15 | + if (Serial.available()!=0){ | |
16 | + char data=Serial.read(); | |
17 | + delay(2); | |
18 | + while(Serial.available()==0){ | |
19 | + switch(data){ | |
20 | + case('h') : posx-=2; | |
21 | + if(posx>180)posx=180; | |
22 | + break; | |
23 | + case('b') : posx+=2; | |
24 | + if(posx<0)posx=0; | |
25 | + break; | |
26 | + case('g') : posy--; | |
27 | + if(posy>180)posy=180; | |
28 | + break; | |
29 | + case('d') : posy++; | |
30 | + if(posy<0)posy=0; | |
31 | + break; | |
32 | + } | |
33 | + if(posx>180)posx=180; | |
34 | + if(posx<0)posx=0; | |
35 | + if(posy>180)posy=180; | |
36 | + if(posy<0)posy=0; | |
37 | + setPosition(posx,posy); | |
38 | + | |
39 | + } | |
40 | + } | |
41 | + } | |
42 | +} | |
43 | + | |
44 | +void setPosition(int positx,int posity){ | |
45 | + int tempx= map(positx,180,0,1550,900); | |
46 | + int tempy= map(posity,180,0,2400,700); | |
47 | + /*Serial.print(tempx); | |
48 | + Serial.print("<X Y>"); | |
49 | + Serial.println(tempy);*/ | |
50 | + digitalWrite(SERVO1,1); | |
51 | + delayMicroseconds(tempx); | |
52 | + digitalWrite(SERVO1,0); | |
53 | + digitalWrite(SERVO2,1); | |
54 | + delayMicroseconds(tempy); | |
55 | + digitalWrite(SERVO2,0); | |
56 | + delay(CYCLE); | |
57 | +} | ... | ... |