Cockpit

* User Profile

Welcome, Guest. Please login or register.

Login with username, password and session length

Who's Online

  • *Users: 0
  • *Guests: 36
  • *Total: 36

Our Discord

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

Offline kurt-olsson

  • I am chained to this website!
  • *
  • Posts: 1,101
  • 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: 309
  • 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,101
  • 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. =)

 

Recent Posts

New supplier for your sim
by Fcoq
[Today at 03:36:32 AM]
Join me on Vatsim Tonight
by Trevor Hale
[December 09, 2018, 05:18:02 PM]
What have you done for your simulator today?
by kurt-olsson
[December 09, 2018, 07:43:43 AM]
Yoke and Rudder Centering with Dynamic Load Control / Force Feedbacl
by bernard S
[December 08, 2018, 12:14:01 PM]
anyone that can help me out get imperial size bolts??
by Gallie
[December 08, 2018, 11:03:29 AM]
OpenCockpits I/O Cards
by al23
[December 08, 2018, 09:22:52 AM]
737-800 Arduino X-Plane Build
by kurt-olsson
[December 07, 2018, 01:56:27 PM]
Level D B767 For FS9
by Goodenough
[December 06, 2018, 08:19:20 PM]
Thickness of a resl 737-800 Glareshield / MCP Light panel
by Joe Lavery
[December 06, 2018, 01:13:54 PM]
Anyone had any experience with JetMax post the FDS sale?
by nickj
[December 05, 2018, 10:13:20 PM]
777 Throttle *price reduced*
by mattking247
[December 04, 2018, 11:05:04 PM]
KLGA curious !!
by jackpilot
[December 03, 2018, 02:55:38 PM]
Opencockpits boards for sale
by navymustang
[December 03, 2018, 12:57:34 PM]
Does something like this Exist? Projection Glass
by fsaviator
[December 02, 2018, 02:49:40 PM]
Move Project Magenta From FSX to P3D Full cockpit
by ScottThePilot
[December 02, 2018, 12:27:31 PM]
Mickey's Flightdeck - A Boeing 737-800 Cockpit on Youtube
by Extraterra
[December 02, 2018, 06:20:38 AM]
TH2GO Digital vs 3-DV Ports on GPU
by fsaviator
[December 01, 2018, 12:49:54 PM]
Project Magenta with Xplane 11
by Trevor Hale
[November 29, 2018, 03:05:14 PM]
X-plane and SIOC help
by Trevor Hale
[November 29, 2018, 07:43:32 AM]
Prepar3d v4.4 coming to you in 2 days!!!
by Flying_Fox
[November 28, 2018, 10:16:49 AM]
More Throttle Quadrant nightmares.
by iwik
[November 27, 2018, 03:47:31 PM]
Attention All Members and Guests
by Trevor Hale
[November 27, 2018, 02:21:47 PM]
I am now asking for a new world of hurt!
by fsaviator
[November 26, 2018, 11:50:19 PM]
Hello and advice about my 737 sim
by nic
[November 26, 2018, 05:42:07 AM]
B737 Rudder Pedal Adjustment Crank Units
by Reensel
[November 25, 2018, 02:53:25 PM]
For sale! B737 home cockpit - mostly OEM parts!
by Ethanoost
[November 25, 2018, 05:33:48 AM]
The Progression of a build [Phase One]
by Joe Lavery
[November 25, 2018, 03:58:12 AM]
OEM Duct Pressure Indicator
by Fly_AB
[November 24, 2018, 08:22:30 PM]
Oxygen Pressure Indicator
by Fly_AB
[November 24, 2018, 08:18:32 PM]
boeing overhead circuit breaker back light panel wiring
by kondrat
[November 21, 2018, 11:14:55 AM]