Learning LUA and working my through things, I want to have a max 7219 readout that shows on the left side 4 digits the Xplane rad-alt and on the right side 4 digits a number/height as set by me, so that I can compare them to let me know when I’m close to or at the desired height AGL .
I can make the right side digits appear no problems, and they are controlled by the encoder. For the life of me I have no clue how to get the rad alt from a function into the readout.
Can someone please help me here as I’m stumped....not only the HOW but, and more importantly, the WHY it needs to be done a certain way?
Yes I’ve watched Tony’s videos, yes I’ve read the almost unintelligible LUA manual, so any explanation as what and why and how will be greatly appreciated.
Steve
Code: Select all
desired_height=0
function test_height (actual_height)
print(actual_height)
end
--set my own desired altitude with rotary encoder
function dial_change(direction)
if direction == 1 then
desired_height=desired_height+10
end
if
direction == -1 then
desired_height=desired_height-10
if desired_height<=0 then desired_height=0
end
end
----this is the only way i can get any number to pretend to be actual_height
actual_height = 100
--convert to string
local str = string.format("%.0f%4d", actual_height, desired_height)
-- Apply string to character display
print(str)
hw_chr_display_set_text(myheight, 0, 0, str)
end
-- Create a rotary encoder and add max7219 LCD Readout
hw_dial_add("ARDUINO_LEONARDO_A_D2", "ARDUINO_LEONARDO_A_D3", "TYPE_2_DETENT_PER_PULSE", 1, 10, dial_change )
myheight = hw_chr_display_add("MAX7219", 1, "ARDUINO_LEONARDO_A_D5", "ARDUINO_LEONARDO_A_D6", "ARDUINO_LEONARDO_A_D7")
--call backs
xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/radio_altimeter_height_ft_pilot","FLOAT", test_height)