Guessing this is obvious to C++ peeps but it’s baffling me.
I have a class “Bbq” that instantiates another class “Auger” and a function of class “Auger” is called from a function of class “Bbq”. The Auger function calls analogWrite to turn on a motor. When I call bbq.ignite, i know auger.turn is being called and working because Serial1.print will print from it. However, analogWrite will not. I can instantiate Auger by itself and call turn and analogWrite works fine there.
I tried just using the pin code and a value to write instead of passing values for each in and still no results (analogWrite(A6,200)
instead of analogWrite(pin,rate)
Any ideas?
Some code:
class Bbq {
public:
Auger auger;
Fan fan;
Bbq(int augerPin, int fanPin);
void ignite();
};
#include "auger.h"
#include "fan.h"
#include "bbq.h"
#include "application.h"
Bbq::Bbq(int augerPin, int fanPin) : auger(augerPin), fan(fanPin){}
void Bbq::ignite() {
auger.turn(200);
fan.spin(200);
}
class Auger{
int pin;
public:
Auger(int p);
void turn(int rate);
};
#include "auger.h"
#include "application.h"
Auger::Auger(int p) {
pin = p;
}
void Auger::turn(int rate = 0){
// Serial1.print(pin);
//analogWrite(pin,rate);
analogWrite(A6,200);
}
int fan_pin = A5;
int auger_pin = A6;
Bbq bbq1 (auger_pin,fan_pin);
void setup()
{
pinMode(fan_pin, OUTPUT);
pinMode(auger_pin, OUTPUT);
}
void loop()
{
// analogWrite(16,230);
bbq1.ignite();
}