Cockpit

* User Profile

Welcome, Guest. Please login or register.

Login with username, password and session length

Who's Online

  • *Users: 4
  • *Guests: 76
  • *Total: 80

Our Discord

Author Topic: Teensy LC Hydralic Panel  (Read 330 times)

Offline kurt-olsson

  • I am chained to this website!
  • *
  • Posts: 1,148
  • 737 -mixed year OEM panel builder.
  • First Name: Peter
  • Home Location: Gothenburg
Teensy LC Hydralic Panel
« on: October 10, 2018, 04:52:42 PM »
Hi!

Here is my sketch for my Haudralic panel for the Zibo 737 and X-Plane 11 using Teensy LC.


const int PIN_5V_BACKLIGHT = 6;
const int PIN_KORRY_PUSH_TO_TEST = 4;

const int PIN_KORRY_LIGHT_ELEC_LOW_PRESSURE_1 = 3;
const int PIN_KORRY_LIGHT_ELEC_LOW_PRESSURE_2 = 23;
const int PIN_KORRY_LIGHT_ELEC_OVERHEAT_1 = 22;
const int PIN_KORRY_LIGHT_ELEC_OVERHEAT_2 = 17;
const int PIN_KORRY_LIGHT_ENG_LOW_PRESSURE_1 = 16;
const int PIN_KORRY_LIGHT_ENG_LOW_PRESSURE_2 = 20;

const int PIN_SWITCH_ENGINE_1 = 15;
const int PIN_SWITCH_ENGINE_2 = 19;
const int PIN_SWITCH_ELEC_1 = 18; //Check these, the ground might be touching
const int PIN_SWITCH_ELEC_2 = 21; //check these, the ground might be touching

FlightSimFloat xPlane_light_elec_low_pressure_1;
FlightSimFloat xPlane_light_elec_low_pressure_2;
FlightSimFloat xPlane_light_eng_low_pressure_1;
FlightSimFloat xPlane_light_eng_low_pressure_2;
FlightSimFloat xPlane_light_el_hyd_ovht_1;
FlightSimFloat xPlane_light_el_hyd_ovht_2;

FlightSimFloat xPlane_engine1_pos;
FlightSimFloat xPlane_engine2_pos;
FlightSimFloat xPlane_elec1_pos;
FlightSimFloat xPlane_elec2_pos; 

FlightSimFloat xPlane_panel_brightness_ratio_manual;

void setup() {
 
  xPlane_engine1_pos = XPlaneRef("laminar/B738/toggle_switch/hydro_pumps1_pos");
  xPlane_engine2_pos = XPlaneRef("laminar/B738/toggle_switch/hydro_pumps2_pos");
  xPlane_elec1_pos = XPlaneRef("laminar/B738/toggle_switch/electric_hydro_pumps1_pos");
  xPlane_elec2_pos = XPlaneRef("laminar/B738/toggle_switch/electric_hydro_pumps2_pos");

  xPlane_light_elec_low_pressure_1 = XPlaneRef("laminar/B738/annunciator/hyd_el_press_a");
  xPlane_light_elec_low_pressure_2 = XPlaneRef("laminar/B738/annunciator/hyd_el_press_b");
  xPlane_light_eng_low_pressure_1 = XPlaneRef("laminar/B738/annunciator/hyd_press_a");
  xPlane_light_eng_low_pressure_2 = XPlaneRef("laminar/B738/annunciator/hyd_press_b");
  xPlane_light_el_hyd_ovht_1 = XPlaneRef("laminar/B738/annunciator/el_hyd_ovht_1");;
  xPlane_light_el_hyd_ovht_2 = XPlaneRef("laminar/B738/annunciator/el_hyd_ovht_2");;

  xPlane_panel_brightness_ratio_manual = XPlaneRef("sim/cockpit2/electrical/panel_brightness_ratio_manual[2]");
   
  pinMode(PIN_5V_BACKLIGHT,OUTPUT);
  pinMode(PIN_KORRY_PUSH_TO_TEST,OUTPUT);
 
  pinMode(PIN_KORRY_LIGHT_ELEC_LOW_PRESSURE_1,OUTPUT);
  pinMode(PIN_KORRY_LIGHT_ELEC_OVERHEAT_1,OUTPUT);
  pinMode(PIN_KORRY_LIGHT_ENG_LOW_PRESSURE_2,OUTPUT);
  pinMode(PIN_KORRY_LIGHT_ELEC_OVERHEAT_2,OUTPUT);
  pinMode(PIN_KORRY_LIGHT_ENG_LOW_PRESSURE_1,OUTPUT);
  pinMode(PIN_KORRY_LIGHT_ELEC_LOW_PRESSURE_2,OUTPUT);
 
  pinMode(PIN_SWITCH_ENGINE_1,INPUT_PULLUP);
  pinMode(PIN_SWITCH_ENGINE_2,INPUT_PULLUP);
  pinMode(PIN_SWITCH_ELEC_1,INPUT_PULLUP);
  pinMode(PIN_SWITCH_ELEC_2,INPUT_PULLUP);
}

void loop() {
  FlightSim.update();   

  analogWrite(PIN_5V_BACKLIGHT,mapfloat(xPlane_panel_brightness_ratio_manual, 0,1,0,255));
  analogWrite(PIN_KORRY_PUSH_TO_TEST,255);

  analogWrite(PIN_KORRY_LIGHT_ELEC_OVERHEAT_1,mapfloat(xPlane_light_el_hyd_ovht_1,0,1,0,255));
  analogWrite(PIN_KORRY_LIGHT_ELEC_OVERHEAT_2,mapfloat(xPlane_light_el_hyd_ovht_2,0,1,0,255));

  analogWrite(PIN_KORRY_LIGHT_ELEC_LOW_PRESSURE_1, mapfloat(xPlane_light_elec_low_pressure_1,0,1,0,255));
  analogWrite(PIN_KORRY_LIGHT_ELEC_LOW_PRESSURE_2, mapfloat(xPlane_light_elec_low_pressure_2,0,1,0,255));
 
  analogWrite(PIN_KORRY_LIGHT_ENG_LOW_PRESSURE_1, mapfloat(xPlane_light_eng_low_pressure_1,0,1,0,255));
  analogWrite(PIN_KORRY_LIGHT_ENG_LOW_PRESSURE_2, mapfloat(xPlane_light_eng_low_pressure_2,0,1,0,255));

  //Fix why these dont align up after restarting teensy, strange!

  if (digitalRead(PIN_SWITCH_ELEC_1) == HIGH && xPlane_elec1_pos != 1) {
    xPlane_elec1_pos = 1;
  }
  if (digitalRead(PIN_SWITCH_ELEC_1) == LOW && xPlane_elec1_pos != 0) {
    xPlane_elec1_pos = 0;
  }
  if (digitalRead(PIN_SWITCH_ELEC_2) == HIGH && xPlane_elec2_pos != 1) {
    xPlane_elec2_pos = 1;
  }
  if (digitalRead(PIN_SWITCH_ELEC_2) == LOW && xPlane_elec2_pos != 0) {
    xPlane_elec2_pos = 0;
  }
  if (digitalRead(PIN_SWITCH_ENGINE_1) == HIGH && xPlane_engine1_pos != 1) {
    xPlane_engine1_pos = 1;
  }
  if (digitalRead(PIN_SWITCH_ENGINE_1) == LOW && xPlane_engine1_pos != 0) {
    xPlane_engine1_pos = 0;
  }
  if (digitalRead(PIN_SWITCH_ENGINE_2) == LOW && xPlane_engine2_pos != 1) {
    xPlane_engine2_pos = 1;
  }
  if (digitalRead(PIN_SWITCH_ENGINE_2) == HIGH && xPlane_engine2_pos != 0) {
    xPlane_engine2_pos = 0;
  }

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

Offline archen

  • Forum GURU
  • *
  • Posts: 322
  • Aviation Enthusiast
    • Anders Simparts
  • First Name: Anders
  • Home Location: Falun
Teensy LC Hydralic Panel
« Reply #1 on: October 14, 2018, 05:17:53 AM »
Hey Peter,
Looking at your code it looks like you control the brightness of the annunciator with a dataref related to some kind of lightning control knob in the Zibo aircraft. Is that correctly understood?

Are you limited to use the analog pins of the teensy? Are all the annunciators connected through a ULN2803A?

BR.
Anders

Skickat från min SM-G955F via Tapatalk

------------
Anders Simparts
http://www.anderssimparts.com
https://www.facebook.com/ArchenSimparts
Selling "Hard-to-get" simparts like authentic Engine starters, Autobrake, IRS mode selectors and N1&SPD Ref Switches.
------------

Offline kurt-olsson

  • I am chained to this website!
  • *
  • Posts: 1,148
  • 737 -mixed year OEM panel builder.
  • First Name: Peter
  • Home Location: Gothenburg
Re: Teensy LC Hydralic Panel
« Reply #2 on: October 18, 2018, 08:38:50 AM »
Yes, its controlled by the dataref of the backlight.
Advantages with this is that you dont have to link backlight and the know by hardware / cables.
Just torn the know and read the values from the Logic in X-Plane. Great.

You prob know this now,

I am limited when it comes to the large panels, but with our PCB i plan to use double PCB and 4 ULN2803A. Then the pins and ULN2803A should be enough. =)

 

FlightSimExpo 2019

FsExpo

Recent Posts

FlyAB Simparts: A new supplier for your OEM needs
by Trevor Hale
[Today at 10:51:54 PM]
737 NG Throttle Levers
by mickc
[Today at 06:19:56 PM]
For sale: A set of faceplate panel for pedestal
by Ed
[Today at 03:53:26 PM]
Join me on Vatsim Tonight
by Trevor Hale
[Today at 12:10:28 PM]
Throttle
by IFLY3
[Today at 08:49:37 AM]
B737-800 Flight Sim for sale $85,000.00
by Rob_b
[Today at 12:47:11 AM]
PC upgrade-build-or buy advice??
by iwik
[February 15, 2019, 06:47:11 PM]
Which Processor i7 - 8700K or i7 - 9700K
by Joe Lavery
[February 15, 2019, 05:39:06 PM]
What have you done for your simulator today?
by bernard S
[February 15, 2019, 11:34:25 AM]
Anyone seen OEM 737-900 ER Throttle Quadrant?
by Fly_AB
[February 15, 2019, 10:32:18 AM]
For Sale: P&P Opencockpit VHF, Transponder, and ADF
by Fly_AB
[February 15, 2019, 09:08:24 AM]
737 DIY MIP For Sale
by Trevor Hale
[February 14, 2019, 11:03:35 AM]
New supplier for your sim
by Fcoq
[February 14, 2019, 12:18:44 AM]
For Sale Prosim 737 v2.03 License
by mdavenport
[February 12, 2019, 04:00:00 PM]
For Sale: Jetmax 737 TQ - Texas, USA
by MistyBlue
[February 11, 2019, 12:11:31 AM]
Complete 737-800 cockpit - moving sale
by navymustang
[February 10, 2019, 12:50:48 PM]
Operating System Blues
by n4208t
[February 10, 2019, 09:56:52 AM]
737-800 Arduino X-Plane Build
by kurt-olsson
[February 10, 2019, 09:31:17 AM]
Revolution Simproducts out of business?
by fsaviator
[February 09, 2019, 12:18:30 PM]
For sale: CPFlight MIP737SE
by Fly_AB
[February 08, 2019, 11:29:26 PM]
For sale: Engravity sixpack pairs --- SOLD
by Fly_AB
[February 08, 2019, 08:32:04 PM]
German B738NG Homecockpit-Projekt
by MjTom
[February 08, 2019, 08:00:54 AM]
Updating Navigraph FMC Data - Project Magenta / ProSim
by Trevor Hale
[February 08, 2019, 07:41:50 AM]
737 Demonstrator For Sale
by Trevor Hale
[February 08, 2019, 07:39:34 AM]
Looking for B737NG or A320 SIM for Home Use
by KingAviation
[February 08, 2019, 03:17:35 AM]
Zibo 737 FlightControl Dataref/Commands
by kurt-olsson
[February 05, 2019, 05:34:35 PM]
Wrong hiegth above ground when landing and P3D set for Panel Only
by FredK
[February 05, 2019, 12:58:20 AM]
Flight Control Panel A Side
by kurt-olsson
[February 04, 2019, 04:34:38 PM]
STEERING AND YOKE 737 PROMO
by alvaro castillo
[February 03, 2019, 09:19:32 PM]
Mickey's Flightdeck - A Boeing 737-800 Cockpit on Youtube
by Extraterra
[February 03, 2019, 02:51:28 PM]