Error compiling with Workbench

@rickkas7

I recently updated Workbench on both a Windows PC and a Macbook Pro.

I used the new project template as the basis for some test code - sampling A0 at a 10 Hz rate but both systems reported compile errors. The initial unedited version of the file compiles, flashes and runs successfully. Simply adding the Timer line in the following code cause a compiler error as below. Comment out the Timer reference and the code flashes and runs OK again.

I would appreciate any advice as to what I am doing wrong - the syntax is identical to that in the reference docs for the Timer routine.

Thanks
Bruce

/* 
 * Project myProject
 * Author: Your Name
 * Date: 
 * For comprehensive documentation and examples, please visit:
 * https://docs.particle.io/firmware/best-practices/firmware-template/
 */

// Include Particle Device OS APIs
#include "Particle.h"

// Let Device OS manage the connection to the Particle Cloud
SYSTEM_MODE(AUTOMATIC);

// Run the application and system concurrently in separate threads
SYSTEM_THREAD(ENABLED);



// Show system, cloud connectivity, and application logs over USB
// View logs with CLI using 'particle serial monitor --follow'
SerialLogHandler logHandler(LOG_LEVEL_INFO);
Timer measurePressure(100,sampleADC);

int16_t volatile ADCvalue;
boolean volatile newsample;

void sampleADC()
{
ADCvalue=analogRead(A0);
newsample=true;
}


// setup() runs once, when the device is first turned on
void setup() {

}

// loop() runs over and over again, as quickly as it can execute.
void loop() {
  // The core of your code will likely live here.

  // Example: Publish event to cloud every 10 seconds. Uncomment the next 3 lines to try it!
   Log.info("Sending Test-install  !");
   //Particle.publish("Test-install v2");
   delay( 10 * 1000 ); // milliseconds and blocking - see docs for more info!
}

Output from the compiler shows the following error

src/Test-install.cpp:16:13: warning: System thread is enabled by default starting with Device OS 6.2.0. SYSTEM_THREAD(DISABLED) may still be explicitly called, however non-threaded behavior is soon to be completely deprecated in later releases.
   16 | SYSTEM_THREAD(ENABLED);
      |             ^~~~~~~~~~~                                                                                                                                                                                                      
src/Test-install.cpp:23:27: error: 'sampleADC' was not declared in this scope
   23 | Timer measurePressure(100,sampleADC);
      |                           ^~~~~~~~~
make[2]: *** [../build/target/user/platform-25-msrc/Test-install.o] Error 1
make[2]: Leaving directory `/firmware/user'
make[1]: *** [user] Error 2

This declaration:

Timer measurePressure(100,sampleADC);

needs to be moved after the declaration of the sampleADC function (or a forward declaration used).

@rickkas7 Thanks. I was using as a reference code I had used a few years ago on a Photon in which I had declared several timers towards the top of the and in which the void's followed later in the body of the code. Shifting the Timer declaration after definition of the void did the trick.

That has fixed the Windows version - I need to check the Macbook version which was also reporting an inability to find the Particle.h file. I tried the Intellisense fix you suggested in a reply to a post in Sept '23 but it did not improve the situation. Now I have the Windows version operating correctly I will address the Macbook issue seperately.

Thanks for the prompt reply as usual.