Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Arduino "function" issue.
Arduino "function" issue. [message #1791137] Sun, 24 June 2018 23:32 Go to next message
Travis Durf is currently offline Travis DurfFriend
Messages: 3
Registered: June 2018
Junior Member
I am looking to use the Arduino C++ IDE and having an issue with Functions. When I create a void function such as this:
void loop() {
   buttoncheck();
}

void buttoncheck(){
  int reading;
  reading = digitalRead(buttonPin);
}



I end up with two errors related to it:
"buttoncheck" was not declared in this scope
and
Invalid arguments 'Candidates are: void buttoncheck()'

It will still save and send the project over to the UNO and performs the other parts in the loop, but it fails to call the function. I have copied and pasted the complete code into the standard Arduino IDE as well as the other Eclipse plugin and it works fine in them. I did not include the full "buttoncheck" code of course it won't do anything like that.
Re: Arduino "function" issue. [message #1791477 is a reply to message #1791137] Sat, 30 June 2018 07:56 Go to previous messageGo to next message
Tauno Voipio is currently offline Tauno VoipioFriend
Messages: 400
Registered: August 2014
Senior Member
Please move buttoncheck() before loop(). The compiler will not care, but the plugin might need the function declared before the call.


--

Tauno Voipio
Re: Arduino "function" issue. [message #1791525 is a reply to message #1791477] Mon, 02 July 2018 00:04 Go to previous messageGo to next message
Travis Durf is currently offline Travis DurfFriend
Messages: 3
Registered: June 2018
Junior Member
Thanks for the info. As it took a few days for post to be approved and posted here, I did alternately come across the issue was the functions need forward declared. Like you have suggested. The other person that suggested that may be the case, was reading the eclipse newsletter that details the plugin and read it that it should "not" be needed. I reread it and it actually seems to say that it "is" needed because it seems to be saying that you "don't" have to on the standard Arduino IDE, meaning you do have to on this.

So the correction is either to move buttoncheck() before anything that calls it, or define it before hand it seems. I almost tried moving the buttoncheck() up in the code as I had some vague recollection of something like that in some other programming I did years ago, but I have long forgotten if it was when I was doing some thing with C++. I am glad I found out I can declare the functions at the top then finish them out down below in an alternate order.


void buttoncheck();

void loop() {
   buttoncheck();
}

void buttoncheck(){
  int reading;
  reading = digitalRead(buttonPin);
}


It is easier to define them at the top before any functions happen, rather than going down the line and find out something is "out of order" trying to sort out why something wasn't happening. If I miss that it is marked with an error, it still compiles and sends to the Arduino board, it just fails to call the function when it was supposed to. Other errors would cause it to not send it and give an error, but these seem to still go through and the rest of the code still operates.
Re: Arduino "function" issue. [message #1792707 is a reply to message #1791525] Mon, 23 July 2018 02:12 Go to previous message
Vaclav Sal is currently offline Vaclav SalFriend
Messages: 185
Registered: September 2014
Senior Member
The answer is in Arduino IDE .ino file.
Study Arduino source code for main() file and then look at BareBones.ino (sic?) Arduino IDE example.
Then read in-between lines on Arduino forum to find out how standard C/C++ main function is bastardized to be "beginners friendly".
#include(s) , preprocessor directives and function prototypes are all hidden or build for you resulting in .ino stripped down file.
Previous Topic:CDT doesn't save project environment variables
Next Topic:Missing IExecutionDMContext to resume a debug session
Goto Forum:
  


Current Time: Wed Sep 26 08:24:05 GMT 2018

Powered by FUDForum. Page generated in 0.01485 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top