Problem with inherited classes

Hello,

Im having some toubles with the use of inherited classes in my program. the problem is that i cant call none of my funcions wether they are inherited or owned by the class.

Heres a snippet of the program

#include "pyr.h"
#include "LDR.h"
#include "arduino.h"

light asd; //Creating the object


void setup(){ asd.Set_parameters(1,10); } //modifying its data

void loop(){
  Serial.print(asd.Get_pin()); //getting data back
  delay(100);
}

I will attach the archive. The program consist of a main sensor library being called by other kinds of sensors. Focus on the LDR one.

im a noob though

DATALOGGER.zip (2.39 KB)

DATALOGGER.ino (265 Bytes)

LDR.h (217 Bytes)

ldr_measurement.cpp (872 Bytes)

pyr.h (289 Bytes)

Sensor_conf.cpp (495 Bytes)

Sensor_main.h (503 Bytes)

Nothing attached... And now that is still the case, DON'T. Make a simple example of your case and post the code (or multiple blocks) inline (yeah, just here) in code-tags! See How to use the forum for that.

septillion: Nothing attached... And now that is still the case, DON'T. Make a simple example of your case and post the code (or multiple blocks) inline (yeah, just here) in code-tags! See How to use the forum for that.

Had an error while uploading, tried to edit. couldnt, had to wait 5 mins. :p

Then you'll have to wait for somebody that is willing to download the .zip. Ain't me like I said ;)

septillion: Then you'll have to wait for somebody that is willing to download the .zip. Ain't me like I said ;)

there.

2.39kB? Why not just post the files?

k there is

Hi,

I’m coding a datalogger which has libraries for each sensor to log data of, and every sensor will be linked to a main Sensor library. Problem is that, when i try to call an inherited function from the main sensor class, i get no response back ( from Serial.print (object.getNumber()) in the main file) which means im doing something wrong in the code.

Heres the main code:

#include "LDR.h"
#include "arduino.h"

light asd; //creating the object

void setup(){
  Serial.begin(9600);
  }

void loop(){
  asd.Set_parameters(1,10); // ( pin, another value)
  Serial.print(asd.Get_pin()); // (should get the pin number which is 1)
  delay(100);
}

heres the main sensor library which is inherited by the other sensors

class Sensor{
  protected:
    int pin;

   ///some  code that is not relevant///




  public:
    void Set_parameters(int a, int s);
    int Get_pin();
};

Functions of main sensor

#include "Sensor_main.h"

void Sensor::Set_parameters(int a, int  s){
      pin = a; 
     .......some other code////
}

int Sensor::Get_pin(){
    return pin;
}

and lastly,the LDR class which is supposed to inherit the Main sensor class functions

class light: public Sensor{
 
 public:    
    some functions
   
};

I havent found something that helps me with inheritance and libraries either.

Ill attach the files, hope its just a noob mistake from me.

DATALOGGER.ino (265 Bytes)

LDR.h (217 Bytes)

ldr_measurement.cpp (872 Bytes)

pyr.h (289 Bytes)

Sensor_conf.cpp (495 Bytes)

Sensor_main.h (503 Bytes)

Cross posted from: http://forum.arduino.cc/index.php?topic=488745.msg3335068#msg3335068

OP, please don't post the same question twice, especially when you already have replies to the other thread. We don't like people wasting our time when we end up giving answers that you've already been given.

Reported to Mods.

Serial.print(asd.Get_pin()); // (should get the pin number which is 1)

What type of Arduino? Most have the Serial lines broken out on pins 0 and 1, so if you are going to use Serial you shouldn't have anything else connected to pins 0 or 1.

If you try to print anything else does that work? That would be my first troubleshooting step.

Merged. Do not cross-post, cross-posting wastes time

Delta_G: Serial.print(asd.Get_pin()); // (should get the pin number which is 1)

What type of Arduino? Most have the Serial lines broken out on pins 0 and 1, so if you are going to use Serial you shouldn't have anything else connected to pins 0 or 1.

If you try to print anything else does that work? That would be my first troubleshooting step.

that doesnt matter, the pin number its registered on an integer, im trying to get that number back. Pins dont matter, getting the value back does.

Is there anything connected to that pin?

AWOL: Merged. Do not cross-post, cross-posting wastes time

Your merge doesn't seem to have merged...

Delta_G:
Is there anything connected to that pin?

No, im not reading it either. Its just a variable with that name which is meant to store any value. The problem is that arduino its not printing that value back.

Cant call a function that is owned by the child class either.

Mbravov: No, im not reading it either. Its just a variable with that name which is meant to store any value. The problem is that arduino its not printing that value back.

OK, I'm just trying to make sure. Gotta remember, I've never seen this thing you're working on.

So back to what I asked earlier. If you print something else in the loop, does that print right?