Hi, Many thanks for your help, this is a cut down version of a program running on a device on my front gate which has been working for about 5 years but I am using a copy of it to practice, it works fine with the 3 functions all on main.cpp but not when separated, the libraries and variables on main.cpp are out of scope.
//----------main.cpp-----------------
#include <Arduino.h>
#include "functions.h"
#include <RF24Network.h> //Network library
#include <RF24.h> //Radio library
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h> //Needed for Temperature sensor
#include "Wire.h"
//************Variables etc***********************
OneWire oneWire(4); //Pin number for DS18B20 temperature sensor
DallasTemperature sensors(&oneWire);
RF24 radio(9, 10); // nRF24L01(+) radio attached
RF24Network network(radio);
int Ledpin = 8;
int Gate, Gstate;
const uint16_t Base = 00;
const uint16_t GateTX = 03;
float GtempC, Volts;
struct payload_t
{ //Universal payload structure used on several devices
float Flt_1;
float Flt_2;
int Integ_1;
int Integ_2;
};
payload_t payload;
void setup()
{
SPI.begin();
Serial.begin(9600);
sensors.setResolution(10); //For DS18B20 Sensor
radio.begin(); //Start radio
radio.setPALevel(RF24_PA_HIGH); //Set power level high on radio
network.begin(90, GateTX); //Channel and Address of this node
radio.startListening();
radio.setDataRate(RF24_250KBPS); //Set data rate
radio.setRetries(15, 15);
Wire.begin();
pinMode(Ledpin, OUTPUT);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
} //End of Setup
void loop()
{
network.update();
if (digitalRead(2) == LOW) //Gate is opening
{
Gstate = 10; //10 = gate opening
Volts = Voltage();
GtempC = Temperature();
payload = {GtempC, Volts, Gstate, 0 }; //Set the payload data followed with dummy data
Sending();
//Double flash indicates opening
digitalWrite(Ledpin, HIGH);
delay(150);
digitalWrite(Ledpin, LOW);
delay(150);
digitalWrite(Ledpin, HIGH);
delay(150);
digitalWrite(Ledpin, LOW);
}
delay(3000);
if (digitalRead(3) == LOW)
{
Gstate = 5; //5 = gate closing
Volts = Voltage();
GtempC = Temperature();
payload = {GtempC, Volts, Gstate, 0}; //Set the payload data
Sending();
//Single flash indicates closing
digitalWrite(Ledpin, HIGH);
delay(150);
digitalWrite(Ledpin, LOW);
}
} //End of Loop
//-----------------functions.cpp------------------------------
#include <Arduino.h>
float Voltage()
{
float Volts;
int sensorValue = analogRead(A0); // read the input on analog pin A0:
Volts = sensorValue * (3.39 / 1023.0); // Convert the analog reading
Volts = Volts * 2.0;
return Volts;
}
float Temperature()
{
sensors.requestTemperatures(); //Fetch temperatures
float tempC = sensors.getTempCByIndex(0); //And load variable with correct data
delay(100);
return tempC;
}
void Sending() //Send data back
{
delay(100);
RF24NetworkHeader header(Base); //Set address to go to
radio.stopListening();
network.write(header, &payload, sizeof(payload)); // Transmit the data
radio.startListening();
radio.read(&payload, sizeof(payload)); // Listen for acknowledgment from the receiver
delay(100);
network.update();
}
//--------------functions.h-----------------------
float Voltage();
void Sending();
float Temperature();
//---------ERRORS------
in functions.cpp
'sensors' was not declared in this scope
'RF24NetworkHeader' was not declared in this scope
'radio' was not declared in this scope
'network' was not declared in this scope
'header' was not declared in this scope
'payload' was not declared in this scope