Code
From Hackteria Wiki
der Code zu den Servos
- include <Servo.h> //Servo library
// defining all the input pins
const int pin1 = 2; // with servo 1 on pin 3
const int pin2 = 4; // with servo 2 on pin 5
const int pin3 = 7; // with servo 3 on pin 6
const int pin4 = 8; // with servo 4 on pin 9
const int pin5 = 12; // with servo 5 on pin 11
//defining all the servos Servo servo1; Servo servo2; Servo servo3; Servo servo4; Servo servo5;
void setup() {
// defining all the pins as inputs: pinMode(pin1, INPUT); pinMode(pin2, INPUT); pinMode(pin3, INPUT); pinMode(pin4, INPUT); pinMode(pin5, INPUT);
pinMode(3, OUTPUT); servo1.attach(3); pinMode(5, OUTPUT); servo2.attach(5); pinMode(6, OUTPUT); servo3.attach(6); pinMode(9, OUTPUT); servo4.attach(9); pinMode(11, OUTPUT); servo5.attach(11);
}
void loop() {
// read the state of the switch for this servo. If the switch is on, set it to 180, otherwise to 0. int servostate1 = digitalRead(pin1); if (servostate1 == HIGH) {servo1.write(180);} else {servo1.write(0);}
// read the state of the switch for this servo. If the switch is on, set it to 180, otherwise to 0. int servostate2 = digitalRead(pin2); if (servostate2 == HIGH) {servo2.write(180);} else {servo2.write(0);}
// read the state of the switch for this servo. If the switch is on, set it to 180, otherwise to 0. int servostate3 = digitalRead(pin3); if (servostate3 == HIGH) {servo3.write(180);} else {servo3.write(0);}
// read the state of the switch for this servo. If the switch is on, set it to 180, otherwise to 0. int servostate4 = digitalRead(pin4); if (servostate4 == HIGH) {servo4.write(180);} else {servo4.write(0);}
// read the state of the switch for this servo. If the switch is on, set it to 180, otherwise to 0. int servostate5 = digitalRead(pin5); if (servostate5 == HIGH) {servo5.write(180);} else {servo5.write(0);}
}