0

relatively new to programming here, but understand the basics.

I have some code I used successfully in Arduino IDE. Starts in main, calls another function called furnaceRelay passing the variables setTemperature, temperatureC, furnaceSwitch and relayPin. When I re-typed it in PlatformIO (VisualCode), I get the "not declared in this scope" errors. I assumed it was a formatting thing (I forgot open or close {} somewhere, but can't seem to find it.

I've declared my variables, and declared the functions in main.cpp,

Function Declared before void Setup:

void furnaceRelay(float setTemperature, float temperatureC, unsigned long furnaceSwitch, int relayPin);

Declared the variables here

float temperatureC;
float setTemperature = 19;
unsigned long furnaceSwitch;
int relayPin;

Then called the function here:

  furnaceRelay(setTemperature, temperatureC, furnaceSwitch, relayPin);

And this is the function called:

void furnaceRelay(float setTemperature, float temperatureC, unsigned long furnaceSwitch, int relayPin)
{


    if ((temperatureC + 1) > setTemperature)
    {
      //Serial.println("Furnace Off");
      furnaceSwitch = millis();
      digitalWrite(relayPin, LOW);
    }

    if ((temperatureC - 1) < setTemperature)
    {
      //Serial.println("Furnace On");
      furnaceSwitch = millis();
      digitalWrite(relayPin, HIGH);
    }

    return;
}

The errors I get is:

identifier millis is undefined millis was not declared in this scope identifier digitalWrite is undefined LOW was not declared in this scope identifier LOW is undefined digitalWrite was not declared in this scope identifier millis is undefined millis was not declared in this scope identifier digitalWrite is undefined HIGH was not declared in this scope identifier HIGH is undefined digitalWrite was not declared in this scope

I'm stumped. I'm pretty sure all my {} are there, what else am I missing?

  • 1
    `millis` may be a function that's available in Arduino, but not in PlatformIO. Confirmed. The compiler can't find it because it doesn't exist. – user4581301 Jan 24 '20 at 01:08
  • Looks like millis is a monotonic count in milliseconds from the start of the device. If you add more information on how you use `furnaceSwitch` we may be able to offer alternatives. – user4581301 Jan 24 '20 at 01:12
  • In general, don't expect functions that are not part of the C++ Standard Library to be present on multiple platforms you may have to support. [`std::chrono::steady_clock`](https://en.cppreference.com/w/cpp/chrono/steady_clock) might be a good, portable alternative. If it isn't you may find yourself writing the beginnings of your very own abstraction layer to conceal the differences between multiple platforms and guaranteeing that you will always have the functions you need wherever you go. After porting the abstraction layer to the new platform, that is. – user4581301 Jan 24 '20 at 01:17
  • @user4581301 So after doing some research, I found out that in the Arduino IDE, one can seperate functions into different files and it compiles them all together without seperate header files, whereas when using C++ , one needs to create .h and .cpp files - this is why all my variables, and libraries outside of my main.cpp were showing up as undefined. Thanks for the help - now I have to teach myself how to split up a C++ project into different files...! – BartleNuts Jan 25 '20 at 18:15
  • [Here's a good answer on the steps in general](https://stackoverflow.com/questions/6264249/how-does-the-compilation-linking-process-work). Exactly what the commands are varies significantly from [toolchain](https://en.wikipedia.org/wiki/Toolchain) to toolchain. – user4581301 Jan 25 '20 at 20:31

0 Answers0