// constants won't change.
const int umschPin = 6; // Parameter Umschalten
const int buttonPin = 7; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
const int grad1 = 180; //Parametersatz 1
const int grad2 = 15; //Parametersatz 1
const int grad3 = 90; //Parametersatz 2
const int grad4 = 90; //Parametersatz 2// variables will change:int buttonState = 0;// variable for reading the pushbutton statusint umschState = 0; //Variable Parameterumschatungint grad11 = 0; //Parameter gesetztint grad12 = 0; //Parameter gesetzt// Sweep// by BARRAGAN <http://barraganstudio.com> // This example code is in the public domain.
#include <Servo.h>
Servo myservo; // create.servo object to control a servo // a maximum of eight servo objects can be created Servo myservo1;
int pos = 0; // variable to store the servo position voidsetup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo1.attach(10); // attaches the servo on pin 9 to the servo object // initialize the LED pin as an output:pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:pinMode(buttonPin, INPUT);
// Parameterumschalter initialisierenpinMode(umschPin, INPUT);
}
// Funktion zur Steuerung von 2 Servos alternierentvoid servosctl(int gradv1, int gradv2)
{
for(pos = 0; pos < gradv1; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 0; pos < gradv2; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo1.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position
}
for(pos = gradv1; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position
}
for(pos = gradv2; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo1.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position
}
}
voidloop()
{
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
//Status Parameterumschalter auslesen
umschState = digitalRead(umschPin);
// check if the pushbutton is pressed.// if it is, the buttonState is HIGH:if (buttonState == HIGH) {
// turn LED on: digitalWrite(ledPin, HIGH);
//Hier werden die Parametert umgeschaltet if (umschState == LOW) {
grad11 = grad1;
grad12 = grad2;
}
else{
grad11 = grad3;
grad12 = grad4;
}
servosctl(grad11, grad12);
}
else {
// turn LED off:digitalWrite(ledPin, LOW);
// Grundstellung Servos
myservo.write(0);
myservo1.write(0);
}
}