Create all_servo_test.ino
This commit is contained in:
parent
ff39d927ba
commit
092364686c
1 changed files with 54 additions and 0 deletions
54
Arduino/all_servo_test/all_servo_test.ino
Normal file
54
Arduino/all_servo_test/all_servo_test.ino
Normal file
|
@ -0,0 +1,54 @@
|
|||
#include <ESP32Servo.h>
|
||||
|
||||
#define SERVO_LINKS 136 // Wert um den Servo 45 Grad nach links zu drehen ... der kann je nach Servo anders sein
|
||||
#define SERVO_RECHTS 45 // Wert um den Servo 45 Grad nach rechtss zu drehen ... der kann je nach Servo anders sein
|
||||
#define SERVO_MITTE 90 // Wert um den Servo in die Mitte zu drehen ... der kann je nach Servo anders sein
|
||||
|
||||
Servo myservo[8]; // ein Servo-Objekt anlegen, um den Servo Motor steuern zu können
|
||||
// oVR oVL oHR oHL uVR uVL uHR uHL
|
||||
// 0 1 2 3 4 5 6 7
|
||||
const int myservo_pin[] = { 21, 32, 12, 13, 22, 19, 16, 23 };
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200); // Serial Monitor aktivieren. Mit dem Monitor kann man sich Werte und Meldungen anzeigen lassen.
|
||||
for(unsigned int serv=0;serv<=7;serv++)
|
||||
{
|
||||
myservo[serv].attach(myservo_pin[serv]); // dem Servo Objekt "sagen" an welchen Pin am Schaltkreis der Server angeschlossen ist
|
||||
delay(200);
|
||||
myservo[serv].write(SERVO_MITTE);
|
||||
delay(500);
|
||||
myservo[serv].detach();
|
||||
delay(200);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
for(unsigned int serv = 0; serv <= 7; serv++)
|
||||
{
|
||||
setServo(serv, SERVO_LINKS);
|
||||
setServo(serv, SERVO_RECHTS);
|
||||
setServo(serv, SERVO_MITTE);
|
||||
Serial.println(".");
|
||||
Serial.println("---------------------------------------------------");
|
||||
delay(2000);
|
||||
}
|
||||
}
|
||||
|
||||
void setServo(unsigned int serv, unsigned int angel)
|
||||
{
|
||||
Serial.print(" Servo ");
|
||||
Serial.print(serv);
|
||||
Serial.print(" set to ");
|
||||
Serial.print(angel);
|
||||
myservo[serv].attach(myservo_pin[serv]);
|
||||
delay(100);
|
||||
myservo[serv].write(angel);
|
||||
delay(1000);
|
||||
myservo[serv].detach();
|
||||
delay(100);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in a new issue