Cockpit

* User Profile

Welcome, Guest. Please login or register.

Login with username, password and session length

Who's Online

  • *Users: 1
  • *Guests: 34
  • *Total: 35

Our Discord

Author Topic: Teensy LC Anti Ice Panel Sketch Code  (Read 220 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 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: 309
  • 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,101
  • 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 »

 

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]