Cockpit

* User Profile

Welcome, Guest. Please login or register.

Login with username, password and session length

Who's Online

  • *Users: 1
  • *Guests: 27
  • *Total: 28

Our Discord

WORLDFLIGHT 2018 - TEAM USA SUPPORTERS (HERO'S)


We would like to thank our HERO'S for Donating to support WORLDFLIGHT Team USA - 2018

Fred Kurasiewicz, Ray Sotkiewicz,Warren Soeldner, Kyle Hathaway-

Thanks to all of you, so far this year we have raised

$670.00 USD


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

Offline kurt-olsson

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

Join me on Vatsim Tonight
by Trevor Hale
[Today at 06:13:52 PM]
737-800 Arduino X-Plane Build
by kurt-olsson
[Today at 03:45:38 PM]
What have you done for your simulator today?
by Joe Lavery
[Today at 10:58:20 AM]
Converting KingAir to Glass
by Trooping
[Today at 10:17:02 AM]
Teensy LC Hydralic Panel
by kurt-olsson
[Today at 08:38:50 AM]
Can you guyse please check this link
by gjha97
[Today at 08:25:00 AM]
B737 Desktop sim project
by KyleH
[October 17, 2018, 09:23:40 PM]
KingAir B200 Builder
by flyinghigh
[October 17, 2018, 07:43:56 PM]
FOR SALE - Pair of IPECO Seats and J-Rails
by fsaviator
[October 16, 2018, 11:55:42 PM]
Edge Blending Blockers?
by FredK
[October 16, 2018, 06:42:58 PM]
More Throttle Quadrant nightmares.
by blueskydriver
[October 16, 2018, 02:14:44 PM]
Korry 318 push to test logic
by kurt-olsson
[October 15, 2018, 01:02:43 PM]
Had to Post (True Story) Funny as Hell though (glad noone was hurt)
by Trevor Hale
[October 15, 2018, 12:01:36 PM]
#Worldflight2018 Less than 20 Days to go!
by Trevor Hale
[October 15, 2018, 10:39:46 AM]
Active Sky 16 Networked to P3D V4 ?
by brianwilliamson
[October 14, 2018, 07:52:08 PM]
Computer Power supply strange 5V and strange behaviour Teensy is connected
by iwik
[October 14, 2018, 01:39:14 PM]
For Sale: Jetmax JetMax-737SKTQ
by Trevor Hale
[October 13, 2018, 08:56:35 PM]
Laser CNC cutting/etching using a 3D printer?
by Joe Lavery
[October 12, 2018, 11:28:59 AM]
For Sale GoFlight Jet Console, 2 Private Pilot Racks all with GoFlight Modules.
by Joe Lavery
[October 12, 2018, 10:57:35 AM]
Project Magenta with Xplane 11
by kevinsayre
[October 12, 2018, 08:14:25 AM]
13.8V ok for 12V use?
by kurt-olsson
[October 11, 2018, 12:40:48 PM]
INTRODUCTION
by twkster
[October 10, 2018, 11:31:27 PM]
SOLD: For sale New FlightsimPM B737 Throttle Quadrant v2.1
by fairchild
[October 10, 2018, 04:13:13 PM]
For sale,Commercial Packege Saitek Modules
by fairchild
[October 10, 2018, 03:05:47 PM]
CR-10, CR-10S, CR-10S4 and CR-10S5 3d Printer Info and Links...
by Trevor Hale
[October 10, 2018, 01:02:44 PM]
Mickey's Flightdeck - A Boeing 737-800 Cockpit on Youtube
by Joe Lavery
[October 10, 2018, 12:28:18 PM]
For Sale: CPFlight MCP 737 EL $400 USD Shipped Lower 48
by Giovan
[October 10, 2018, 05:18:11 AM]