Quote from: Jason L on August 24, 2023, 01:15:52 PMAny thoughts of using mobiflight as your interface instead of link2fs? Actively supported with multiple flavors of arduinos and works really well.Does it support FS9?
Quote from: Mach7 on August 24, 2023, 02:39:41 AMHello guys, the program works perfectly!!
Thank you!!!!!!!!!!..
@Arturo...I thought I knew what you were talking about with respect to the fuel quantity indication and battery bus power...now seeing it it makes perfect sense to me what you were trying to tell me. Still not an issue for me in this application, but now I understand what you were saying..thanks.
I will put up some screen shots up today.
Also...and not a really big deal...but is there anyway to have the fuel needle(s) move a bit slower to there requested positions?
I notice that it may be beneficial, (to the instrument life itself) to have the needle move slowly to the requested fuel levels...that is to say in transient states the needle will move very fast, epecially when it returns to zero from a high fuel state..the needle "bounces" off its stops.
This may not be too big of an issue...just thinking that anything that moves a bit slower may increase the life of the instrument itself.
Quote from: _alioth_ on August 24, 2023, 02:18:50 AMnew mistakes are always funnier, Ame!
I would like to code some cleaner and efficient way to read the link2fs data.
But I would need to know if:
- ticking the box "include CR/LF" there is always a return at the end of each command.
- ticking the box "include comma's between" sends always a "," at the end of each command.
First one, then the other. Not both at the same time, if posible.
Can you help me with this Mach7? you can see it in link2fs "to card" window or put some screenshots.
Thanks
Quote/*
This code is in the public domain
For use with "Link2fs_Multi"
Jimspage.co.nz (via archive.org)
*/
int CodeIn;// used on all serial reads
String flaps;
String fuel; // Re-use this variable for all fuel gauges as we only do one at a time
// PWM pins for gauges. Must be one of 3, 5, 6, 9, 10, or 11 for Arduino Uno
// Flaps
int flaps_PWM_out_pin = 3;
// Fuel
int fuel_L_PWM_out_pin = 5; // Left fuel gauge
int fuel_C_PWM_out_pin = 6; // Centre fuel gauge
int fuel_R_PWM_out_pin = 9; // Right fuel gauge
// Variables for fuel gauges
// Can be reused for each gauge as we do one at a time.
int fuel_PWM_out;
float fuel_percent;
float fuel_lbs;
float flaps_degrees = 0;
int PWM_out = 0;
// Variables to support incremental update of gauges
unsigned long currentMillis; // store the current time
unsigned long previousMillis;
unsigned long period = 100; // 100millis = 0.1s, 10 updates per second
// Variables for flaps gauge
const int flaps_max_PWM_per_slot = 1; // Maximum amount we can move in 0.1s
int flaps_PWM_target; // Target PWM value, based on last flaps degrees
int flaps_PWM_current; // Current PWM value, can only move slowly
bool first_flaps_PWM_value; // Flag to see if we should go directly to target
void setup()
{
Serial.begin(115200);
// Set up PWM pins.
pinMode(flaps_PWM_out_pin, OUTPUT);
pinMode(fuel_L_PWM_out_pin, OUTPUT);
pinMode(fuel_C_PWM_out_pin, OUTPUT);
pinMode(fuel_R_PWM_out_pin, OUTPUT);
// Set PWM values to zero.
analogWrite(flaps_PWM_out_pin, 0);
analogWrite(fuel_L_PWM_out_pin, 0);
analogWrite(fuel_C_PWM_out_pin, 0);
analogWrite(fuel_R_PWM_out_pin, 0);
flaps_PWM_target = 0;
flaps_PWM_current = 0;
first_flaps_PWM_value = true;
}
void loop() {
// Deal with incoming data from link2fs
if (Serial.available()) {
CodeIn = getChar();
if (CodeIn == '=') {
EQUALS(); // The first identifier is "="
}
if (CodeIn == '<') {
LESSTHAN(); // The first identifier is "<"
}
if (CodeIn == '?') {
QUESTION(); // The first identifier is "?"
}
if (CodeIn == '/') {
SLASH(); // The first identifier is "/" (Annunciators)
}
}
// Other tasks
// Currently we have to smooth the flaps output.
// Fuel gauges don't need smoothing.
currentMillis = millis(); // store the current time
if (currentMillis - previousMillis >= period) { // check if 100ms passed
// We're on a 100ms boundary
previousMillis = currentMillis; // update the time we were here
if (flaps_PWM_target > flaps_PWM_current) {
flaps_PWM_current += flaps_max_PWM_per_slot;
if (flaps_PWM_current > flaps_PWM_target) flaps_PWM_current = flaps_PWM_target;
}
else if (flaps_PWM_target < flaps_PWM_current) {
flaps_PWM_current -= flaps_max_PWM_per_slot;
if (flaps_PWM_current < flaps_PWM_target) flaps_PWM_current = flaps_PWM_target;
}
else {
// target and current are equal. Nothing to do.
}
analogWrite(flaps_PWM_out_pin, flaps_PWM_current);
}
}
char getChar()// Get a character from the serial buffer
{
while (Serial.available() == 0); // wait for data
return ((char)Serial.read()); // Thanks Doug
}
void EQUALS() { // The first identifier was "="
CodeIn = getChar(); // Get another character
switch (CodeIn) { // Now lets find what to do with it
case 'A'://Found the second identifier
//Do something
break;
case 'B':
//Do something
break;
case 'C':
//Do something
break;
}
}
void LESSTHAN() { // The first identifier was "<"
CodeIn = getChar(); // Get another character
switch (CodeIn) { // Now lets find what to do with it
case 'A'://Found the second identifier
//Do something
break;
case 'B':
//Do something
break;
case 'G': //Found the second identifier ("G" Flaps position)
// Next three characters should be numeric
flaps = "";
flaps += getChar();
flaps += getChar();
flaps += getChar();
// convert 3-character numeric string to a float
// Expected range is 000 to 033
flaps_degrees = flaps.toFloat();
// Convert degrees to PWM 0-255.
// 33 degrees is full scale, so multiplier is 255/33=7.727
PWM_out = flaps_degrees * 7.727;
// Clip output to maximum if (for some reason) it's >255
if (PWM_out > 255) PWM_out = 255;
// New flaps PWM is calculated. Copy to other variables to
// be handled by main loop on next 100ms boundary
flaps_PWM_target = PWM_out;
// If this is the first value we have received, go directly there.
if (first_flaps_PWM_value) {
flaps_PWM_current = flaps_PWM_target;
first_flaps_PWM_value = false;
}
Serial.print("G");
Serial.println (PWM_out);
break;
case 'X': // "X" left fuel gauge
// Next three characters should be numeric
fuel = "";
fuel += getChar();
fuel += getChar();
fuel += getChar();
// convert 3-character numeric string to a float
// It's a percentage of full, where full is 9200 lbs (left)
// Expected range is 000 to 100
fuel_percent = fuel.toFloat();
fuel_lbs = fuel_percent * 9200;
// Convert lbs to PWM 0-255.
// 0 lbs on gauge is PWM 75
// 10,000 lbs on gauge is 255
// So PWM is (1.8 x (lbs/100)) + 75
fuel_PWM_out = ((fuel_lbs * 1. / 10000) + 75.0;
// Clip output to maximum if (for some reason) it's >255
if (fuel_PWM_out > 255) fuel_PWM_out = 255;
// Drive the gauge
analogWrite(fuel_L_PWM_out_pin, fuel_PWM_out);
Serial.print("X");
Serial.println (fuel_lbs);
break;
case 'Y': // "Y" centre fuel gauge
// Next three characters should be numeric
fuel = "";
fuel += getChar();
fuel += getChar();
fuel += getChar();
// convert 3-character numeric string to a float
// It's a percentage of full, where full is 4400 lbs (centre)
// Expected range is 000 to 100
fuel_percent = fuel.toFloat();
fuel_lbs = fuel_percent * 4400;
// Convert lbs to PWM 0-255.
// 0 lbs on gauge is PWM 75
// 10,000 lbs on gauge is 255
// So PWM is (1.8 x (lbs/100)) + 75
fuel_PWM_out = ((fuel_lbs * 1. / 10000) + 75.0;
// Clip output to maximum if (for some reason) it's >255
if (fuel_PWM_out > 255) fuel_PWM_out = 255;
// Drive the gauge
analogWrite(fuel_C_PWM_out_pin, fuel_PWM_out);
Serial.print("Y");
Serial.println (fuel_PWM_out);
break;
case 'Z': // "Z" right fuel gauge
// Next three characters should be numeric
fuel = "";
fuel += getChar();
fuel += getChar();
fuel += getChar();
// convert 3-character numeric string to a float
// It's a percentage of full, where full is 9200 lbs (left)
// Expected range is 000 to 100
fuel_percent = fuel.toFloat();
fuel_lbs = fuel_percent * 9200;
// Convert lbs to PWM 0-255.
// 0 lbs on gauge is PWM 75
// 10,000 lbs on gauge is 255
// So PWM is (1.8 x (lbs/100)) + 75
fuel_PWM_out = ((fuel_lbs * 1. / 10000) + 75.0;
// Clip output to maximum if (for some reason) it's >255
if (fuel_PWM_out > 255) fuel_PWM_out = 255;
// Drive the gauge
analogWrite(fuel_R_PWM_out_pin, fuel_PWM_out);
Serial.print("Z");
Serial.println (fuel_PWM_out);
break;
}
}
void QUESTION() { // The first identifier was "?"
CodeIn = getChar(); // Get another character
switch (CodeIn) { // Now lets find what to do with it
case 'A'://Found the second identifier
//Do something
break;
case 'B':
//Do something
break;
case 'C':
//Do something
break;
}
}
void SLASH() { // The first identifier was "/" (Annunciator)
//Do something
}
Page created in 0.241 seconds with 25 queries.