Hello, I hope that you're all ok!
I have a problem.
Yesterday I tried for the first time to write a library that I named "Clavier" (that mean keypad in french).
I saved my two files (.h and .cpp) into the Arduino's library folder, into a folder called "Clavier".
Now I open a new sketch and I see my library when i do: "insert a library".
I write the sketch, and the compilator corrector says "expected unqualified-id before '.' token"
I think that the IDE doesn't like my library because it doesn't like the word "clavier".
If you could give me some help I would be grateful.
Sorry for my bad english.
thanks,
stefano
If these are static methods in the class, there is no reason to create an instance of the class. If they are not static methods, you are supposed to call them with an instance of the class.
#ifndef Clavier_h
#define Clavier_h
#if ARDUINO<100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif
class Clavier{
public:
Clavier(int col1,int col2,int col3,int lig1,int lig2,int lig3,int lig4);// constructeur
double getValue();// retourne la valeur actuelle
void resetValue();// valeur actuelle=0
void readKeypad();
private:
double valeurFinale;
int dec;
int moin;
int tempsTouche;
int i;
int col1,col2,col3, lig1, lig2, lig3, lig4;
int getterKey();
};
#endif
#if ARDUINO<100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif
#include "Clavier.h"
Clavier ::Clavier(int A,int B,int C,int D,int E,int F,int G){
col1=A;
col2=B;
col3=C;
lig1=D;
lig2=E;
lig3=F;
lig4=G;
pinMode(col1,OUTPUT);
pinMode(col2,OUTPUT);
pinMode(col3,OUTPUT);
pinMode(lig1,INPUT);
pinMode(lig2,INPUT);
pinMode(lig3,INPUT);
pinMode(lig4,INPUT);
restValue();
}
double Clavier::getValue(){
if (moin==1){
valeurFinale=valeurFinale*(-1);
}
return valeurFinale;
}// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%fin de la fonction "getValue"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void Clavier::resetValue(){
dec=0;
moin=0;
valeurFinale=0.0;
tempsTouche=200;
i=0;
}// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%fin de la fonction "resetValue"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
int Clavier::getterKey(){
int valeur;
valeur=13;
digitalWrite(col1,1); // colonne 1 alumee (147*)
if (digitalRead(lig1)==1){ // verification de la ligne 1 (*0#)
valeur=10;
//break;
}
if (digitalRead(lig2)==1){// verification de la ligne 2 (789)
valeur=7;
//break;
}
if (digitalRead(lig3)==1){// verification de la ligne 3 (456)
valeur=4;
//break;
}
if (digitalRead(lig4)==1){// verification de la ligne 4 (123)
valeur=1;
//break;
}
digitalWrite(col1,0);// extinction de la colonne 1
digitalWrite(col2,1);// colonne 2 alumee (0852)
if (digitalRead(lig1)==1){ // verification de la ligne 1 (*0#)
valeur=0;
//break;
}
if (digitalRead(lig2)==1){// verification de la ligne 2 (789)
valeur=8;
//break;
}
if (digitalRead(lig3)==1){// verification de la ligne 3 (456)
valeur=5;
//break;
}
if (digitalRead(lig4)==1){// verification de la ligne 4 (123)
valeur=2;
//break;
}
digitalWrite(col2,0);// extinction de la colonne 2
digitalWrite(col3,1);// colonne 3 alumee (#963)
if (digitalRead(lig1)==1){ // verification de la ligne 1 (*0#)
valeur=11;
//break;
}
if (digitalRead(lig2)==1){// verification de la ligne 2 (789)
valeur=9;
//break;
}
if (digitalRead(lig3)==1){// verification de la ligne 3 (456)
valeur=6;
//break;
}
if (digitalRead(lig4)==1){// verification de la ligne 4 (123)
valeur=3;
//break;
}
return valeur;
} // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%fin de la fonction "getKey"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void Clavier::readKeypad(){
int valeurBrut;
int tpsdet;
tpsdet=300;
if (tpsdet-tempsTouche>0){
valeurBrut=getterKey();
if (valeurBrut<10){// chiffres de 1 a 9
if (dec==0){// avant d'appuyer sur la virgule
valeurFinale=valeurFinale*pow(10,i)+valeurBrut;
i++;
}
if (dec==1){// apres avoir appuyé sur la virgule
valeurBrut=valeurBrut/(pow(10,i+1));
valeurFinale=valeurFinale+valeurBrut;
i++;
}
tpsdet=millis()-tpsdet;
}
if (valeurBrut==10){// si on appuye sur virgule(etoile)
dec=1; // dec en variable globale
}
if (valeurBrut==11){//si on appuye sur moin (diese)
if (moin==0){
moin=1; // variable globale
}
if (moin==1){
moin=0;
}
tpsdet=millis()-tpsdet;
}
}//fin du if te temporisa
}// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%fin de la fonction "keypadRead"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I'm studying mecanical enginering, so I'm sorry if I don't understand everything about programmation.
thank you for help!
pinMode() relies on the hardware being ready. When your constructor is called, the hardware is not. You need a begin() method where you put the pinMode() calls.
You need to call the begin() method in setup().
readKeypad() and getValue() are not static methods, so they need to be called on an instance of the class (clavierNum) not on the class (Clavier).