Bonjour,
Tout d'abord, merci de m’accueillir sur votre site.
Je me suis lancé dans dans la création de bibliotheque aujourd'hui et c'est lorque que je pensais toucher au but que je me retrouve totalement bloqué!
error: 'codeur' was not declared in this scope
Voici le fichier d'en tete:
#ifndef BordBib_h
#define BordBib_h
//#include "Arduino.h"
class Codeur
{
public:
Codeur( int encoder0PinA, int encoder0PinB, int encoder0Pin0);
int pos() ;
private:
static void blink();
int val;
int encoder0PinALast;
static int n ;
int encoder0Pos ;
};
#endif
Le fichier source
#include "Bordbib.h"
#include "Arduino.h"
int val;
int encoder0Pos=0;
int encoder0PinALast ;
int n = LOW;
int encoder0PinA;
int encoder0PinB;
int encoder0Pin0;
Codeur::Codeur( int encoder0PinA, int encoder0PinB, int encoder0Pin0)
{
pinMode (encoder0PinA,INPUT);
pinMode (encoder0PinB,INPUT);
attachInterrupt(encoder0Pin0, blink, RISING);
}
int Codeur::pos()
{
n = digitalRead(encoder0PinA);
if ((encoder0PinALast == LOW) && (n == HIGH))
{
if (digitalRead(encoder0PinB) == LOW)
{
encoder0Pos--;
}
else
{
encoder0Pos++;
}
//Serial.println (encoder0Pos);
//Serial.print ("/n");
}
encoder0PinALast = n;
return encoder0Pos;
}
void blink()
{
encoder0Pos = 0;
}
et le .c!
/* Read Quadrature Encoder
* Connect Encoder to Pins encoder0PinA, encoder0PinB, encoder0Pin0 and +5V.
*
* Sketch by max wolf / www.meso.net
* v. 0.1 - very basic functions - mw 20061220
*
*/
#include "Bordbib.h"
//int val;
int encoder0PinA = 3;
int encoder0PinB = 4;
int encoder0Pos;
int encoder0Pin0 = 2;
//int encoder0PinALast = LOW;
//int n = LOW;
void setup()
{
Serial.begin (115200);
Codeur codeur(encoder0PinA, encoder0PinB, encoder0Pin0);
}
void loop()
{
encoder0Pos = codeur.pos();
Serial.println (encoder0Pos);
//Serial.print ("/n");
}
/*
void blink()
{
encoder0Pos = 0;
} */
J'ai eu beau écumer les forums et bidouiller mon programme dans tout les sens je ne trouve pas mes autres erreurs!
Merci d'avance,
#include "Bordbib.h"
//int val;
int encoder0PinA = 3;
int encoder0PinB = 4;
int encoder0Pos;
int encoder0Pin0 = 2;
//int encoder0PinALast = LOW;
//int n = LOW;
Codeur codeur(encoder0PinA, encoder0PinB, encoder0Pin0);
void setup()
{
Serial.begin (115200);
}
void loop()
{
encoder0Pos = codeur.pos();
Serial.println (encoder0Pos);
//Serial.print ("/n");
}
le fichier source
#include "Bordbib.h"
#include "Arduino.h"
Codeur::Codeur( int encoder0PinA, int encoder0PinB, int encoder0Pin0)
{
pinMode (encoder0PinA,INPUT);
pinMode (encoder0PinB,INPUT);
attachInterrupt(encoder0Pin0, blink, RISING);
int PinA=encoder0PinA;
int PinB=encoder0PinB;
int Pin0=encoder0Pin0;
}
int Codeur::pos()
{
n = digitalRead(PinA);
if ((encoder0PinALast == LOW) && (n == HIGH))
{
if (digitalRead(PinB) == LOW)
{
encoder0Pos--;
}
else
{
encoder0Pos++;
}
//Serial.println (encoder0Pos);
//Serial.print ("/n");
}
encoder0PinALast = n;
return encoder0Pos;
}
void Codeur::blink()
{
encoder0Pos = 0;
}
et le fichier d'en tete
#ifndef BordBib_h
#define BordBib_h
//#include "Arduino.h"
class Codeur
{
public:
Codeur( int encoder0PinA, int encoder0PinB, int encoder0Pin0);
int pos() ;
private:
static void blink();
int val;
int encoder0PinALast;
int n ;
int encoder0Pos;
int PinA;
int PinB;
int Pin0;
};
#endif
et la
invalid use of member 'Codeur::encoder0Pos'
J'ai essayer de le mettre en static int mais ca devient crititique...
BordBib.cpp.o: In function Codeur::blink()': C:\DOCUME~1\NICOLA~1.DOM\LOCALS~1\Temp\build4189112365359606367.tmp/BordBib.cpp:37: undefined reference to Codeur::encoder0Pos'
C:\DOCUME~1\NICOLA~1.DOM\LOCALS~1\Temp\build4189112365359606367.tmp/BordBib.cpp:37: undefined reference to Codeur::encoder0Pos' BordBib.cpp.o: In function Codeur::pos()':
C:\DOCUME~1\NICOLA~1.DOM\LOCALS~1\Temp\build4189112365359606367.tmp/BordBib.cpp:20: undefined reference to Codeur::encoder0Pos' C:\DOCUME~1\NICOLA~1.DOM\LOCALS~1\Temp\build4189112365359606367.tmp/BordBib.cpp:20: undefined reference to Codeur::encoder0Pos'
C:\DOCUME~1\NICOLA~1.DOM\LOCALS~1\Temp\build4189112365359606367.tmp/BordBib.cpp:26: undefined reference to Codeur::encoder0Pos' BordBib.cpp.o:C:\DOCUME~1\NICOLA~1.DOM\LOCALS~1\Temp\build4189112365359606367.tmp/BordBib.cpp:26: more undefined references to Codeur::encoder0Pos' follow
ld_remi:
Merci fdunews,
Maintenant, ça compile mais la position ne s'incrémente pas!
La méthode pos() me parait un peu bizarre. je ne suis pas certain quelque puisse compter.
D'ailleurs entre nous la logique de cette librairie m'échappe.
Logiquement elle devrait décharger l'application de la gestion du codeur incrémental or là si l'appli n'appelle pas la méthode pos() il ne se passe rien. Ou alors quelque chose m'a échappé...
Selon moi, pinA et pinB devrait déclencher des interruptions qui assureraient le comptage.
La méthode pos() ne devrait être appelée par l'appli que pour récupérer la valeur actuelle du comptage.
Il me semble qu'il existe déjà une (ou des) librairie(s) pour gérer des codeurs tu devrais y jeter un coup d'oeil.
#ifndef encoder_h
#define encoder_h
#include "arduino.h"
class Codeur
{
public:
Codeur(int pinA,int pinB,int pin0);
int pos();
static void blink();
private:
int _pinA;
int _pinB;
int _pin0;
int CodPos;
int encoder0PinALast;
int n ;
int _flag;
};
#endif
#include "arduino.h"
#include "encoder.h"
Codeur::Codeur(int pinA,int pinB,int pin0)
{
_pinA=pinA;
_pinB=pinB;
_pin0=pin0;
CodPos=0;
pinMode (_pinA,INPUT);
pinMode (_pinB,INPUT);
attachInterrupt(_pin0, blink, RISING);
int encoder0PinALast = LOW;
int n = LOW;
}
int Codeur::pos()
{
n = digitalRead(_pinA);
if ((encoder0PinALast == LOW) && (n == HIGH))
{
if (digitalRead(_pinB) == LOW)
{
CodPos--;
}
else
{
CodPos++;
}
}
encoder0PinALast = n;
return CodPos;
}
void Codeur::blink()
{
_flag = 0;
}
#include "encoder.h"
int val;
int encoder0PinA = 3;
int encoder0PinB = 4;
int encoder0Pos = 0;
Codeur Codeur(encoder0PinA,encoder0PinB,encoder0Pos);
void setup()
{
Serial.begin (115200);
}
void loop()
{
val= Codeur.pos();
Serial.println (val);
}
maintenant les programme fonctionne bien mais je n'arrive pas à y ajouter une interruption externe.
La pin 0 représente un point qui se trouve le codeur une fois par tour, je m'en sert pour remettre à 0 mon comptage.
Lorsque je compile, le compilateur me dit "error: invalid use of member 'Codeur::_flag' in static member function"