Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic does not name a type (Read 2536 times)
chema
Newbies
*
Offline


Posts: 2
Location: Spain
Joined: Mar 23rd, 2018
does not name a type
Mar 23rd, 2018 at 7:13pm
Print Post  
Hi. When I build my code, Visual Studio report next error:

"lcd.ino: 18:1: error: 'veloRes' does not name a type veloRes velocimetro(int pin)
Error compiling project sources
Build failed for project 'lcd' "

Then I build my code in arduino IDE but there are not error.

Why doesn't run in VisualStudio? Know anyone how to fix this build error?

Thanks.

My code is (The comments are in spanish but it are irrelevant for the question):

Code (C++)
Select All
#include <LiquidCrystal_I2C.h>
#include <LiquidCrystal.h>
#include <Wire.h>


//estructura de datos para la función velocímetro
struct veloRes
{
	double velocidad;//almacena la velocidad
	double frecuencia;//almacena la frecuencia
	bool valido;//almacena si la medida ha sido válida o no
	String msg;//si algo ha fallado se almacena aquí un mensaje descriptivo
};

//Crear el objeto lcd  dirección  0x27 y 16 columnas x 2 filas
LiquidCrystal_I2C lcd(0x27,16,2);

veloRes datos = { 0,0,false,"" };


const int pinVel = 7;//pin para conectar el radar

const int nLect = 4;//número de lectiras para realizar una medida

//Función que devuelve la velocidad, la frecuencia y los errores si los hay
veloRes velocimetro(int pin) {

	veloRes resultados;
	long matAnchoPulso[nLect];
	long pulso_tot = 0;
	resultados.velocidad = 0;
	resultados.frecuencia = 0;
	resultados.valido = false;
	resultados.msg = "";

	noInterrupts();//Desactiva las interrupciones

	pulseIn(pin, HIGH);

	for (int i = 0; i < nLect; i++)//realiza las lecturas necesatias
	{
		long anchoPulso = 0;
		anchoPulso = pulseIn(pin, HIGH);
		anchoPulso += pulseIn(pin, LOW);

		matAnchoPulso[i] = anchoPulso;
		pulso_tot += anchoPulso;
		if (anchoPulso == 0)//si no ha habido pulso esctibe un mensaje de error y devuelve los valores
		{
			resultados.valido = false;
			resultados.msg = "pulso 0";
			interrupts();
			return resultados;
			break;
		}

	}

	interrupts();//activa las interrupciones



	for (int i = 0; i < nLect - 1; i++)//comprueba que el ancho de los pulsos no varíe demasiado
	{//si los pulsos no son más o menos del mismo tamaño saca un error como resultado
		if (((matAnchoPulso[0] * 2) < matAnchoPulso[i + 1]) || ((matAnchoPulso[0] / 2) > matAnchoPulso[i + 1]))
		{
			resultados.valido = false;
			resultados.msg = "pulso no válido";
			return resultados;
			break;
		}
		else//si no pone a true la variable
		{
			resultados.valido = true;
		}
	}
	//si todoes correcto calcula la frecuencia y la velocidad y devuelve los resultados
	resultados.frecuencia = double(1000000 / (pulso_tot / nLect));
	resultados.velocidad = double(resultados.frecuencia / 19.49);
	resultados.msg = "todo OK";

	return resultados;
}

void setup() {

	//se inicializa la pantalla

  lcd.init(); 
  lcd.backlight();

  //se declara comoentrada el pin para el radar

  pinMode(pinVel, INPUT);
 
}

void loop() {

	//se mide la velocidad
	datos = velocimetro(pinVel);

	if (datos.valido)//si elcálculo ha salido bien, se sacan por la pantalla los resultados
	{
		pantalla(datos.velocidad, datos.frecuencia);
	}
	else//si no, se saca por la pantalla el mensaje de error
	{
    lcd.clear();
	lcd.print(datos.msg);
	}

	delay(500);//tiempo de espera entre medidas



}
//función para sacar los datos por pantalla
void pantalla(double vel, double freq){

	lcd.clear();

	lcd.setCursor(0, 0);
	lcd.print("Vel: ");
	lcd.print(vel,1);
	lcd.print("km/h");

	lcd.setCursor(0, 1);
	lcd.print("frec: ");
	lcd.print(freq,1);
	lcd.print("Hz");

} 

  
Back to top
 
IP Logged
 
Jo Sto
Ex Member
*


Re: does not name a type
Reply #1 - Mar 23rd, 2018 at 9:03pm
Print Post  
chema wrote on Mar 23rd, 2018 at 7:13pm:
//Función que devuelve la velocidad, la frecuencia y los errores si los hay
veloRes velocimetro(int pin) {

If i use Quote:

//Función que devuelve la velocidad, la frecuencia y los errores si los hay
struct veloRes velocimetro(int pin) {

it compiles in both ides. But why?
  
Back to top
 
IP Logged
 
chema
Newbies
*
Offline


Posts: 2
Location: Spain
Joined: Mar 23rd, 2018
Re: does not name a type
Reply #2 - Mar 23rd, 2018 at 9:48pm
Print Post  
Sorry I'm a beginner. It has built with that change.

Thank you very much.

Why Arduino IDE does not report some errors that it should?
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint