Class Declaration Error

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!

Where does the source file (ADC.cpp) include the header file (ADC.h)?

It doesn't. You told me that the header should include the source?

Also adc.h includes adc.cpp

you want the .cpp to see the .h, switch around.

what you want is 'header should be included in the source'

It doesn't. You told me that the header should include the source?

I didn't! I said that the sketch includes the header. So does the source.

Right ok, I misread that sorry.

So what includes the adc.cpp then? Wont this just get ignored?

you will also need #include <WProgram.h> in adc.cpp so analogRead can be used outside of a .pde

nothing includes it, it is the compilation unit described by the headers and defined in the .cpp

Ah cool cheers. I'll include WProgram too, I was wondering about that.

Still getting this error (amongst others because of it)

ADC.cpp:2:17: error: ADC.h: No such file or directory

It is 100% there in the folder next to the .pde and .cpp

<> looks in the core directory structure and common locations, use ""

EDIT: sorry, a bit more info.

#include <adc.h> to #include "adc.h"

Ah didnt know that. It's takes all but one compiler errors out in one fell swoop! Thanks!

Just left with this now, grrr

pointers.cpp:60:17: error: ADC.h: No such file or directory

It is there!

pointers.cpp:60:17: error: ADC.h: No such file or directory

and

ADC.cpp:2:17: error: ADC.h: No such file or directory

are same errors, different file, sure pointers.cpp has the correct include syntax

This is the top of the pointers.pde (which is the 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

A lowercase (adc.h) vs. uppercase (ADC.h) issue?

sbr_:
A lowercase (adc.h) vs. uppercase (ADC.h) issue?

Nope, everything is in upper case :frowning:

Is your sketch called pointers.cpp or pointers.pde?

When it is named pointers.pde, I have no problem compiling your code, after fixing the <> issue, including WProgram.h, adding curly braces to the sketch, and commenting out calls to undefined functions and undefined variable initialization.

Hi Paul,

It's pointers.pde

How do you mean curly braces to the sketch? I know they are {} but where do I need to put them, I'm unfamiliar with this.

Cheers mate

In the code you posted, the sketch appears to be missing the last two lines, which should contain the } to close the while loop and the loop function.

Please post the exact error message you are seeing. The IDE renames pointers.pde to pointers.pde.cpp to compile it. That name is not reflected in what you have posted so far.

Ah right yes, the loop and while are both closed. There's a bit more code in there which I didn't want to post but nothing that will impact this problem.

The exact, and only, error message I'm getting now is:

pointers.cpp:62:17: error: ADC.h: No such file or directory

Pointers, in the sketch folder is a .pde, along with ADC.cpp and ADC.h

#include <ADC.h> is before half way down still, if that is one file you posted, you included the header twice

look for the block

///////////////////////////////////////////////////////////////////////////
/*-----------------------------------------------------------------------*/
///////////////////////////////////////////////////////////////////////////
/////////////////////////////FINALISED CODE////////////////////////////////
///////////////////////////////////////////////////////////////////////////


#include <ADC.h>

///////////////////////////////////////////////////////////////////////////

Yep found it, not sure how it got there!!

Well would you believe it troops, it compiles! 6412bytes which is a lot but then it's not the most elegant code!

Many many thanks for all your help, until next time (I give it 20mins lol).

Simon

PS: If you hadn't guessed from the odd comment this will be for a control system for a Hydrogen PEM fuel cell hybrid which is the topic for my engineering PhD in implementing a fuel cell into a small, lightweight, unmanned aerial vehicle. I'll ensure everyone gets referenced in my thesis!