Pages: [1]   Go Down
Author Topic: 1 servo OK 2 servo ça bug !  (Read 1017 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Bonjour,

j'ai branché deux servo sur deux sorties analogique différentes, et qu'ils sont piloté par deux potentiomètres différents.
Hors quand 1 seul est connecté ça marche, quand y'en a deux ça bug !
les servos font un aller retour à mis chemin du potentiomètre chose qu'ils ne font pas en temps normal...

voici le code !

merci d'avance

Code:
#include <Servo.h>
 
Servo myservo0;  // create servo object to control a servo
Servo myservo1;
 
int potpin0 = 0;  // analog pin used to connect the potentiometer
int potpin1 = 1;  // analog pin used to connect the potentiometer
int val1;    // variable to read the value from the analog pin
int val2;    // variable to read the value from the analog pin
 
void setup()
{
  myservo1.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo0.attach(11);  // attaches the servo on pin 9 to the servo object
}
 
void loop()
{
  val1 = analogRead(potpin1);            // reads the value of the potentiometer (value between 0 and 1023)
  val1 = map(val1, 0, 179, 0, 1023);     // scale it to use it with the servo (value between 0 and 180)
  myservo1.write(val1);  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there
 
  val2 = analogRead(potpin0);            // reads the value of the potentiometer (value between 0 and 1023)
  val2 = map(val2, 0, 179, 0, 1023);     // scale it to use it with the servo (value between 0 and 180)
  myservo0.write(val2);  // sets the servo position according to the scaled value
  delay(15);

}
Logged

Britanny
Offline Offline
Full Member
***
Karma: 0
Posts: 233
Mais vrai, j'ai trop pleuré, toute lune est atroce
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

dans le référentiel Servo:
Quote
As of Arduino 0017, the Servo library supports up to 12 motors on most Arduino boards and 48 on the Arduino Mega. On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins.

en Français: ça marche pas sur les pin 9 et 10!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok merci ^^

je m'étais basé sur l'exemple de arduino.cc qui utilise la pin9!

merci!
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17303
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset



val1 = map(val1, 0, 179, 0, 1023);   >>   val1 = map(val1, 0, 1023, 0, 179);

 val2 = map(val2, 0, 179, 0, 1023);   >>  val2 = map(val2, 0, 1023, 0, 179);

    http://arduino.cc/en/Reference/Map

Lefty   
Logged

Britanny
Offline Offline
Full Member
***
Karma: 0
Posts: 233
Mais vrai, j'ai trop pleuré, toute lune est atroce
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

map(value, fromLow, fromHigh, toLow, toHigh)

ouaip faut inverser les valeurs que tu as mises.

'l a fallu que je lise 2 fois le message de lefty pour voi ou ça allait pas...
je croyais qu'il s'était planté aussi..
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hey hey ça marche!

merci !
Logged

France
Offline Offline
Faraday Member
**
Karma: 39
Posts: 3626
There is an Arduino for that
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

dans le référentiel Servo:
Quote
As of Arduino 0017, the Servo library supports up to 12 motors on most Arduino boards and 48 on the Arduino Mega. On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins.

en Français: ça marche pas sur les pin 9 et 10!
Pas exactement. Ca marche sur les broches 9 et 10 mais ça désactive analogWrite() et les fonctions PWM sur ces broches.
Logged

Pages: [1]   Go Up
Jump to: