Cockpit

* User Profile

Welcome, Guest. Please login or register.

Login with username, password and session length

Who's Online

  • *Users: 1
  • *Guests: 46
  • *Total: 47

Our Discord

Author Topic: Teensy LC Fuel Panel B (low part)  (Read 96 times)

Offline kurt-olsson

  • I am chained to this website!
  • *
  • Posts: 1,232
  • 737 -mixed year OEM panel builder.
  • First Name: Peter
  • Home Location: Gothenburg
Teensy LC Fuel Panel B (low part)
« on: July 24, 2019, 05:27:30 PM »
Made a function for the switches.
This is borderline, it will not be easy to understand when returning to the code. Sometimes it is better not to abstract but in this case it is so much more compact and easy to understand anyway.


const int PIN_KORRY_LIGHT_PUSH_TO_TEST = 17;
const int PIN_KORRY_LIGHT_PUSH_TO_TEST_2 = 10;
const int PIN_KORRY_LIGHT_RIGHT_AFT_LOW_PREASSURE = 9;
const int PIN_KORRY_LIGHT_LEFT_FWD_LOW_PREASSURE = 4;
const int PIN_KORRY_LIGHT_RIGHT_FWD_LOW_PREASSURE = 20;
const int PIN_KORRY_LIGHT_LEFT_FUEL_PUMP_LOW_PREASSURE = 16;
const int PIN_KORRY_LIGHT_LEFT_AFT_LOW_PREASSURE = 3;
const int PIN_KORRY_LIGHT_RIGHT_FUEL_PUMP_LOW_PREASSURE = 6;

const int PIN_SWITCH_FUEL_PUMP_RIGHT = 13; 
const int PIN_SWITCH_FUEL_PUMP_LEFT = 14; 
const int PIN_SWITCH_LEFT_AFT = 15; 
const int PIN_SWITCH_LEFT_FWD = 18; 
const int PIN_SWITCH_RIGHT_AFT = 19; 
const int PIN_SWITCH_RIGHT_FWD = 21; 


FlightSimFloat xPlane_low_fuel_press_l1;
FlightSimFloat xPlane_low_fuel_press_l2;
FlightSimFloat xPlane_low_fuel_press_r1;
FlightSimFloat xPlane_low_fuel_press_r2;
FlightSimFloat xPlane_low_fuel_press_c1;
FlightSimFloat xPlane_low_fuel_press_c2;

FlightSimFloat xPlane_fuel_tank_pos_lft1;
FlightSimFloat xPlane_fuel_tank_pos_lft2;
FlightSimFloat xPlane_fuel_tank_pos_rgt1;
FlightSimFloat xPlane_fuel_tank_pos_rgt2;
FlightSimFloat xPlane_fuel_tank_pos_ctr1;
FlightSimFloat xPlane_fuel_tank_pos_ctr2;

void setup() {
 
  xPlane_low_fuel_press_l1 = XPlaneRef("laminar/B738/annunciator/low_fuel_press_l1");
  xPlane_low_fuel_press_l2 = XPlaneRef("laminar/B738/annunciator/low_fuel_press_l2");
  xPlane_low_fuel_press_r1 = XPlaneRef("laminar/B738/annunciator/low_fuel_press_r1");
  xPlane_low_fuel_press_r2 = XPlaneRef("laminar/B738/annunciator/low_fuel_press_r2");
  xPlane_low_fuel_press_c1 = XPlaneRef("laminar/B738/annunciator/low_fuel_press_c1");
  xPlane_low_fuel_press_c2 = XPlaneRef("laminar/B738/annunciator/low_fuel_press_c2");

  xPlane_fuel_tank_pos_lft1 = XPlaneRef("laminar/B738/fuel/fuel_tank_pos_lft1");
  xPlane_fuel_tank_pos_lft2 = XPlaneRef("laminar/B738/fuel/fuel_tank_pos_lft2");
  xPlane_fuel_tank_pos_rgt1 = XPlaneRef("laminar/B738/fuel/fuel_tank_pos_rgt1");
  xPlane_fuel_tank_pos_rgt2 = XPlaneRef("laminar/B738/fuel/fuel_tank_pos_rgt2");
  xPlane_fuel_tank_pos_ctr1 = XPlaneRef("laminar/B738/fuel/fuel_tank_pos_ctr1");
  xPlane_fuel_tank_pos_ctr2 = XPlaneRef("laminar/B738/fuel/fuel_tank_pos_ctr2");
 
  pinMode(PIN_KORRY_LIGHT_PUSH_TO_TEST,OUTPUT);
  pinMode(PIN_KORRY_LIGHT_PUSH_TO_TEST_2,OUTPUT);
  pinMode(PIN_KORRY_LIGHT_RIGHT_AFT_LOW_PREASSURE,OUTPUT);   
  pinMode(PIN_KORRY_LIGHT_LEFT_FWD_LOW_PREASSURE,OUTPUT);
  pinMode(PIN_KORRY_LIGHT_RIGHT_FWD_LOW_PREASSURE,OUTPUT);
  pinMode(PIN_KORRY_LIGHT_LEFT_FUEL_PUMP_LOW_PREASSURE,OUTPUT);
  pinMode(PIN_KORRY_LIGHT_RIGHT_FUEL_PUMP_LOW_PREASSURE,OUTPUT);
  pinMode(PIN_KORRY_LIGHT_LEFT_AFT_LOW_PREASSURE,OUTPUT);
 
  pinMode(PIN_SWITCH_FUEL_PUMP_RIGHT, INPUT_PULLUP);
  pinMode(PIN_SWITCH_FUEL_PUMP_LEFT, INPUT_PULLUP);
  pinMode(PIN_SWITCH_LEFT_AFT, INPUT_PULLUP);
  pinMode(PIN_SWITCH_LEFT_FWD, INPUT_PULLUP);
  pinMode(PIN_SWITCH_RIGHT_AFT, INPUT_PULLUP);
  pinMode(PIN_SWITCH_RIGHT_FWD, INPUT_PULLUP);

}

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_FUEL_PUMP_LOW_PREASSURE,mapfloat(xPlane_low_fuel_press_c1, 0,1,0,255));
  analogWrite(PIN_KORRY_LIGHT_RIGHT_FUEL_PUMP_LOW_PREASSURE, mapfloat(xPlane_low_fuel_press_c2, 0,1,0,255));
  analogWrite(PIN_KORRY_LIGHT_RIGHT_AFT_LOW_PREASSURE, mapfloat(xPlane_low_fuel_press_r1, 0,1,0,255));
  analogWrite(PIN_KORRY_LIGHT_RIGHT_FWD_LOW_PREASSURE,mapfloat(xPlane_low_fuel_press_r2, 0,1,0,255));
  analogWrite(PIN_KORRY_LIGHT_LEFT_FWD_LOW_PREASSURE,mapfloat(xPlane_low_fuel_press_l2, 0,1,0,255));
  analogWrite(PIN_KORRY_LIGHT_LEFT_AFT_LOW_PREASSURE, mapfloat(xPlane_low_fuel_press_l1, 0,1,0,255));

  readSwitchHigh(PIN_SWITCH_FUEL_PUMP_RIGHT, 0,1, xPlane_fuel_tank_pos_ctr2);
  readSwitchHigh(PIN_SWITCH_FUEL_PUMP_LEFT, 0,1, xPlane_fuel_tank_pos_ctr1);
  readSwitchHigh(PIN_SWITCH_LEFT_AFT, 1,0, xPlane_fuel_tank_pos_lft1);
  readSwitchHigh(PIN_SWITCH_LEFT_FWD, 1,0, xPlane_fuel_tank_pos_lft2);
  readSwitchHigh(PIN_SWITCH_RIGHT_AFT, 1,0, xPlane_fuel_tank_pos_rgt1);
  readSwitchHigh(PIN_SWITCH_RIGHT_FWD, 1,0, xPlane_fuel_tank_pos_rgt2);

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

void readSwitchHigh(int pin, int highValue, int lowValue, FlightSimFloat &dataref) {
  if (digitalRead(pin) == HIGH && dataref != highValue) {
    dataref = highValue;
  }
  if (digitalRead(pin) == LOW && dataref != lowValue) {
    dataref = lowValue;
  }
}

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

 

Recent Posts

Free Jet Ranger.
by geneb
[Today at 06:16:52 PM]
items/oem from overhead
by gufau
[Today at 12:49:15 PM]
Hi everyone!
by jskibo
[Today at 08:05:33 AM]
737-800 Front window post size
by kurt-olsson
[Today at 03:35:11 AM]
Shipping Woes
by Caflyt
[August 22, 2019, 10:47:49 AM]
Official WF 2019 Route
by dougsnow
[August 21, 2019, 07:49:35 PM]
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]
Flight Illusion Boeing Press Gauge for sale
by XOrionFE
[August 19, 2019, 08:40:35 AM]
Shell placement and yoke placement questions
by helloo
[August 18, 2019, 02:37:26 PM]
panel sismo oh
by gufau
[August 17, 2019, 04:17:00 AM]
My next sim?
by fsaviator
[August 16, 2019, 06:54:51 PM]
What have you done for your simulator today?
by blueskydriver
[August 14, 2019, 10:35:26 AM]
Looking for gear lever from 747-400, 757
by navymustang
[August 13, 2019, 10:05:44 AM]
Quick way to attach low res/smaller file size pics in your posts...
by Vincent T.
[August 12, 2019, 09:58:46 PM]
Cant post attachments from my iphone
by Trevor Hale
[August 12, 2019, 09:26:08 AM]
For Sale: Engravity 737 Window Frames
by Caflyt
[August 11, 2019, 05:02:28 PM]
737-800 Arduino X-Plane Build
by kurt-olsson
[August 10, 2019, 01:43:57 PM]
Help identifying a connector
by kurt-olsson
[August 10, 2019, 10:59:31 AM]
For Sale GoFlight Jet Console, 2 Private Pilot Racks all with GoFlight Modules.
by blueskydriver
[August 08, 2019, 09:40:02 PM]
Flightdeck Solutions Works with X-Plane11
by Michael_B737_ATP
[August 07, 2019, 02:59:21 PM]
Boeing Dual Linked Yokes for sale
by tennyson
[August 07, 2019, 07:34:58 AM]
CPFLight Backlighting
by mickc
[August 05, 2019, 10:09:53 PM]
Three Projector 210 degree with P3D4
by Nat Crea
[August 03, 2019, 08:36:50 PM]
Looking for part numbers from the 737 NG IPC
by mickc
[August 02, 2019, 11:20:49 PM]
WF2019
by Sam Llorca
[August 02, 2019, 09:22:56 PM]
Teensy LC Fuel Panel A (top)
by bernard S
[August 02, 2019, 06:09:00 PM]
737 overhead
by nigel27
[July 28, 2019, 11:50:47 PM]