I had a copy+paste error, Pisada_c was never being defined.
J-M-L:
Why does pisada_c.h starts with#ifndef Led_c_h
#define Led_c_h
Hum....
Hi!
I'm developing my first big project using a Leonardo board and IDE 1.8.5
I separated it in small pieces in order to check that every piece worked before joining them, and I made a few custom libraries too.
I just began to join things, and got an "X does not name a type" error, related to libraries that worked fine when used in the corresponding small piece of code.
I simplified the main sketch as much as possible to find where the error is, and a found a strange thing. In a generic code like
#include <class1_c.h>
#include <class2_c.h>
class1_c object1;
class2_c object2;
The error I get is "class2_c does not name a type". But if I change it like
#include <class2_c.h>
#include <class1_c.h>
class1_c object1;
class2_c object2;
the error would be "class1_c.h does not name a type" and class1_c would be fine now.
Now I'll copy the simplified sketch, both full libraries and the full error. I hope everything is clear, as it is my first post and english is not my first language. Sorry for variables and functions in spanish.
Main
#include <Pisada_c.h>
#include <Led_c.h>
#define R 3
#define G 5
#define B 6
Led_c Led1(R,G,B);
Pisada_c Pisada;
void setup() {
// put your setup code here, to run once:
analogReference(EXTERNAL);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
}
Led_c.h
#ifndef Led_c_h
#define Led_c_h
#include <Arduino.h>
enum Color_t
{
Blanco,
Rojo,
Amarillo,
Verde,
};
enum EstadoLed_t
{
Encendido,
Apagado,
};
class Led_c
{
public:
Led_c(int r, int g, int b);
//ATRIBUTOS
EstadoLed_t Estado;
void Encender(Color_t Color);
void Titilar(Color_t Color, int t); //t=tiempo de cada fase del titilado
bool flagTitilar;
//METODOS
void Apagar();
void invertirLed(Color_t Color);
private:
//ATRIBUTOS
int R; //pin de la pata R
int G;//pin de la pata G
int B;//pin de la pata B
unsigned long Cont_titilar;//cuenta los ms para saber cuando invertir el led
//METODOS
void SetearRojo();
void SetearAmarillo();
void SetearVerde();
void SetearBlanco();
};
#endif
Led_c.cpp
#include <Arduino.h>
#include "Led_c.h"
Led_c::Led_c(int r, int g, int b)
{
R = r;
G = g;
B = b;
pinMode(R, OUTPUT);
pinMode(G, OUTPUT);
pinMode(B, OUTPUT);
analogWrite(R,255);
analogWrite(G,255);
analogWrite(B,255);
Estado=Apagado;
Cont_titilar=0UL;
flagTitilar=false;
}
void Led_c::Apagar()
{
analogWrite(R,255);
analogWrite(G,255);
analogWrite(B,255);
Estado=Apagado;
}
void Led_c::Encender(Color_t Color)
{
switch(Color) {
case Rojo:
SetearRojo();
break;
case Amarillo:
SetearAmarillo();
break;
case Verde:
SetearVerde();
break;
case Blanco:
SetearBlanco();
break;
default:
SetearBlanco();
break;
}
}
void Led_c::Titilar(Color_t Color, int t) //Tiempo de encendido o apagado en ms
{
if(millis()>Cont_titilar+t)
{
invertirLed(Color);
Cont_titilar=millis();
}
}
void Led_c::SetearAmarillo()
{
analogWrite(R,120);
analogWrite(G,120);
analogWrite(B,255);
Estado=Encendido;
}
void Led_c::SetearVerde()
{
analogWrite(R,255);
analogWrite(G,120);
analogWrite(B,255);
Estado=Encendido;
}
void Led_c::SetearRojo()
{
analogWrite(R,120);
analogWrite(G,255);
analogWrite(B,255);
Estado=Encendido;
}
void Led_c::SetearBlanco()
{
analogWrite(R,1);
analogWrite(G,1);
analogWrite(B,1);
Estado=Encendido;
}
void Led_c::invertirLed(Color_t Color)
{
switch(Color)
{
case Verde:
if(Estado==Apagado)
{SetearVerde();} else if(Estado==Encendido)
Apagar();
break;
case Amarillo:
if(Estado==Apagado) {SetearAmarillo();} else if(Estado==Encendido)
Apagar();
break;
case Rojo:
if(Estado==Apagado) {SetearRojo();} else if(Estado==Encendido)
Apagar();
break;
case Blanco:
if(Estado==Apagado) {SetearBlanco();} else if(Estado==Encendido)
Apagar();
break;
default:
if(Estado==Apagado) {SetearBlanco();} else if(Estado==Encendido)
Apagar();
break;
}
}
Pisada_c.h
#ifndef Led_c_h
#define Led_c_h
#include <Arduino.h>
enum EstadoPisada_t
{
Apoyo,
Balanceo
};
class Pisada_c
{
public:
//ATRIBUTOS
Pisada_c();
unsigned int tiempoPaso;
unsigned int tiempoApoyo;
long porcentajeApoyo;
bool flagApoyo;
bool flagPorcentaje;
//METODOS
void fsmFaseMarcha();
void calcularPorcentajeApoyo();
void enviarAlerta();
private:
//ATRIBUTOS
unsigned long t0;//Inicio de la fase de apoyo
unsigned long t1;//inicio de la fase de balanceo
unsigned long tf;//Fin de la fase de balanceo y comienzo de una nueva fase de apoyo
int porcentajeReferencia_min;
int porcentajeReferencia_max;
EstadoPisada_t Estado;
bool activarAlertas;
int contPasos;//hace que en el primer paso no se active la alarma ya que no se juntaron los datos para hacer el calculo
int timeThreshold;//Genera efecto antirrebote en la fsmFaseMarcha
};
#endif
Pisada_c.cpp
#include <Arduino.h>
#include "Pisada_c.h"
Pisada_c::Pisada_c()
{
t0=0UL;//Inicio de la fase de apoyo
t1=0UL;//inicio de la fase de balanceo
tf=0UL;//Fin de la fase de balanceo y comienzo de una nueva fase de apoyo
porcentajeReferencia_min=20;//por ahora valor arbirtrario
porcentajeReferencia_max=60;//por ahora valor arbirtrario
Estado=Apoyo;
tiempoPaso=0U;
tiempoApoyo=0U;
porcentajeApoyo=-1;
flagApoyo=true;
flagPorcentaje=false;
activarAlertas=false;
contPasos=0;
timeThreshold=100;
}
void Pisada_c::fsmFaseMarcha()
{
switch(Estado)
{
case Apoyo:
if(flagApoyo==false && millis()>t0+timeThreshold)
{
t1=millis();
tiempoApoyo=t1-t0;
Estado=Balanceo;
}
break;
case Balanceo:
if(flagApoyo==true && millis()>t1+timeThreshold)
{
tf=millis();
tiempoPaso=tf-t0;
t0=tf;
flagPorcentaje=true;
Estado=Apoyo;
if(contPasos<2)contPasos++;
if(contPasos>1) activarAlertas=true;
}
break;
}
}
void Pisada_c::calcularPorcentajeApoyo()
{
if(flagPorcentaje==true)//si se está listo para entregar un valor de porcentaje...
{
flagPorcentaje=false;
porcentajeApoyo=tiempoApoyo*100L;
porcentajeApoyo=porcentajeApoyo/tiempoPaso;
} else porcentajeApoyo=-1;
}
void Pisada_c::enviarAlerta()
{
if(porcentajeApoyo!=-1 && activarAlertas==true)
{
Serial.print("Tiempo de paso ");//Encender buzzer
Serial.println(tiempoPaso);
Serial.print("Tiempo de apoyo ");
Serial.println(tiempoApoyo);
Serial.print("Porcentaje de apoyo ");
Serial.println(porcentajeApoyo);
Serial.println("");
} //apagar buzzer
}
Error
Include_test:9: error: 'Led_c' does not name a type
Led_c Led1(R,G,B);
^
exit status 1
'Led_c' does not name a type
Thank you!!