Hallo, ich bräuchte mal eure Hilfe da ich gerade anstehe: Ich bin Modellbauer und benötige für mein aktuelles Projekt eine Steuerung welche 2 Servos steuern kann. Ich möchte das ganze mit einem Arduino Nano durchführen und habe hierfür schon alle Komponenten zusammen. Die Servos sollen folgende Aufgabe erledigen: https://www.youtube.com/watch?v=RhTMjVR0U00&feature=youtu.be Ein Programm habe ich schon soweit geschrieben aber könntet ihr mir vielleicht sagen ob das so stimmt bzw. ob es anderes auch funktioniert. Beim Funktionstest zeigte sich, dass ein Servo beim Start eine Position ein nimmt und der andere macht einfach irgendetwas. Programm:
1 | /**
|
2 | |
3 | ***Funktionsbeschreibung Lukensteuerung***
|
4 | |
5 | Sobald am Input "CTI" eine Spannung von 5V anliegt soll sich
|
6 | der Servo "Luke" bewegen und sobald der Kontakt "SicherungLuke"
|
7 | geschlossen ist, soll sich auch Servo "Fahrer" bewegen.
|
8 | Wird nun der Input "CTI" auf 0V gesetzt so soll sich zuerst Servo "Fahrer"
|
9 | bewegen und erst wenn Kontakt "Sicherung Fahrer" geschlossen ist, darf Servo
|
10 | "Luke" wieder zurück in die Ursprungsposition gehen.
|
11 | |
12 | **/
|
13 | |
14 | |
15 | int LED = 13; |
16 | int CTI = 2; |
17 | int SicherungLuke = 7; |
18 | int SicherungFahrer = 8; |
19 | #include <Servo.h> |
20 | |
21 | Servo Luke; // create servo object to control a servo |
22 | Servo Fahrer; // create servo object to control a servo |
23 | // a maximum of eight servo objects can be created
|
24 | int posL = 0; // variable to store the servo position |
25 | int posF = 0; // variable to store the servo position |
26 | |
27 | void setup() { |
28 | // initialize the LED pin as an output:
|
29 | pinMode(LED, OUTPUT); |
30 | // initialize the pushbutton pin as an input:
|
31 | pinMode(CTI, INPUT); |
32 | pinMode(SicherungLuke, INPUT); |
33 | pinMode(SicherungFahrer, INPUT); |
34 | Luke.attach(9); // attaches the servo on pin 9 to the servo object |
35 | Fahrer.attach(6); // attaches the servo on pin 10 to the servo object |
36 | }
|
37 | |
38 | void loop(){ |
39 | |
40 | if (digitalRead(CTI) == HIGH) { //prüft Signal von CTI-Modul |
41 | digitalWrite(LED, HIGH); // turn the LED on |
42 | for(posL = 0; posL < 100; posL += 1) // goes from X degrees to Y degrees |
43 | // in steps of 1 degree
|
44 | Luke.write(posL); // tell servo to go to position in variable 'posL' |
45 | delay(30); |
46 | |
47 | if (digitalRead(SicherungLuke) == HIGH) { |
48 | for(posF = 0; posF < 100; posF += 1) // goes from X degrees to Y degrees |
49 | // in steps of 1 degree
|
50 | Fahrer.write(posF); |
51 | delay(30); // tell servo to go to position in variable 'posF' |
52 | |
53 | }
|
54 | }
|
55 | else { |
56 | digitalWrite(LED, LOW); // turn the LED off |
57 | for(posF = 100; posF >= 20; posF -= 1) // goes from X degrees to Y degrees |
58 | |
59 | Fahrer.write(posF); // tell servo to go to position in variable 'posF' |
60 | delay(30); |
61 | |
62 | if (digitalRead(SicherungFahrer) == HIGH) { |
63 | for(posL = 100; posL >= 20; posL -= 1) // goes from X degrees to Y degrees |
64 | // in steps of 1 degree
|
65 | Fahrer.write(posL); // tell servo to go to position in variable 'posL' |
66 | delay(30); |
67 | |
68 | }
|
69 | }
|
70 | }
|
Ich würde mich sehr über eure Hilfe freuen! Lg, Alex