Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision Les deux révisions suivantes
projets:bateau_rc [14/03/2018 19:22]
Mathieu Hery [Ressources]
projets:bateau_rc [14/03/2018 19:24]
Mathieu Hery
Ligne 38: Ligne 38:
  
 ---- ----
 +==== Code Arduino pour Servos ====
 +
 +Ce boût de code est à adapter pour controller un servo-moteur SG90 avec un potentiomètre :
 +
 +<​code>​
 +/*
 +Into Robotics
 +*/
 +
 +#include <​Servo.h> ​
 +
 +int servoPin = 9;
 + 
 +Servo servo;  ​
 + 
 +int servoAngle = 0;   // servo position in degrees
 + 
 +void setup()
 +{
 +  Serial.begin(9600);  ​
 +  servo.attach(servoPin);​
 +}
 + 
 + 
 +void loop()
 +{
 +//control the servo'​s direction and the position of the motor
 +
 +   ​servo.write(45); ​     // Turn SG90 servo Left to 45 degrees
 +   ​delay(1000); ​         // Wait 1 second
 +   ​servo.write(90); ​     // Turn SG90 servo back to 90 degrees (center position)
 +   ​delay(1000); ​         // Wait 1 second
 +   ​servo.write(135); ​    // Turn SG90 servo Right to 135 degrees
 +   ​delay(1000); ​         // Wait 1 second
 +   ​servo.write(90); ​     // Turn SG90 servo back to 90 degrees (center position)
 +   ​delay(1000);​
 +
 +//end control the servo'​s direction and the position of the motor
 +
 +
 +//control the servo'​s speed  ​
 +
 +//if you change the delay value (from example change 50 to 10), the speed of the servo changes
 +  for(servoAngle = 0; servoAngle < 180; servoAngle++) ​ //move the micro servo from 0 degrees to 180 degrees
 +  {                                  ​
 +    servo.write(servoAngle); ​             ​
 +    delay(50); ​                 ​
 +  }
 +
 +  for(servoAngle = 180; servoAngle > 0; servoAngle--) ​ //now move back the micro servo from 0 degrees to 180 degrees
 +  {                                ​
 +    servo.write(servoAngle); ​         ​
 +    delay(10); ​     ​
 +  }
 +  //end control the servo'​s speed  ​
 +}
 +</​code>​
 +
  
 ==== Ressources ==== ==== Ressources ====