Cockpit

* User Profile

Welcome, Guest. Please login or register.

Login with username, password and session length

Who's Online

  • *Users: 1
  • *Guests: 56
  • *Total: 57

Our Discord

Author Topic: Teensy LC Anti Ice Panel Sketch Code  (Read 428 times)

Offline kurt-olsson

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

International shipping?
by mickc
[June 25, 2019, 09:51:20 PM]
Flooring Installed!
by jackpilot
[June 25, 2019, 05:49:57 PM]
How much room between center pedestal and seat?
by jackpilot
[June 25, 2019, 08:19:42 AM]
PM MCP.ini Question...
by ScottThePilot
[June 25, 2019, 03:14:37 AM]
2020 Microsoft Flight Simulator - new at E3 2019
by blueskydriver
[June 24, 2019, 02:29:16 PM]
How to install DZUS fasteners?
by Buster99
[June 22, 2019, 04:12:34 PM]
Desert Air Spares - Trustworthy?
by kattz
[June 22, 2019, 12:40:51 PM]
Wanted - 737 Audio Panels - OEM
by jackpilot
[June 20, 2019, 12:26:51 PM]
Throttletek 737 Throttle For Sale
by kevinsayre
[June 19, 2019, 03:57:33 PM]
For sale - rudder pedals and linkages - pending to Craig
by Caflyt
[June 19, 2019, 07:49:14 AM]
737-800 Arduino X-Plane Build
by kurt-olsson
[June 18, 2019, 11:26:12 AM]
737 Throttle Conversion OC + ProSim
by kattz
[June 16, 2019, 11:39:03 AM]
A friendly FYI on Boeing rudder pedals
by kattz
[June 15, 2019, 10:36:39 AM]
737 starter switch mechanism
by paulnd
[June 13, 2019, 02:58:39 PM]
Make up your mind, Microsoft!
by jmlohrenz
[June 12, 2019, 07:25:10 PM]
What have you done for your simulator today?
by C150DIY
[June 12, 2019, 12:53:27 PM]
Complete 737-800 cockpit - moving sale
by FaustoP
[June 12, 2019, 01:26:39 AM]
Flyengravity desktop MIP
by patiju
[June 10, 2019, 01:01:06 PM]
the perfect thing to complete your sim hanger
by fsaviator
[June 09, 2019, 03:12:50 PM]
Wanted - COMPLETE set of Boeing 727 or 737 rudder pedals
by kattz
[June 08, 2019, 01:26:09 PM]
Visual system screen by Northern Flight Sim for sale $500
by peterkwu
[June 08, 2019, 06:07:39 AM]
Wanted: GoFlight T8
by C150DIY
[June 07, 2019, 02:32:29 PM]
For Sale - CPFlight MCP737 + EFIS
by ZillaUK
[June 07, 2019, 09:54:58 AM]
737 FWD Overhead Switch Diagram
by bernard S
[June 07, 2019, 08:21:46 AM]
Change the Forum Theme to suit your own Needs.
by AdamMilstead
[June 07, 2019, 06:20:41 AM]
Aileron & Elevator jump back to center
by iwik
[June 06, 2019, 08:01:24 PM]
Join me on Vatsim Tonight
by Trevor Hale
[June 05, 2019, 05:17:13 PM]
Machinery for home cockpit building
by giaviv
[June 04, 2019, 04:12:10 PM]
PROMOCION STEERING FREE
by alvaro castillo
[June 04, 2019, 11:42:43 AM]
FLIGHTSIMEXPO LAUNCHES DISCOUNTED ADVANCE REGISTRATION FOR ORLANDO 2019 EVENT
by fsaviator
[June 03, 2019, 06:52:44 PM]