Problème bouton et moteur servo

bonjour
je suis en train de faire le code arduino pour piloter mon telescope
sauf que la partie moteur servo ne fonctionne pas
j'ai un problème avec les bouton et le déplacement du servo

voici mon code

#include <Servo.h> 
int batinovPin = 22;
Servo Batinov;

void setup() {
  Batinov.attach(batinovPin);   
  Batinov.write(0); 
 }
void loop() {
if (digitalRead(bouton13) == low) {
    Batinov.write(0); 
  }
  else (digitalRead(bouton14) == low) {
    Batinov.write(270);
  }
}

comme code erreur je reçois ça

C:\Users\*****\Documents\Arduino\photostrock\photostrock.ino: In function 'void loop()':
C:\Users\*****\Documents\Arduino\photostrock\photostrock.ino:162:32: error: 'low' was not declared in this scope
   if (digitalRead(bouton13) == low) {
                                ^~~
C:\Users\*****\Documents\Arduino\photostrock\photostrock.ino:162:32: note: suggested alternative: 'pow'
   if (digitalRead(bouton13) == low) {
                                ^~~
                                pow
Multiple libraries were found for "Servo.h"
 Used: C:\Users\*****\Documents\Arduino\libraries\Servo
 Not used: C:\Program Files (x86)\Arduino\libraries\Servo
Compilation error: exit status 1}

merci :wink:
cdt

Bonsoir astronomy

low doit être en majuscules == LOW

Autre chose, la valeur d'angle 270 risque de poser problème, la bibliothèque servo considère que tout ce qui est < 200 comme valeur d'angle, donc >= 200 comme des millisecondes, largeur d'impulsion du PWM. Pour tes premiers essais, remplaces 270 par 180 pour "assurer le coup".

Cordialement
jpbbricole

1 Like

Bonjour ami
Vous devez spécifier l'un des boutons pour qu'il soit "high".
Parce que vous n'avez configuré aucun bouton pour qu'il fonctionne

1 Like

bonjour
ça marche toujours pas
mon nouveau code erreur

C:\Users\****\Documents\Arduino\photostrock\photostrock.ino: In function 'void loop()':
C:\Users\****\Documents\Arduino\photostrock\photostrock.ino:166:39: error: expected ';' before '{' token
   else (digitalRead(bouton14) == LOW) {
                                       ^

merci
cdt

bonjour
j'ai essayé et rien ne change
merci
cdt

Bonjour astronomy

Tu as un problème de fond dans ta programmation.

Tu n'a pas déclaré les variables bouton13 et bouton14.
Regardes l'exemple Button.ino dans l'IDE Arduino.
Et une explication sur le traitement des boutons.

else n'a pas de condition, autrement c'est else if

PS: Quelle carte Arduino as-tu?

Cordialement
jpbbricole

1 Like

si j'ai déclaré les boutons
en vrai mon code c'est ça

#include <AccelStepper.h>
#include <MultiStepper.h>
#include <LiquidCrystal.h>
#include <Servo.h> 

AccelStepper collimation1(AccelStepper::DRIVER, 53, 52);
AccelStepper collimation2(AccelStepper::DRIVER, 10, 11);
AccelStepper collimation3(AccelStepper::DRIVER, 6, 7);
AccelStepper moteurAD(AccelStepper::DRIVER, 51, 50);
AccelStepper moteurDEC(AccelStepper::DRIVER, 12, 13);
AccelStepper focuser(AccelStepper::DRIVER, 8, 9);

LiquidCrystal lcd (45, 44, 46, 47, 48, 49);

int batinovPin = 22;
Servo Batinov;

const int bouton1 = 24;
const int bouton2 = 25; 
const int bouton3 = 26;
const int bouton4 = 27;
const int bouton5 = 28;
const int bouton6 = 29;
const int bouton7 = 30; 
const int bouton8 = 31;
const int bouton9 = 32;
const int bouton10 = 33; 
const int bouton11 = 34;
const int bouton12 = 35;
const int bouton13 = 36;
const int bouton14 = 37;
const int bouton15 = 38; 
const int bouton16 = 39;
const int bouton17 = 40;
const int bouton18 = 41;
const int bouton19 = 42; 
const int bouton20 = 43;
const int ST4ADplus = 2;
const int ST4DECplus = 3;
const int ST4DECminus = 4;
const int ST4ADminus = 5;

void setup() {

  pinMode (bouton1, INPUT_PULLUP);
  pinMode (bouton2, INPUT_PULLUP);
  pinMode (bouton3, INPUT_PULLUP);
  pinMode (bouton4, INPUT_PULLUP);
  pinMode (bouton5, INPUT_PULLUP);
  pinMode (bouton6, INPUT_PULLUP);
  pinMode (bouton7, INPUT_PULLUP);
  pinMode (bouton8, INPUT_PULLUP);
  pinMode (bouton9, INPUT_PULLUP);
  pinMode (bouton10, INPUT_PULLUP);
  pinMode (bouton11, INPUT_PULLUP);
  pinMode (bouton12, INPUT_PULLUP);
  pinMode (bouton13, INPUT_PULLUP);
  pinMode (bouton14, INPUT_PULLUP);
  pinMode (bouton15, INPUT_PULLUP);
  pinMode (bouton16, INPUT_PULLUP);
  pinMode (bouton17, INPUT_PULLUP);
  pinMode (bouton18, INPUT_PULLUP);
  pinMode (bouton19, INPUT_PULLUP);
  pinMode (bouton20, INPUT_PULLUP);
  pinMode (ST4ADplus, INPUT_PULLUP);
  pinMode (ST4DECplus, INPUT_PULLUP);
  pinMode (ST4DECminus, INPUT_PULLUP);
  pinMode (ST4ADminus, INPUT_PULLUP);
  

  collimation1.setMaxSpeed(1000);
  collimation1.setSpeed(0);

  collimation2.setMaxSpeed(1000);
  collimation2.setSpeed(0);

  collimation3.setMaxSpeed(1000);
  collimation3.setSpeed(0);

  moteurAD.setMaxSpeed(1000);
  moteurAD.setSpeed(0);

  moteurDEC.setMaxSpeed(1000);
  moteurDEC.setSpeed(0);

  focuser.setMaxSpeed(1000);
  focuser.setSpeed(0);


  lcd.begin(16, 2);

  Batinov.attach(batinovPin);  
  Batinov.write(0); 

 }
void loop() {
  
  if (digitalRead(bouton1) == LOW) {
    collimation1.setSpeed(100);
  }
  else  if (digitalRead(bouton2) == LOW) {
    collimation1.setSpeed(-100);
  }
  else {
    collimation1.setSpeed(0);
  }
  collimation1.runSpeed();

  if (digitalRead(bouton3) == LOW) {
    collimation2.setSpeed(100);
  }
  else  if (digitalRead(bouton4) == LOW) {
    collimation2.setSpeed(-100);
  }
  else {
    collimation2.setSpeed(0);
  }
  collimation2.runSpeed();

  if (digitalRead(bouton5) == LOW) {
    collimation3.setSpeed(100);
  }
  else  if (digitalRead(bouton6) == LOW) {
    collimation3.setSpeed(-100);
  }
  else {
    collimation3.setSpeed(0);
  }
  collimation3.runSpeed();

  if (digitalRead(bouton7) == LOW) {
    moteurAD.setSpeed(100);
  }
  else  if (digitalRead(bouton8) == LOW) {
    moteurAD.setSpeed(-100);
  }
  else {
    moteurAD.setSpeed(0);
  }
  moteurAD.runSpeed();

  if (digitalRead(bouton9) == LOW) {
    moteurDEC.setSpeed(100);
  }
  else  if (digitalRead(bouton10) == LOW) {
    moteurDEC.setSpeed(-100);
  }
  else {
    moteurDEC.setSpeed(0);
  }
  moteurDEC.runSpeed();

  if (digitalRead(bouton11) == LOW) {
    focuser.setSpeed(100);
  }
  else  if (digitalRead(bouton12) == LOW) {
    focuser.setSpeed(-100);
  }
  else {
    focuser.setSpeed(0);
  }
  focuser.runSpeed();
  if (digitalRead(bouton13) == LOW) {
    Batinov.write(0); 
  }
  else if (digitalRead(bouton14) == LOW) {
    Batinov.write(200);
  }
}

je suis sur une arduino mega 2560
avec else if ça marche
merci cdt
cdt

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.