Welcome, Guest. Please Login or Register
Arduino IDE for Visual Studio
 
 
When Logging a Support Issue in the Forum, please ensure you have also:-
  • Enabled vMicro > Compiler > Show Build Properties and Verbose
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
Support requests without the output above may be impossible to answer, so please help us to help you
 
  HomeSearch Tutorials & Wiki visualmicro.com LoginHelpRegister  
 
Page Index Toggle Pages: 1
Send Topic Print
Using millis() in a class method - out of scope (Read 2486 times)
davidbal
Junior Member
**
Offline



Posts: 18
Using millis() in a class method - out of scope
Jul 25th, 2017 at 12:16pm
 
When I try to use millis() in a class method e.g.

void GeneralTimer::startTimer(unsigned long dur)
{
     duration = dur;
     startTime = millis();
     endTime = startTime + duration;
}

The compiler complains millis() is out of scope. I can understand why as it is a standard arduino library, but can't see a way of resolving the scope.

I have seen an example here https://learn.adafruit.com/multi-tasking-the-arduino-part-1/a-classy-solution where it seems to work, although it is all defined within the class.

Any tips?

Regards,

David
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10388
United Kingdom
Re: Using millis() in a class method - out of scope
Reply #1 - Jul 25th, 2017 at 12:32pm
 
have you included the arduino.h in your code?
Back to top
 
WWW  
IP Logged
 
davidbal
Junior Member
**
Offline



Posts: 18
Re: Using millis() in a class method - out of scope
Reply #2 - Jul 25th, 2017 at 12:59pm
 
Thanks, that fixed the problem.
It is quite a big project with multiple files and thought it might of already been included. But obviously not.

I get the feeling that the .ino file includes that file automatically?

Regards,

David
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10388
United Kingdom
Re: Using millis() in a class method - out of scope
Reply #3 - Jul 25th, 2017 at 1:21pm
 
Yes when .ino is converted to .cpp the include is added

When you create new .cpp/h files using the visual micro menus the arduino.h is included for you

If you create your own cpp/h files manually you will always need to include the arduino.h
Back to top
 
WWW  
IP Logged
 
davidbal
Junior Member
**
Offline



Posts: 18
Re: Using millis() in a class method - out of scope
Reply #4 - Jul 25th, 2017 at 7:56pm
 
OK Thanks..I will remember that tip...

Regards,

David
Back to top
 
 
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print