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 Unable to Compile in VS2010 (Read 5836 times)
tpbw
Newbies
*
Offline


Posts: 3
Joined: Dec 23rd, 2012
Unable to Compile in VS2010
Dec 23rd, 2012 at 6:43pm
Print Post  
Hi,

I have some code that I am able to compile in the Arduino IDE but when I try and compile it in VS2010 it give me a compiling error. It started when I started implementing a structure.

These are the errors I get
Code
Select All
Compiling 'funWithSounds' for 'Arduino Uno'
funWithSounds.ino : variable or field 'playBack' declared void
funWithSounds.ino : 'musicNote' was not declared in this scope
funWithSounds.ino : expected primary-expression before 'int'
Error compiling
 



This is the code associated with the sections in descending order.

This is the Definition of the Structure
Code
Select All
struct musicNote
{
	char note;              //note
	unsigned int beat;      //length played
};

 



I used a function declaration at the beginning of the program
Code
Select All
void playBack(musicNote note[], int arrySize);         //plays back contents in musicNote
 



This where I declared my musicNote variable
Code
Select All
musicNote note[MAX];         //all notes are recorded to this structure
 



This is how the function is called.
Code
Select All
playBack(note, tuneLen);
 



This is the definition of the function
Code
Select All
void playBack(musicNote note[], int arrySize)
{
	for( int i = 0; i < arrySize; i++)
	{
		if (note[i].note == 'c')
			for (int j = 0; j < note[i].beat; j++)
				playNote(soundPin, 1915); 

		if (note[i].note == 'b')
			for (int j = 0; j < note[i].beat; j++)
				playNote(soundPin, 1700); 

		if (note[i].note == 'a')
			for (int j = 0; j < note[i].beat; j++)
				playNote(soundPin, 1519);
		if (note[i].note == '.')
		{
			sensorValue = analogRead(sensorPin);
			Serial.print(sensorValue);
			Serial.print('\n');
			delay((note[i].beat)/(sensorValue + 50));
		}
	}
}
 



Before I added the structure the program compiled fine and uploaded to the Arduino with no issues. Thanks for any help.

TPBW4321
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Unable to Compile in VS2010
Reply #1 - Dec 23rd, 2012 at 7:46pm
Print Post  
Does it compile if you exclude the function definition?

Code
Select All
//void playBack(musicNote note[], int arrySize);  



Please email the sketch to info [at] visualmicro.com
  
Back to top
IP Logged
 
tpbw
Newbies
*
Offline


Posts: 3
Joined: Dec 23rd, 2012
Re: Unable to Compile in VS2010
Reply #2 - Dec 24th, 2012 at 12:03am
Print Post  
No it does not compile after commenting that section out. I sent the you the source

Tim@Visual Micro wrote on Dec 23rd, 2012 at 7:46pm:
Does it compile if you exclude the function definition?

Code
Select All
//void playBack(musicNote note[], int arrySize);  



Please email the sketch to info [at] visualmicro.com

  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Unable to Compile in VS2010
Reply #3 - Dec 24th, 2012 at 12:19am
Print Post  
Thanks I have the sketch.

If I comment out the prototypes I get exactly the same error when I compile using Arduino 1.0.3 as I do in Visual Studio. Prototypes are not normally required because they are created automatically

I'll look into over the next few days

In the meantime you can enable the "External Editor" option in the arduino ide "File>Preferences". This option allows you to leave the sketch open in the arduino ide at the same time as editing in VS. Use the Arduino IDE for compile/upload.

Thanks

« Last Edit: Dec 24th, 2012 at 12:26am by Tim@Visual Micro »  
Back to top
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Unable to Compile in VS2010
Reply #4 - Dec 24th, 2012 at 12:57am
Print Post  
I have found the problem. You might know that normally the prototypes are automatically created and added to the top of the sketch (below any #includes).

In your case one of your prototypes (playBack), uses a struct (musicNote) that is also defined in the same sketch. So in this case, it doesn't make sense (is an error) to add prototypes to the top of your sketch.

I'll change vm in the next release to prevent it automatically adding prototypes if they already exist. It's something I have been meaning to do anyway and the more recent versions of the Arduino IDE do the same. This is why is works in arduino but not in VS.

There is an easy fix if it meets your needs. You can add a ".h" to your sketch project, #include it at the top of beatMaker.ino and  move the musicNote struct from the .ino to the .h

Code
Select All
struct musicNote
{
	char note;              //note
	unsigned int beat;      //length played
};
 



The .h needs to reside in the same folder as the beatMaker.ino. 

The best way to add a .h is to right click the beatMaker project in the solution explorer and click "Add new item"

With this solution we also remove the need to create prototypes for all the methods in your code.

Example: I created a breatMaker.h and moved the struct to it. The compile then worked. I also tried commenting out all of your prototypes and the compile still worked. So you might consider this a more productive solution. See below...

Code
Select All
#include "beatMaker.h"
#define MAX 500 

const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin
const int playBackPin = 8;
const int soundPin = 9;
const int dPin = 10;
const int ePin = 11;
const int recordPin = 12;
const int sensorPin = 1;

// variables will change:
int buttonState = 0;         //c
int buttonState2 = 0;        //d
int buttonState3 = 0;        //e
int buttonState4 = 0;        //record
int buttonState5 = 0;        //playBack
int recordState = 0;         //if recording
int sensorValue = 0;         //variable Resistor
int i = 0;
int tuneLen = 0;             //length of tune
int delayLen = 0;            //note play length
musicNote note[MAX];         //all notes are recorded to this structure

//void playBack(musicNote note[], int arrySize);         //plays back contents in musicNote
//void playNote(const int pin, int note);                //plays a single note
//void clearNotes();                                     //clears musicNote
//void readPins();                                       //reads all inputs
//int rec();

void setup() {
 

« Last Edit: Dec 24th, 2012 at 1:32pm by Tim@Visual Micro »  
Back to top
IP Logged
 
tpbw
Newbies
*
Offline


Posts: 3
Joined: Dec 23rd, 2012
Re: Unable to Compile in VS2010
Reply #5 - Dec 24th, 2012 at 1:20am
Print Post  
Awesome thanks for the info.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint