Hi,
ich habe mal eine Frage. Es gibt ja bei Arduino das Beispiel für die
Servo Ansteuerung.
Jetzt habe ich das Beispiel schon mal erweitert, das es für zwei Motoren
sein soll.
Die Daten für den Servo sollen seriell hinein kommen.
Wie schreibe ich das aber bei Arduino?
Ich bin total neu in Arduino und hab leider noch überhaupt keine
Erfahrungen. :(
Der Code sieht erstmal folgendermaßen aus:
1 | // Sweep
|
2 | // by BARRAGAN <http://barraganstudio.com>
|
3 | // This example code is in the public domain.
|
4 |
|
5 |
|
6 | #include <Servo.h>
|
7 |
|
8 | Servo myservo_links; // create servo object to control a servo
|
9 | // a maximum of eight servo objects can be created
|
10 | Servo myservo_rechts;
|
11 |
|
12 | int pos_links = 0; // variable to store the servo position
|
13 | int pos_rechts = 0;
|
14 |
|
15 | void setup()
|
16 | {
|
17 | myservo_links.attach(9); // attaches the servo on pin 9 to the servo object
|
18 | myservo_rechts.attach(10);
|
19 | }
|
20 |
|
21 |
|
22 | void loop()
|
23 | {
|
24 |
|
25 | ///////////////////////////////
|
26 | //Eingabe muss erfolgen!!!
|
27 | //
|
28 | //////////////////////////////
|
29 |
|
30 | // linker Servo:
|
31 |
|
32 | for(pos_links = 0; pos_links < 180; pos_links += 1) // goes from 0 degrees to 180 degrees
|
33 | { // in steps of 1 degree
|
34 | myservo_links.write(pos_links); // tell servo to go to position in variable 'pos_links'
|
35 | delay(15); // waits 15ms for the servo to reach the position
|
36 | }
|
37 | for(pos_links = 180; pos_links >= 1; pos_links-=1) // goes from 180 degrees to 0 degrees
|
38 | {
|
39 | myservo_links.write(pos_links); // tell servo to go to position in variable 'pos'
|
40 | delay(15); // waits 15ms for the servo to reach the position
|
41 | }
|
42 |
|
43 | // rechter Servo:
|
44 |
|
45 | for(pos_rechts = 0; pos_rechts < 180; pos_rechts += 1) // goes from 0 degrees to 180 degrees
|
46 | { // in steps of 1 degree
|
47 | myservo_rechts.write(pos_rechts); // tell servo to go to position in variable 'pos_rechts'
|
48 | delay(15); // waits 15ms for the servo to reach the position
|
49 | }
|
50 | for(pos_rechts = 180; pos_rechts >= 1; pos_rechts -= 1) // goes from 180 degrees to 0 degrees
|
51 | {
|
52 | myservo_rechts.write(pos_rechts); // tell servo to go to position in variable 'pos'
|
53 | delay(15); // waits 15ms for the servo to reach the position
|
54 | }
|
55 |
|
56 | }
|