Frasca 142 gauges

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
Jeff_S
Posts: 2
Joined: Sun Mar 17, 2024 6:10 pm

Frasca 142 gauges

#1 Post by Jeff_S »

Hi everyone,

I have acquired a Frasca 142 simulator and I have been trying to re-purpose it to use MSFS 2020. I have been using Chatgpt to try and generate some code but I can't seem to get it working.

Currently I am attempting to make the ADI guage work.

It has 1 pot for the pitch and 1 pot for the bank. I am just trying to get the pitch working at the moment. I have an H-Bridge which I can use to power the 12v motors separately, and can reverse the motors using 2 pwm pins each.

The pitch pot maxes out at 67% when the pitch is in full upward deflection, and 0% at minimum deflection.

How do I make the coding move the motors?

This is what I have so far, which it only displays the current pot position. Any help would be greatly appreciated.
Thanks!



----------------------------------



PitchValue = 0.0
BankValue = 0.0

-- Function to map a value from one range to another
function map(x, in_min, in_max, out_min, out_max)
return out_min + (x - in_min) * (out_max - out_min) / (in_max - in_min)
end

-- Function to handle ADC input for pitch and bank
function adc_input_PitchBank(PitchV, BankV)
-- Map the ADC values to the range (-1, 1) for Pitch and Bank
PitchValue = -1 + 2 * map(PitchV, 0, 1023, 0, 66) -- Assuming 0-66 is the range for PitchV
BankValue = map(BankV, 0, 1023, -360, 360) -- Assuming -360 to 360 is the range for BankV

-- Print the mapped values for debugging
print("Pitch: " .. PitchValue .. ", Bank: " .. BankValue)
end

-- Function to handle changes in Bank value
function new_bank_callback(Bank)
-- Call adc_input_PitchBank with the updated Bank value
adc_input_PitchBank(PitchValue, Bank)
end

-- Function to handle changes in Pitch value
function new_pitch_callback(Pitch)
-- Call adc_input_PitchBank with the updated Pitch value
adc_input_PitchBank(Pitch, BankValue)
end

if value is changing positive, then


-- Subscribe to FS2020 variables for Pitch and Bank values
fs2020_variable_subscribe("ATTITUDE INDICATOR PITCH DEGREES", "Degrees", new_pitch_callback)
fs2020_variable_subscribe("ATTITUDE INDICATOR BANK DEGREES", "Degrees", new_bank_callback)

-- Function to handle ADC input
function adc_callback(value)
-- Round the value to get percentage
percent = var_round(value * 100, 0)
-- Print the percentage for debugging
print("Pitch Input: " .. percent .. "%")
end

-- Add ADC input for debugging
hw_adc_input_id = hw_adc_input_add("ARDUINO_MEGA2560_A_A2", adc_callback)

Post Reply