The code is for a hardware/software DIY cockpit for the Hotstart TBM900. The issue was I could not get the hw_dial_add rotaries to work in a panel but they would work in create/edit. In this case I was using a rotaries to dial in altitude or heading. Here is a snippet of code that illustrates the problem
Code: Select all
--hw_dial_right_id=hw_dial_add("rightRotary",RR)--pin A is A10 B is A11
hw_dial_right_id=hw_dial_add("ARDUINO_MEGA2560_D_A10","ARDUINO_MEGA2560_D_A11",RR)--Pin A= A14 B=A13
But I don't understand why. There must be something I am missing in the documentation perhaps. If anyone can enlighten me I'd appreciate it
The actual code in this instrument which runs on an Arduino Mega is about 1000 line. To debug the issue I trimmed that down to the following, in case anyone needs this.
Tony, please forgive the print direction code after the If-then I put that in for debugging purposes.
Code: Select all
-- T B M - D - M A I N L A R G E P A N E L
-- T E S T T E S T T E S T
--================================================================
-- L E F T R O T A R Y A13 A14 A12(PRESSED)
--================================================================\--
local heading
--+++++++++++ H E A D I N G dataref and function needed to get heading so we can increment it
function hdg_change_callback(xheading)
print ("heading ="..xheading)
heading=xheading
end
xpl_dataref_subscribe ("tbm900/knobs/ap/hdg","INT",hdg_change_callback)
--+++++++++++end dataref code for xheading variable
function A12_pressed() -- L E F T
print("A12 Left Dial pressed")
xpl_command("tbm900/actuators/ap/hdg_sync")
end
hw_button_add("ARDUINO_MEGA2560_D_A12",A12_pressed)
function LR (direction) --Left Rotary - heading set
if direction==-1 then print ("LEFT Rotary dial rotated right")
heading=heading+2 elseif direction==1 then print ("Left rotary rotated left")
heading=heading-2
end
print (heading)
xpl_dataref_write("tbm900/knobs/ap/hdg","INT",heading)
end
-- L E F T R O T A R Y DIAL ADD
--NOTE THE NEXT LINE WORKS IN CREATE EDIT BUT WILL NOT RUN IN A PANEL
--hw_dial_left_id=hw_dial_add("Left_Rotary",LR)--Pin A= A14 B=A13
hw_dial_left_id=hw_dial_add("ARDUINO_MEGA2560_D_A14","ARDUINO_MEGA2560_D_A13",LR)--Pin A= A14 B=A13
--==================================================,
--================================================================
-- R I G H T R O T A R Y A13 A14 A15(PRESSED)
--================================================================
local altitude
--+++++++++++ H E A D I N G dataref and function needed to get heading so we can increment it
function alt_change_callback(xaltitude)
print ("Altitude ="..xaltitude)
altitude=xaltitude
end
xpl_dataref_subscribe ("tbm900/knobs/ap/alt","INT",alt_change_callback)
--+++++++++++end dataref code for xheading variable
---------------------------------------------------
function A15_pressed() --R I G H T
print("A15 Right Dial pressed")
xpl_command("sim/GPS/gcu478/alt_sync")
end
hw_button_add("ARDUINO_MEGA2560_D_A15",A15_pressed)
---------------------------------------------------
function RR(direction)
print ("RR")
if direction ==-1 then print ("right rotary turning right")
altitude=altitude+500
elseif direction ==1 then print ("right rotary turning left")
altitude=altitude-500
end
xpl_dataref_write("tbm900/knobs/ap/alt","INT",altitude)
end
-- R I G H T R O T A R Y DIAL ADD
--NOTE THE NEXT LINE WORKS IN CREATE EDIT BUT WILL NOT RUN IN A PANEL
--hw_dial_right_id=hw_dial_add("rightRotary",RR)--pin A is A10 B is A11
hw_dial_right_id=hw_dial_add("ARDUINO_MEGA2560_D_A10","ARDUINO_MEGA2560_D_A11",RR)--Pin A= A10 B=A11
--################################################################