Cockpit

* User Profile

Welcome, Guest. Please login or register.

Login with username, password and session length

Who's Online

  • *Users: 1
  • *Guests: 56
  • *Total: 57

Our Discord

WORLDFLIGHT 2019 - TEAM USA SUPPORTERS (HERO'S)

 
Worldflight 2019
Donations Starting Early
With 50 Days Left, it's time to start Counting Down to Worldflight 2019.  Beginning in August, we had 2 kind gentleman lead the way on our quest for donations to this amazing Charity Event.  Over the Past 6 Years, we (This community) Has helped to raise over $25,000.00USD to help the kids and their families of the All Children's Hospital in St. Petersburgh, Florida.  Kicking off the donations this year these Two Hero's are leading the way to another Successful Year.  I personally want to thank these two Gentleman and use this opportunity to have all of you donate to our wonderful cause. 
Thank you in advance for your help and please wish us much success for our 2019 event.
       
  ---Worldflight 2019 HEROS---

 James Williams, Warren Soeldner,  Sam Llorca, Doug Snow, Ryan O'Keefe, Edwin Burton        





Thanks to all of you, You are all helping to make Worldflight 2019 a success..
Because of all you wonderful people so far we have raised a total of:

$1245.00 USD


Author Topic: Need some basic gauge code help  (Read 1527 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: 824
  • 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);
}

 

Recent Posts

727/737 yokes
by Caflyt
[Today at 02:11:06 PM]
WORLDFLIGHT 2019 - Scenery Check Volunteers Needed
by Vincent T.
[September 14, 2019, 03:08:00 PM]
WORLDFLIGHT 2019 - FLIGHT BIDS
by Vincent T.
[September 14, 2019, 03:00:40 PM]
WORLDFLIGHT 2019 - AVAILABILITY
by Trevor Hale
[September 14, 2019, 07:25:32 AM]
WORLDFLIGHT 2019 - Employer matching for Donations...
by RayS
[September 14, 2019, 12:03:45 AM]
SimFest-West 2019 Videos
by RayS
[September 13, 2019, 07:27:16 PM]
737 MAX Build
by helloo
[September 13, 2019, 04:41:17 PM]
A little pucker factor here, I'm sure... nerves of steel
by RayS
[September 12, 2019, 06:30:45 PM]
Which size fuses to use in fuse block supplying FDS boards?
by blueskydriver
[September 11, 2019, 05:56:37 PM]
I finally got the shell pulled off the ATC-810...
by geneb
[September 11, 2019, 07:29:51 AM]
Wanted: Optoma GT1080Darbee Short Throw Projector
by Flightdeck57
[September 11, 2019, 12:24:08 AM]
F16 Simulator For Sale
by blueskydriver
[September 06, 2019, 03:52:34 PM]
Ebay Assistance
by iwik
[September 06, 2019, 02:00:00 PM]
Matrox 3
by jackpilot
[September 05, 2019, 10:45:00 AM]
So I got a big crate the other day...
by geneb
[September 05, 2019, 09:20:22 AM]
Official WF 2019 Route
by fsaviator
[September 05, 2019, 08:20:10 AM]
Are some sellers off their trolly
by kurt-olsson
[September 02, 2019, 12:39:54 PM]
Display Glare FDS w/Pic
by Joe Lavery
[September 01, 2019, 02:33:47 AM]
MCP
by Caflyt
[August 27, 2019, 06:57:41 PM]
Dispatch and Career Add-on
by fsaviator
[August 26, 2019, 10:42:45 AM]
What have you done for your simulator today?
by B763
[August 25, 2019, 04:58:46 PM]
Free Jet Ranger.
by geneb
[August 23, 2019, 06:16:52 PM]
items/oem from overhead
by gufau
[August 23, 2019, 12:49:15 PM]
Hi everyone!
by jskibo
[August 23, 2019, 08:05:33 AM]
737-800 Front window post size
by kurt-olsson
[August 23, 2019, 03:35:11 AM]
Shipping Woes
by Caflyt
[August 22, 2019, 10:47:49 AM]
Worldflight 2019 Open for Business
by Trevor Hale
[August 21, 2019, 08:28:13 AM]
More ?'s - annunciators?
by kattz
[August 21, 2019, 05:44:21 AM]
Looking for annunciators
by kattz
[August 19, 2019, 10:36:39 PM]
OK, So here we go!
by Caflyt
[August 19, 2019, 02:32:28 PM]