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

March 28, 2024, 03:52:02 PM

Login with username, password and session length

PROUDLY ENDORSING


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

COUNTDOWN TO WF2022


WORLDFLIGHT TEAM USA

Will Depart in...

Recent

Welcome

Teensy LC Fuel Panel A (top)

Started by kurt-olsson, July 23, 2019, 12:48:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kurt-olsson

Code for Fuel Panel.
With good datarefs, the code looks clean. I like this...


const int PIN_KORRY_LIGHT_PUSH_TO_TEST = 9;
const int PIN_KORRY_LIGHT_PUSH_TO_TEST_2 = 4;
const int PIN_KORRY_LIGHT_LEFT_FILTER_BYPASS = 20;
const int PIN_KORRY_LIGHT_RIGHT_FILTER_BYPASS = 16;
const int PIN_KORRY_LIGHT_VALVE_OPEN = 17;
const int PIN_KORRY_LIGHT_LEFT_FUEL_VALVE_CLOSED = 10;
const int PIN_KORRY_LIGHT_RIGHT_FUEL_VALVE_CLOSED = 3;

const int PIN_SWITCH_CROSS_FEED = 13; 

FlightSimFloat xPlane_cross_feed_pos;
FlightSimFloat xPlane_eng1_valve_closed;
FlightSimFloat xPlane_eng2_valve_closed;
FlightSimFloat xPlane_bypass_filter_1;
FlightSimFloat xPlane_bypass_filter_2;
FlightSimFloat xPlane_crossfeed;

void setup() {
 
  xPlane_cross_feed_pos = XPlaneRef("laminar/B738/knobs/cross_feed_pos");
  xPlane_eng1_valve_closed = XPlaneRef("laminar/B738/annunciator/eng1_valve_closed");
  xPlane_eng2_valve_closed = XPlaneRef("laminar/B738/annunciator/eng2_valve_closed");
  xPlane_bypass_filter_1 = XPlaneRef("laminar/B738/annunciator/bypass_filter_1");
  xPlane_bypass_filter_2 = XPlaneRef("laminar/B738/annunciator/bypass_filter_2");
  xPlane_crossfeed = XPlaneRef("laminar/B738/annunciator/crossfeed");

 
   pinMode(PIN_KORRY_LIGHT_LEFT_FILTER_BYPASS,OUTPUT);
   pinMode(PIN_KORRY_LIGHT_RIGHT_FILTER_BYPASS,OUTPUT);
   pinMode(PIN_KORRY_LIGHT_VALVE_OPEN,OUTPUT);
   pinMode(PIN_KORRY_LIGHT_LEFT_FUEL_VALVE_CLOSED,OUTPUT);
   pinMode(PIN_KORRY_LIGHT_PUSH_TO_TEST,OUTPUT);   
   pinMode(PIN_KORRY_LIGHT_RIGHT_FUEL_VALVE_CLOSED,OUTPUT);
   pinMode(PIN_KORRY_LIGHT_PUSH_TO_TEST_2,OUTPUT);

   pinMode(PIN_SWITCH_CROSS_FEED, INPUT_PULLUP);

   //Serial.begin(9600); // USB is always 12 Mbit/sec
}

void loop() {
  FlightSim.update(); 
 
  analogWrite(PIN_KORRY_LIGHT_PUSH_TO_TEST,255);
  analogWrite(PIN_KORRY_LIGHT_PUSH_TO_TEST_2,255);
  analogWrite(PIN_KORRY_LIGHT_LEFT_FILTER_BYPASS,mapfloat(xPlane_bypass_filter_1, 0,1,0,255));
  analogWrite(PIN_KORRY_LIGHT_RIGHT_FILTER_BYPASS,mapfloat(xPlane_bypass_filter_2, 0,1,0,255));
  analogWrite(PIN_KORRY_LIGHT_VALVE_OPEN,mapfloat(xPlane_crossfeed, 0,1,0,255));
  analogWrite(PIN_KORRY_LIGHT_LEFT_FUEL_VALVE_CLOSED,mapfloat(xPlane_eng1_valve_closed, 0,1,0,255));
  analogWrite(PIN_KORRY_LIGHT_RIGHT_FUEL_VALVE_CLOSED, mapfloat(xPlane_eng2_valve_closed, 0,1,0,255));
 
  if (digitalRead(PIN_SWITCH_CROSS_FEED) == LOW && xPlane_cross_feed_pos != 0)
  {
    xPlane_cross_feed_pos = 0;
  }
 
  if (digitalRead(PIN_SWITCH_CROSS_FEED) == HIGH && xPlane_cross_feed_pos != 1)
  {
    xPlane_cross_feed_pos = 1;
  }

  //put a small delay here otherwise the processing is so fast. Lots of read/write that dont have to be so fast.
  delay(20);
}

float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

mickc

2 queries Kurt;

Are you not using the separate ENG and SPAR valve lights for the NG?

Also how are you handling the dim/brt states for valve position disagree ?

kurt-olsson

Hi Mick.

Unfortunatly i have annolder fuel panel from the classic, so there is only fuel valve closed korrys and no eng/spar annunciators. These are differences from the NG i will ignore in my build for now.

Regarding the logic of dim states i only read from xPlane values of 0.0 - 2.0 (mosty 1.0). So the logic is allready there so i just read it.

Hope i understood your last question and anssered it. :)

bernard S


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