Bonjour
J'ai ce code mais je ne sais pas comment le transformer.
Voici le code complet
#include <Servo.h>
Servo myservo1;
Servo myservo2;
int posServo1 = 0;
int posServo2 = 0;
const int buttonPin1 = 2;
const int buttonPin2 = 4;
int buttonState1 = 0;
int buttonState2 = 0;
int angleMin = 0;
int angleMax = 180;
void setup()
{
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
myservo1.attach(9);
myservo2.attach(7);
}
void loop()
{
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
if (buttonState1 == HIGH && buttonState2 == LOW)
{
if (posServo1 < angleMax)
posServo1++;
if(posServo2 > angleMin )
posServo2--;
}
else if (buttonState1 == LOW && buttonState2 == HIGH)
{
if (posServo1 > angleMin )
posServo1--;
if (posServo2 < angleMax)
posServo2++;
}
myservo1.write(posServo1);
myservo2.write(posServo2);
delay(1);
}
Sur ce code lorsque j'appuie sur le bouton le servo 1 et le servo 2 font un seul mouvement
qu'est ce qu'il faut rajouter comme code pour que les servos reviennent leurs positions initiales sans rappuyer sur le bouton?
else if (buttonState1 == LOW && buttonState2 == HIGH)
{
if (posServo1 > angleMin )
posServo1--;
if (posServo2 < angleMax)
posServo2++;
Ici le servo va de 0° à 180°
Comment je dois faire si je veux qu'il passe de 45° à 90°?
int angleMin = 0;
int angleMax = 180;
if (posServo1 < angleMax)
posServo1++;
if(posServo2 > angleMin )
posServo2--;
new.cpp: In function 'void loop()':
new:34: error: expected primary-expression before '}' token
new:34: error: expected ;' before '}' token new:44: error: 'else' without a previous 'if' new:47: error: expected primary-expression before '}' token new:47: error: expected ;' before '}' token
new:50: error: expected primary-expression before '=' token
new:57: error: expected }' at end of input new:57: error: expected }' at end of input