- Thu Jan 11, 2018 6:21 am
#197831
started using this tutorial as a guide
http://paulmurraycbr.github.io/ArduinoT ... nheritance
in my own code cant for the life of me figure out what the problem is
read comments in code thank you for your help
const int fieldCoilPin = 6;
class FieldCoil{
public:
int pwm;
int setPwm() { return pwm; }
void getPwm(int pwmvalue) { pwm = pwmvalue; }
void setup() {
pinMode(fieldCoilPin, OUTPUT);
}
void loop() {
Serial.println(pwm);
analogWrite(fieldCoilPin, pwm);
}
};
class Throtle {
FieldCoil field;
int x;
public:
void setup() {
x = 255;
}
void loop() {
Serial.println();
field.getPwm(x); //trying to pass x back to FieldCoil class
} // but i get nothing back
};
Throtle throtle;
FieldCoil fieldCoil;
void setup(){
Serial.begin(9600);
fieldCoil.setup();
throtle.setup();
}
void loop()
{
//fieldCoil.getPwm(255); //uncomment this and it works
// proves the function does what it suppose to
// but my goal is to do this through the Throtle class
fieldCoil.loop();
throtle.loop();
}
http://paulmurraycbr.github.io/ArduinoT ... nheritance
in my own code cant for the life of me figure out what the problem is
read comments in code thank you for your help
const int fieldCoilPin = 6;
class FieldCoil{
public:
int pwm;
int setPwm() { return pwm; }
void getPwm(int pwmvalue) { pwm = pwmvalue; }
void setup() {
pinMode(fieldCoilPin, OUTPUT);
}
void loop() {
Serial.println(pwm);
analogWrite(fieldCoilPin, pwm);
}
};
class Throtle {
FieldCoil field;
int x;
public:
void setup() {
x = 255;
}
void loop() {
Serial.println();
field.getPwm(x); //trying to pass x back to FieldCoil class
} // but i get nothing back
};
Throtle throtle;
FieldCoil fieldCoil;
void setup(){
Serial.begin(9600);
fieldCoil.setup();
throtle.setup();
}
void loop()
{
//fieldCoil.getPwm(255); //uncomment this and it works
// proves the function does what it suppose to
// but my goal is to do this through the Throtle class
fieldCoil.loop();
throtle.loop();
}