Cockpit

* User Profile

Welcome, Guest. Please login or register.

Login with username, password and session length

Who's Online

  • *Users: 0
  • *Guests: 14
  • *Total: 14

Our Discord

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

Offline kurt-olsson

  • I am chained to this website!
  • *
  • Posts: 1,181
  • 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: 337
  • 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,181
  • 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

What have you done for your simulator today?
by blueskydriver
[May 20, 2019, 07:28:19 PM]
GSX across networked client visual computers
by zillmer
[May 20, 2019, 05:38:53 PM]
Jetmax TQ - motorized it?
by FredK
[May 20, 2019, 07:58:36 AM]
Mickey's Flightdeck - A Boeing 737-800 Cockpit on Youtube
by Extraterra
[May 20, 2019, 02:47:37 AM]
FDS CDU old
by kattz
[May 19, 2019, 01:13:46 PM]
Serial Key
by hiflight1
[May 19, 2019, 05:10:00 AM]
Join me on Vatsim Tonight
by Trevor Hale
[May 15, 2019, 01:58:50 PM]
Gauge circuit
by jackpilot
[May 15, 2019, 01:56:51 PM]
Prosim and RSP TQ interfacing
by jfuenmayor
[May 15, 2019, 08:53:22 AM]
Arduino Mega question Newbie
by Yair1956
[May 15, 2019, 02:23:57 AM]
f18 mfd
by bernard S
[May 14, 2019, 11:15:44 PM]
Multi-Projector color calibration
by fsaviator
[May 13, 2019, 04:32:23 PM]
Immersive Calibration Pro help?
by jskibo
[May 13, 2019, 09:22:00 AM]
X-Plane 737-800 Build
by kenrosefire
[May 12, 2019, 08:37:05 PM]
KBD03 Keyboard Emulator
by Yair1956
[May 12, 2019, 03:52:05 PM]
5 Position Rotary Spring return Switch
by Yair1956
[May 12, 2019, 03:09:25 PM]
Flyengravity desktop MIP
by patiju
[May 11, 2019, 05:11:05 PM]
Pfd display.
by Patt737
[May 08, 2019, 12:48:32 PM]
Mini Sim
by jskibo
[May 08, 2019, 08:36:28 AM]
F16 Simulator For Sale
by blueskydriver
[May 08, 2019, 12:14:40 AM]
Wanted: Collins Style radios
by jkbarr30
[May 07, 2019, 08:23:32 PM]
Crap! 26V on 5V backlight!
by Steenos
[May 07, 2019, 05:33:46 PM]
Complete 737-800 cockpit - moving sale
by Ed
[May 07, 2019, 08:01:22 AM]
Prosim 737 iOS help
by Aztrucker
[May 06, 2019, 11:56:30 PM]
Fly Elise Warping
by jskibo
[May 06, 2019, 11:14:31 AM]
CPFlight 737 NG MCP Pro and Efis Pro (SOLD)
by patiju
[May 05, 2019, 10:52:46 AM]
Operating System Blues
by 727737Nut
[May 03, 2019, 11:54:35 AM]
FOR SALE - 737 Sim items
by flymo
[May 02, 2019, 07:43:53 AM]
Cpflight MCP737PRO (SOLD)
by archen
[April 30, 2019, 02:07:33 PM]
737-800 Arduino X-Plane Build
by Trevor Hale
[April 29, 2019, 07:29:12 PM]