I added the EGT section to my code today and now the rest of the code quit working. If I take out all the EGT gauge stuff then the original code works fine again. Any idea what I missed? Thanks
Rob
Rob
Code:
// Code for Course Dev Bar and GS on HSI
#include <Servo.h>
Servo glareDim; // create servo object to control a servo
FlightSimFloat crsBar; //-2.0 to 2.0 2 dot deflection
FlightSimFloat gsBar; //-2.0 to 2.0 2 dot deflection
FlightSimFloat egt1; // in degrees celcius
#define CourseDeviation 10
#define GsDeviation 9
#define Egt1Gauge 3
int potpin = 15; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
// setup runs once
void setup() {
setupCourseDeviation();
setupGsDeviation();
setupEgt1Gauge();
glareDim.attach(4);
}
// loop runs repetitively, as long as power is on
void loop() {
FlightSim.update(); // causes X-Plane's changes to be received
updateCourseDeviation();
updateGsDeviation();
updateEgt1Gauge();
}
void setupCourseDeviation() {
crsBar = XPlaneRef("sim/cockpit/radios/nav1_hdef_dot");
pinMode(CourseDeviation, OUTPUT); // PWM out
}
void updateCourseDeviation() {
// crsBar -2.0 to 2.0 2 dot deflection
int dev = (crsBar * 127); // dev = Deviation of course bar
dev = map(dev, -254, 254, 0, 255);
analogWrite(CourseDeviation, dev);
}
void setupGsDeviation() {
gsBar = XPlaneRef("sim/cockpit/radios/nav1_vdef_dot");
pinMode(GsDeviation, OUTPUT); // PWM out
}
void updateGsDeviation() {
// crsBar -2.0 to 2.0 2 dot deflection
int gsdev = (gsBar * 127); // dev = Deviation of course bar
gsdev = map(gsdev, -254, 254, 0, 255);
analogWrite(GsDeviation, gsdev);
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 800, 0, 179); // scale it to use it with the servo (value between 0 and 180)
glareDim.write(val); // sets the servo position according to the scaled value
delay(15);
}
void setupEgt1Gauge(){
egt1 = XPlaneRef("sim/cockpit2/engine/indicators/EGT_deg_C[0]");
pinMode(Egt1Gauge, OUTPUT);
}
void updateEgt1Gauge(){
egt1 = map(egt1, 0, 700, 0, 3095);
analogWriteResolution(12);
analogWrite(Egt1Gauge, egt1);
}