Kurzmeldung Info

Neue Homepage

Ab 2015 gibts neue Beiträge nur noch hier! Neues responsible Design. Aus Mambo wird jetzt Joomla.
Arduino und Servos PDF Drucken E-Mail
Bewertung:  Stimmen: 4/Sterne: 5
SchlechtSehr gut 
Verfasst von
Artikelindex
Arduino und Servos
Erweiterung
Sourcecode
Arduino steuert Antriebe

// 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 status
int umschState = 0; //Variable Parameterumschatung
int grad11 = 0;   //Parameter gesetzt
int 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 
 
void setup() 
{ 
  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 initialisieren
  pinMode(umschPin, INPUT);

} 
// Funktion zur Steuerung von 2 Servos  alternierent

void 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 
  } 
 
  
  
  
  
  
}
 
 
void loop() 
{ 
  
    // 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);
  }
}



Letzte Aktualisierung ( 03.03.2014 )
Gemacht von Stefan Höhn als ; Publisher und Mambo.
Mambo ist freie Software herausgegeben unter GNU/GPL Lizenz.