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 Using millis() in a class method - out of scope (Read 5033 times)
davidbal
Junior Member
**
Offline


Posts: 29
Joined: Dec 20th, 2015
Using millis() in a class method - out of scope
Jul 25th, 2017 at 11:16am
Print Post  
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
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Using millis() in a class method - out of scope
Reply #1 - Jul 25th, 2017 at 11:32am
Print Post  
have you included the arduino.h in your code?
  
Back to top
WWW  
IP Logged
 
davidbal
Junior Member
**
Offline


Posts: 29
Joined: Dec 20th, 2015
Re: Using millis() in a class method - out of scope
Reply #2 - Jul 25th, 2017 at 11:59am
Print Post  
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
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Using millis() in a class method - out of scope
Reply #3 - Jul 25th, 2017 at 12:21pm
Print Post  
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: 29
Joined: Dec 20th, 2015
Re: Using millis() in a class method - out of scope
Reply #4 - Jul 25th, 2017 at 6:56pm
Print Post  
OK Thanks..I will remember that tip...

Regards,

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