Arduino Servo Motor Ansteuerung, Dateneingabe?

OP #3204792
Lesenswert?
• ▲
▼
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
}

Antwort schreiben

Hinweis: der ursprüngliche Beitrag ist mehr als 6 Monate alt. Bitte hier nur auf die ursprüngliche Frage antworten, für neue Fragen einen neuen Beitrag erstellen.

Formatierung
  • [c]C-Code[/c]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] – Link zu einem Artikel
  • Verweis auf einen anderen Beitrag: Rechtsklick auf dessen Beitrags-ID (#8078628), „Adresse kopieren“, in den Text einfügen

Mehr zur Formatierung

Längeren Sourcecode als Anhang, nicht in den Text. JPG nur für Fotos und Scans; Zeichnungen und Screenshots als PNG oder GIF. Siehe Bildformate.

Schon registriert? Anmelden

Wird nicht angezeigt. Wir schicken dir einen Link; sobald du damit bestätigst, erscheint dein Beitrag.

Mit dem Abschicken legst du einen kostenlosen Account an und erkennst die Nutzungsbedingungen und die Datenschutzerklärung an.