Larger sketches..

I'd like to know how to export some functions from my existing sketch into a different file that can then be included into the sketch.

I've tried various methods to include the code, but no luck.

My expectation would be to use something like

#include <regularlibfiles.h>
#include <myotherfunctions.ino>

void setup(){
  // setup code
}

void loop{
  function_in_myotherfunctions(); // Calling a function from my other source file.
}

Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the # button above the posting area.

Define "no luck"? Error? If so, what? Doesn't work? Spontaneous combustion? Smoke?

#include <myotherfunctions.ino>

I wouldn't be doing that. Just include the .h files. Your other files would normally be .cpp files. Plus you should make a tab in the IDE for them. Don't just plonk them in the directory. Hit the "new tab" button (top RH corner), name your .h and .cpp files as appropriate, and put stuff in them.

Here's a pair of functions that I set up as a test, it's in HitCounter.h which is in the same directory of the main sketch.
When I open the main sketch, the HitCounter file is also opened at the same time, in another tab, but when I compile, I get an error: "Function definition does not declare parameters" Neither function takes a passed parameter, or returns one, so I don't understand the error message.

In the main sketch, I get an error saying that "HitCounter was not declared in this scope"

char Hits      = 0;

void HitCounter{
 Hits++; 
}


long Uptime    = 0;
long LastUpTime = 0;

void Update_Uptime(){
  if (millis() - LastUpTime < 1000){return;}
  Uptime++;
  LastUpTime = millis();
}

In the main application, I have this:

#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include "HitCounter.h"

(other things that are irrelevant)


// Glorious main loop with nothing in it.
void loop(){
  //pinMode(3,OUTPUT);
  //digitalWrite(3,HIGH);
  Update_Uptime();   // One function I'm trying to use 
  web();
  //digitalWrite(3,LOW);
  DS_Temp();
}

// Handles serving up pages if someone is connected
void web(){ 
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    HitCounter();   // The other one I'm trying to use.
    
(more code not relevant to the issue)

}
void HitCounter{
 Hits++; 
}

Well? Where are the parameters? The error said it does not declare parameters. You want something like:

void HitCounter ()
{
 Hits++; 
}

Besides, .h files are usually for headers, not procedural code. It should be something like:

void HitCounter();
void Update_Uptime();

And then add a .cpp file that actually implements those functions.

Ok, I was looking right past the problem. The HitCounter function wasn't properly formed.

Thanks!