Hi all, I could do with another set of eyes on this. It's a repost from my division problem thread since it went off topic.
I'm new to the Arduino ide, and am trying to setup some code using tabs to keep things organised, however when I put a class in a tab, include it, it's having none of it. Here are the files and the error:
main file
#include <Wire.h>
#include <ADC.h>
#define verbose // Prints everything to screen for debugging
#define data // Forces getV and getI to pump out random gobbleijuke
// constants won't change. Used here to
// set pin numbers:
const unsigned long period = 50; // the number of milliseconds per loop (100ms=10Hz)
const byte ledPin = 13; // the number of the LED pin
const byte hPin = 0; // the number of the H2 servo pin
const byte vPin = 7; // the number of the voltage ADC pin
const byte iPin = 6; // the number of the current ADC pin
const byte sda = 4; // the number of the current I2C sda pin
const byte scl = 5; // the number of the current I2C scl pin
const byte ID = 0x72; // 7-bit I2C address (0xE4,0xE5)
#ifdef data
int dummyData[100] = {
123,456,789,234,567,890,345,678,901,123,456,789,234,567,890,345,678,901,123,456,789,234,567,890,345,678,901,123,456,789,234,567,890,345,678,901,123,456,789,234,567,890,345,678,901,123,456,789,234,567,890,345,678,901,123,456,789,234,567,890,345,678,901,123,456,789,234,567,890,345,678,901,123,456,789,234,567};
int* pDummyData;
#endif
CAdc myAdc; // Construct the ADC class
CAdc *pMyAdc = &myAdc;
void setup()
{
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
analogReference(EXTERNAL); // Use analogue reference pin (3v3)
Wire.begin(ID);
Wire.onReceive(receiveEvent); // register event
Wire.onRequest(requestEvent); // register event
Serial.begin(115200);
}
void loop()
{
#ifdef data
pDummyData = dummyData;
#endif
while(true){
#ifdef verbose
Serial.println("**ADC**");
#endif
// Read in voltage and current from ADC
outputInts[0] = pMyAdc->getAdc(vPin);
outputInts[1] = pMyAdc->getAdc(iPin);
ADC.h
#ifndef ADC_H
#define ADC_H
#include <ADC.cpp>
// ADC
class CAdc {
public:
#ifndef data
CAdc(){
adcVal=0;
}
#endif
#ifdef data
CAdc(){
adcVal=0,counter=0;
}
#endif
int getAdc(int pin);
private:
int adcRead(int pin);
int adcVal;
#ifdef data
int counter;
#endif
};
#endif
ADC.cpp
// ADC
// Real data read
#ifndef data
int CAdc::adcRead(int pin){
return(analogRead(pin)); // 0 to 1023
}
#endif
// Dummy data read
#ifdef data
int CAdc::adcRead(int pin){
if(counter<75){
counter++;
return(*pDummyData++);
}
else{
counter = 0;
pDummyData = dummyData;
return(*pDummyData++);
}
}
#endif
// Getter
int CAdc::getAdc(int pin){
adcVal = adcRead(pin);
#ifdef verbose
Serial.print("adcRead=");
Serial.println(adcVal,DEC);
#endif
return adcVal;
}
Error when compiling
ADC.cpp:4: error: 'CAdc' has not been declared
ADC.cpp: In function 'int adcRead(int)':
ADC.cpp:5: error: 'analogRead' was not declared in this scope
ADC.cpp: At global scope:
ADC.cpp:25: error: 'CAdc' has not been declared
ADC.cpp: In function 'int getAdc(int)':
ADC.cpp:26: error: 'adcVal' was not declared in this scope
Many thanks in advance to everyone helping me!