I am currently programming my RGB LEDCube and therefor I create color gradients in seperate classes. Those classes are derived from colorgnt.h. I dervied rainbowgnt.h from colorgnt.h. A colorgnt has a virtual rgb8bit(24bit RGB) function that delivers the wanted values dependant on uint8_t position. But I keep getting the number 0 but it should be 255. Why?
Code:
/*
colorgnt.h
*/
#ifndef colorgnt_H
#define colorgnt_H
#include "LEDCube.h"
typedef struct rgb8bit {
uint8_t r;
uint8_t g;
uint8_t b;
};
class colorgnt {
public:
colorgnt() {}
virtual rgb8bit rgb(uint8_t position) {}
};
#endif
/*
rainbowgnt.h
*/
#ifndef rainbowgnt_H
#define rainbowgnt_H
#include "colorgnt.h"
#include "LEDCube.h"
class colorgnt; //is this neccessary?
class rainbowgnt: public colorgnt {
public:
rainbowgnt() {}
virtual rgb8bit rgb(uint8_t position) {
rgb8bit rgb;
rgb.r = 255; //just for testing, no rainbow
rgb.g = 255;
rgb.b = 255;
return rgb;
}
};
#endif
void LEDCube::rendergradient(colorgnt gradient) {
rgb8bit whatever;
whatever = gradient.rgb(5); //Should set whatever.r/g/b to 255
Serial.println(whatever.r); //Which it doesnt... Delivers '0'
}
void LEDCube::test() {
rainbowgnt gnt; //Intializing instance of rainbowgnt
rendergradient(gnt); //passing the instance to the function above
}