Multiple variable definition error when compiling with .h and .cpp file tabs

The xxx.h file should only contain DECLARATIONS of classes, variables, and function prototypes that are DEFINED in your xxx.cpp file AND are needed by OTHER files to use the features of your xxx.cpp file. Global variables and functions that you want to keep confined to xxx.cpp should be DEFINED / DECLARED in that file with the 'static' key word. The example below includes only variables and functions since it doesn't look like you're using classes:

testing.h:

#ifndef TESTING_H
#define TESTING_H

// The variables DECLARED here will be avaiable to every file that includes 'testing.h'
extern int globalInt;
extern bool globalBool;

// // The functions DECLARED here will be available to every file that includes 'testing.h'
void globalFunction1(void);
int globalFunction2(int);

#endif

testing.cpp:

#include <Arduino.h>
#include "testing.h"

// DEFINE the global variables here. Avaiable to every file that includes 'testing.h'.
int globalInt;
bool globalBool;

// DEFINE secrete global variables here. Only visible in this file.
static int secreteInt;
static bool secreteBool;

// DECLARE secrete functions here.  Only visible in this file.
static void secreteFunction1(void);
static int secreteFunction2(int);

// DEFINE global functions here.  Avaiable to every file that includes 'testing.h'.
void globalFunction1() {
  secreteFunction1();
}

int globalFunction2(int x) {
  return secreteFunction2(x) + secreteInt;
}


// DEFINE secrete functions here.  Only visible in this file.
static void secreteFunction1() {
  secreteBool = !secreteBool;
}

static int secreteFunction2(int x) {
  return x;
}

.ino file:

#include "testing.h"
void setup() {
  int localInt;
  bool localBool;

  // Access the global variables
  localInt = globalInt;
  localBool = globalBool;

  /// Call the global functions
  globalFunction1();
  localInt = globalFunction2(54);
}

void loop() {}
1 Like