Cockpit

* User Profile

Welcome, Guest. Please login or register.

Login with username, password and session length

Who's Online

  • *Users: 3
  • *Guests: 85
  • *Total: 88

Our Discord

Author Topic: Need some basic gauge code help  (Read 1447 times)

Offline ElStino737

  • Forum GURU
  • *
  • Posts: 28
  • Aviation Enthusiast
  • First Name: Stijn
  • Home Location: Ninove
Need some basic gauge code help
« on: January 21, 2017, 01:27:01 PM »
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);
  }
}

Offline RayS

  • I spend way too much on this forum!
  • *
  • Posts: 817
  • Private Pilot, Sim Enthusiast
    • Anthony Scott Photography
  • First Name: Ray Sotkiewicz
  • Home Location: Seattle, WA
Re: Need some basic gauge code help
« Reply #1 on: January 21, 2017, 02:00:44 PM »
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.
« Last Edit: January 21, 2017, 02:02:22 PM by RayS »
Ray Sotkiewicz

Offline ElStino737

  • Forum GURU
  • *
  • Posts: 28
  • Aviation Enthusiast
  • First Name: Stijn
  • Home Location: Ninove
Re: Need some basic gauge code help
« Reply #2 on: January 21, 2017, 03:52:59 PM »
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);
}

Offline ElStino737

  • Forum GURU
  • *
  • Posts: 28
  • Aviation Enthusiast
  • First Name: Stijn
  • Home Location: Ninove
Re: Need some basic gauge code help - SOLVED
« Reply #3 on: January 21, 2017, 05:15:02 PM »
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);
}

 

FlightSimExpo 2019

FsExpo

Recent Posts

Flooring Installed!
by helloo
[Today at 04:00:36 PM]
How much room between center pedestal and seat?
by jackpilot
[Today at 08:19:42 AM]
PM MCP.ini Question...
by ScottThePilot
[Today at 03:14:37 AM]
2020 Microsoft Flight Simulator - new at E3 2019
by blueskydriver
[June 24, 2019, 02:29:16 PM]
How to install DZUS fasteners?
by Buster99
[June 22, 2019, 04:12:34 PM]
Desert Air Spares - Trustworthy?
by kattz
[June 22, 2019, 12:40:51 PM]
Wanted - 737 Audio Panels - OEM
by jackpilot
[June 20, 2019, 12:26:51 PM]
Throttletek 737 Throttle For Sale
by kevinsayre
[June 19, 2019, 03:57:33 PM]
For sale - rudder pedals and linkages - pending to Craig
by Caflyt
[June 19, 2019, 07:49:14 AM]
737-800 Arduino X-Plane Build
by kurt-olsson
[June 18, 2019, 11:26:12 AM]
737 Throttle Conversion OC + ProSim
by kattz
[June 16, 2019, 11:39:03 AM]
A friendly FYI on Boeing rudder pedals
by kattz
[June 15, 2019, 10:36:39 AM]
737 starter switch mechanism
by paulnd
[June 13, 2019, 02:58:39 PM]
Make up your mind, Microsoft!
by jmlohrenz
[June 12, 2019, 07:25:10 PM]
What have you done for your simulator today?
by C150DIY
[June 12, 2019, 12:53:27 PM]
Complete 737-800 cockpit - moving sale
by FaustoP
[June 12, 2019, 01:26:39 AM]
Flyengravity desktop MIP
by patiju
[June 10, 2019, 01:01:06 PM]
the perfect thing to complete your sim hanger
by fsaviator
[June 09, 2019, 03:12:50 PM]
Wanted - COMPLETE set of Boeing 727 or 737 rudder pedals
by kattz
[June 08, 2019, 01:26:09 PM]
Visual system screen by Northern Flight Sim for sale $500
by peterkwu
[June 08, 2019, 06:07:39 AM]
Wanted: GoFlight T8
by C150DIY
[June 07, 2019, 02:32:29 PM]
For Sale - CPFlight MCP737 + EFIS
by ZillaUK
[June 07, 2019, 09:54:58 AM]
737 FWD Overhead Switch Diagram
by bernard S
[June 07, 2019, 08:21:46 AM]
Change the Forum Theme to suit your own Needs.
by AdamMilstead
[June 07, 2019, 06:20:41 AM]
Aileron & Elevator jump back to center
by iwik
[June 06, 2019, 08:01:24 PM]
Join me on Vatsim Tonight
by Trevor Hale
[June 05, 2019, 05:17:13 PM]
Machinery for home cockpit building
by giaviv
[June 04, 2019, 04:12:10 PM]
PROMOCION STEERING FREE
by alvaro castillo
[June 04, 2019, 11:42:43 AM]
FLIGHTSIMEXPO LAUNCHES DISCOUNTED ADVANCE REGISTRATION FOR ORLANDO 2019 EVENT
by fsaviator
[June 03, 2019, 06:52:44 PM]
Question about linking the yokes
by jackpilot
[June 01, 2019, 02:22:10 PM]