Go Down

Topic: Division Problem (Read 7846 times) previous topic - next topic

howroyd

when you start a new tab it call it "whatever you type".pde!! But that is by the by, the extention technically doesnt matter (or at least it doesnt in any ide ive used before), it's only aesthetics, neither does putting a 'C' at the front of a name.

As I say I'm new to the arduino IDE, some compilers automatically include anything in the same sketch/workspace.  Eg atollic, eclipse, PICC

PaulS

Quote
when you start a new tab it call it "whatever you type".pde!!

Unless "whatever you type" includes a recognized extension, like .h or .cpp.
The art of getting good answers lies in asking good questions.

howroyd

Yep got that now.

Still getting the same error
Quote
ADC.cpp:4:17: error: ADC.h: No such file or directory

PaulS

We need to see your .pde file, your ADC.cpp file, your ADC.h file, and a screen shot of the IDE showing all the tabs.
The art of getting good answers lies in asking good questions.

howroyd

Main .PDE file (interesting bits only)
Code: [Select]
#include <ADC.cpp>
#define verbose  // Prints everything to screen for debugging
#define data     // Forces getV and getI to pump out random gobbleijuke

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->getV();
    outputInts[1] = pMyAdc->getI();


ADC.cpp
Code: [Select]
#ifndef ADC
#define ADC

#include <ADC.h>

// ADC
int CAdc::adcReadV(){
#ifndef data
  return(analogRead(vPin));  // 0 to 1023
#endif
#ifdef data
  if(counter<75){
    counter++;
    return(*pDummyData++);
  }
  else{
    counter = 0;
    pDummyData = dummyData;
    return(*pDummyData++);
  }
#endif
}


int CAdc::adcReadI(){
#ifndef data
  return(analogRead(iPin));  // 0 to 1023
#endif
#ifdef data
  if(counter<75){
    counter++;
    return(*pDummyData++);
  }
  else{
    counter = 0;
    pDummyData = dummyData;
    return(*pDummyData++);
  }
#endif
}


int CAdc::getV(){
  v = adcReadV();                // Calibration code (if any)
#ifdef verbose
  Serial.print("adcReadV=");
  Serial.println(v,DEC);
#endif
  return v;
}


int CAdc::getI(){
  i = adcReadI();                // Calibration code (if any)
#ifdef verbose
  Serial.print("adcReadI=");
  Serial.println(i,DEC);
#endif
  return i;
}

#endif


ADC.h
Code: [Select]
// ADC
class CAdc {
public:
#ifndef data
  CAdc(){
    v=0,i=0;
  }
#endif
#ifdef data
  CAdc(){
    v=0,i=0,counter=0;
  }
  #endif
  int getV();
  int getI();
private:
  int adcReadV();
  int adcReadI();
  int v;
  int i;
#ifdef data
  int counter;
#endif
};


Dont know how to put an image but the tabs read:
pointers (this is the main pde)
ADC.cpp
ADC.h


Thanks for your help

PaulS

#35
Nov 17, 2011, 01:05 pm Last Edit: Nov 17, 2011, 01:08 pm by PaulS Reason: 1
Code: [Select]
#include <ADC.cpp>
You need to include the header file, not the source file, in the sketch.

Code: [Select]
    pDummyData = dummyData;
Where is dummyData defined?

Why are you making this class so complicated?
The art of getting good answers lies in asking good questions.

howroyd

#36
Nov 17, 2011, 01:08 pm Last Edit: Nov 17, 2011, 01:15 pm by howroyd Reason: 1
Ok.

Isn't including the .cpp which then includes the .h the same as including the .h which then includes the .cpp?

I appreciate there is a convention but I'm an engineer not a programmer so like to get stuff working my way then tidy it up later  :P

Quote
Where is dummyData defined?

dummyData is a global variable that has pDummyData as a pointer to it, however this is not where the problem lies.

Quote
Why are you making this class so complicated?

It is as complicated as it needs to be for the ADC functionality I need -> read data from sensors, or provide dummy data.

PaulS

Quote
Isn't including the .cpp which then includes the .h the same as including the .h which then includes the .cpp?

No.

The IDE copies the sketch, and all files referenced in the sketch to another directory for compilation. It also copies any .cpp files that are related to any .h files that it copies.

So, when the sketch includes the source file, the sketch and source file are copied, but the header file is not.

When the sketch includes the header file, the sketch and header file and source file are copied.

In the copied location, the compiler is executed, and sees that the .cpp file needs to be dealt with, so it tries to compile it. If the header file was not included in the sketch it isn't copied, so it will not be found.
The art of getting good answers lies in asking good questions.

Go Up