Welcome to Cockpitbuilders.com. Please login or sign up.

March 28, 2024, 12:37:09 AM

Login with username, password and session length

PROUDLY ENDORSING


Fly Elise-ng
94 Guests, 0 Users
Members
Stats
  • Total Posts: 59,639
  • Total Topics: 7,853
  • Online today: 100
  • Online ever: 582
  • (January 22, 2020, 08:44:01 AM)
Users Online
Users: 0
Guests: 94
Total: 94

COUNTDOWN TO WF2022


WORLDFLIGHT TEAM USA

Will Depart in...

Recent

Welcome

Need some basic gauge code help

Started by ElStino737, January 21, 2017, 09:27:01 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ElStino737

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);
  }
}

RayS

#1
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.
Ray Sotkiewicz

ElStino737

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);
}

ElStino737

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);
}

Like the Website ?
Support Cockpitbuilders.com and Click Below to Donate