Working on my APU EGT gauge.
Got the gauge working via PWM, but I have some trouble writing the proper code to drive it from the Xplaneref.
I'm a complete beginner at this and it's making me feel like an idiot :o
It should be a simple code, I've hooked up a resistor to the gauge so the 5V output via PWM matches full deflection (=790°C)
Here is what i've got so far but this won't even compile :huh:
FlightSimFloat APUegtC; //in degrees celcius
#define APUegtGauge 23
void setup() {
// put your setup code here, to run once:
APUegtC = XPlaneRef("sim/cockpit2/engine/indicators/EGT_deg_C[0]");
pinMode(APUegtGauge, OUTPUT);
}
void loop() {
FlightSim.update();
analogWriteResolution(12); // analogWrite value 0 to 4095, or 4096 for high
APUegtGauge = map(APUegtC, 0, 790, 0, 4095); //(0°C, 790°C, 0PWM, 4096PWM)
analogWrite(APUegtGauge, APUegtC);
}
}
You have too many braces. Remove that very last right-brace and try it. :-)
Also, in your map function, I think that PWM channels only go from 0-255. Your mapping may be off.
Thank you for your answer.
You where correct on the bracket.
I've taken out the analogwriteresolution and changed to 255 mapping, but still no luck.
There still seems to be something wrong in the map line, or maybe I'm missing something all together?
FlightSimFloat APUegtC; //in degrees celcius
#define APUegtGauge 23
void setup() {
APUegtC = XPlaneRef("sim/cockpit2/engine/indicators/EGT_deg_C[0]");
pinMode(APUegtGauge, OUTPUT);
}
void loop() {
FlightSim.update();
APUegtGauge = map(APUegtC, 0, 790, 0, 255); //(0°C, 790°C, 0PWM, 4096PWM)
analogWrite(APUegtGauge, APUegtC);
}
Ok, got it working:
FlightSimFloat APUegtC; //in degrees celcius
#define APUegtGauge 23
FlightSimInteger EGTPWM;
void setup() {
APUegtC = XPlaneRef("FJS/732/Elec/APUExhTempNeedle");
pinMode(APUegtGauge, OUTPUT);
}
void loop() {
FlightSim.update();
//APUegtGauge = map(APUegtC, 0,790,0,255); //(0°C, 790°C, 0PWM, 4096PWM)
EGTPWM = map(APUegtC, 0,790,0,254);
analogWrite(APUegtGauge, EGTPWM);
}