Cockpit

* User Profile

Welcome, Guest. Please login or register.

Login with username, password and session length

Who's Online

  • *Users: 1
  • *Guests: 75
  • *Total: 76

Our Discord

Author Topic: Teensy LC Anti Ice Panel Sketch Code  (Read 290 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 Anti Ice Panel Sketch Code
« on: October 05, 2018, 04:09:01 PM »
Hi.

This is the final code for my OEM Anti ice Panel used with Zibo 737 and X-Plane with a Teensy LC.

const int PIN_5V_BACKLIGHT = 22;
const int PIN_KORRY_PUSH_TO_TEST = 10;

const int PIN_KORRY_LIGHT_COWL_ANTI_ICE_1 = 3;
const int PIN_KORRY_LIGHT_COWL_ANTI_ICE_2 = 17;
const int PIN_KORRY_LIGHT_COWL_VALVE_OPEN_1 = 4;
const int PIN_KORRY_LIGHT_COWL_VALVE_OPEN_2 = 6;
const int PIN_KORRY_LIGHT_L_VALVE_OPEN = 16;
const int PIN_KORRY_LIGHT_R_VALVE_OPEN = 20;

const int PIN_SWITCH_ENGINE_ANTI_ICE_1 = 19;
const int PIN_SWITCH_WING_ANTI_ICE = 9;
const int PIN_SWITCH_ENGINE_ANTI_ICE_2 = 7;

//CONNECTED SWITCH PINS NOT USED: 18,5,21,8

FlightSimFloat xPlane_wing_ice_on_left;
FlightSimFloat xPlane_wing_ice_on_right;
FlightSimFloat xPlane_cowl_ice_on_0;
FlightSimFloat xPlane_cowl_ice_on_1;
FlightSimFloat xPlane_cowl_ice_0;
FlightSimFloat xPlane_cowl_ice_1;

FlightSimFloat xPlane_eng1_heat_pos;
FlightSimFloat xPlane_eng2_heat_pos;
FlightSimFloat xPlane_wing_heat_pos;

//array, overhead panel = 2
FlightSimFloat xPlane_panel_brightness_ratio_manual;
void setup() {
  // put your setup code here, to run once:
  xPlane_wing_ice_on_left = XPlaneRef("laminar/B738/annunciator/wing_ice_on_L");
  xPlane_wing_ice_on_right = XPlaneRef("laminar/B738/annunciator/wing_ice_on_R");
  xPlane_cowl_ice_on_0 = XPlaneRef("laminar/B738/annunciator/cowl_ice_on_0");
  xPlane_cowl_ice_on_1 = XPlaneRef("laminar/B738/annunciator/cowl_ice_on_1");
  xPlane_cowl_ice_0 = XPlaneRef("laminar/B738/annunciator/cowl_ice_0");
  xPlane_cowl_ice_1 = XPlaneRef("laminar/B738/annunciator/cowl_ice_1");

  xPlane_eng1_heat_pos = XPlaneRef("laminar/B738/ice/eng1_heat_pos");
  xPlane_eng2_heat_pos = XPlaneRef("laminar/B738/ice/eng2_heat_pos");
  xPlane_wing_heat_pos = XPlaneRef("laminar/B738/ice/wing_heat_pos");

  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_L_VALVE_OPEN,OUTPUT);
  pinMode(PIN_KORRY_LIGHT_R_VALVE_OPEN,OUTPUT);
  pinMode(PIN_KORRY_LIGHT_COWL_VALVE_OPEN_1,OUTPUT);
  pinMode(PIN_KORRY_LIGHT_COWL_VALVE_OPEN_2,OUTPUT);
  pinMode(PIN_KORRY_LIGHT_COWL_ANTI_ICE_1,OUTPUT);
  pinMode(PIN_KORRY_LIGHT_COWL_ANTI_ICE_2,OUTPUT);

  pinMode(PIN_SWITCH_ENGINE_ANTI_ICE_1,INPUT_PULLUP);
  pinMode(PIN_SWITCH_WING_ANTI_ICE,INPUT_PULLUP);
  pinMode(PIN_SWITCH_ENGINE_ANTI_ICE_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); //this should be controlled by the aircrafts battery/amp power, if no power then the korry should not light on this test.

  analogWrite(PIN_KORRY_LIGHT_L_VALVE_OPEN, mapfloat(xPlane_wing_ice_on_left, 0,1,0,255));     
  analogWrite(PIN_KORRY_LIGHT_R_VALVE_OPEN, mapfloat(xPlane_wing_ice_on_right,0,1,0,255));
  analogWrite(PIN_KORRY_LIGHT_COWL_VALVE_OPEN_1,mapfloat(xPlane_cowl_ice_on_0,0,1,0,255));
  analogWrite(PIN_KORRY_LIGHT_COWL_VALVE_OPEN_2,mapfloat(xPlane_cowl_ice_on_1,0,1,0,255));
  analogWrite(PIN_KORRY_LIGHT_COWL_ANTI_ICE_1,mapfloat(xPlane_cowl_ice_0,0,1,0,255));
  analogWrite(PIN_KORRY_LIGHT_COWL_ANTI_ICE_2,mapfloat(xPlane_cowl_ice_1,0,1,0,255));

  if (digitalRead(PIN_SWITCH_WING_ANTI_ICE) == HIGH && xPlane_wing_heat_pos == 0) {
    xPlane_wing_heat_pos = 1;
  }
  if (digitalRead(PIN_SWITCH_WING_ANTI_ICE) == LOW && xPlane_wing_heat_pos == 1) {
    xPlane_wing_heat_pos = 0;
  }

  if (digitalRead(PIN_SWITCH_ENGINE_ANTI_ICE_2) == HIGH && xPlane_eng2_heat_pos == 1) {
    xPlane_eng2_heat_pos = 0;
  }
  if (digitalRead(PIN_SWITCH_ENGINE_ANTI_ICE_2) == LOW && xPlane_eng2_heat_pos == 0) {
    xPlane_eng2_heat_pos = 1;
  }

  if (digitalRead(PIN_SWITCH_ENGINE_ANTI_ICE_1) == HIGH && xPlane_eng1_heat_pos == 1) {
    xPlane_eng1_heat_pos = 0;
  }
  if (digitalRead(PIN_SWITCH_ENGINE_ANTI_ICE_1) == LOW && xPlane_eng1_heat_pos == 0) {
    xPlane_eng1_heat_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;
}
« Last Edit: October 06, 2018, 08:59:38 AM by kurt-olsson »

Offline archen

  • Forum GURU
  • *
  • Posts: 322
  • Aviation Enthusiast
    • Anders Simparts
  • First Name: Anders
  • Home Location: Falun
Teensy LC Anti Ice Panel Sketch Code
« Reply #1 on: October 06, 2018, 01:49:13 AM »
Hello Peter,

This looks awesome. I'm currently using Arduino with SimVim but I'm looking at options for my desktop 737 sim I'm building.

Is it hard to learn teensy? Do you have any good links on how to get started? I understand teensy is Arduino based. Is it possible to use any Arduino board or do you need a teensy specific board?

I like the simplicity with SimVim but as you know with simplicity comes limitations so I'm looking for alternatives.

Is teensy able to communicate via Ethernet?


Best regards
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 Anti Ice Panel Sketch Code
« Reply #2 on: October 06, 2018, 08:06:06 AM »
Hi Anders.

I started with Arduino and was going to write my C++ plugin myself for X-plane because i wanted total control and not be limited by another library written by someone else. But FlightsimControl is all i wanted it had exactly the same architechture that i was building for. So no need to invent the wheel again.

Read:https://www.pjrc.com/teensy/td_flightsim.html

Teensy with X-Plane is a real win, stable and fast. I dont know if your using X-plane but for me there is no option to use old FSX or Prepared3D that looks ugly and is a slideshow. See lots of people building cool setup ending up with cartoon 13FPS. But this is my own opinion.

I have only tried the Teensy with USB cable, i am not going wifi route because it needs to be stable and cable provides just that.

Also the coding is really easy, there are 4-5 different techniques in a boeing. Switch, lights, motors etc and it is alot of repettwting coding for all components.

I am using sketch language same as on Arduino, really great.

« Last Edit: October 06, 2018, 09:01:12 AM by kurt-olsson »

 

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]