Welcome to the forum for MobiFlight! Feel free to reach out to the community in case you have questions, issues or just want to share great ideas or details about your latest home cockpit project.
You like MobiFlight? Donate via PayPal and support the MobiFlight development. Thanks!
The community support for MobiFlight has moved exclusively over to our Discord server. Register for free and enjoy more interactive functions like image and video upload, voice chat. More than 7,000 registered users around the world make it a great experience!
See you on our MobiFlight Community Discord server.
A HUGE Thank You to everyone who participated in the forum, especially obviously to Pizman and Stephan who did an outstanding job over so many years providing an incredible service to the MobiFlight community.
The forum is still providing a lot of good content, hence we keep this information accessible.
Code:
--------------------------------------------- -- Chronometer -- -- Modification of Russ Barlows original -- -- OAT & Time indicator -- -- Brian McMullan 20180324 -- -- Property for background off/on -- -- Property for dimming overlay -- --------------------------------------------- --------------------------------------------- -- Properties -- --------------------------------------------- prop_BG = user_prop_add_boolean("Background Display",true,"Hide background?") prop_DO = user_prop_add_boolean("Dimming Overlay",false,"Enable dimming overlay?") --------------------------------------------- -- Load and display images in Z-order -- -- Loaded images selectable with prop -- --------------------------------------------- -- Load images in Z-order -- txt_load_font("digital-7-mono.ttf") if user_prop_get(prop_BG) == false then img_add_fullscreen("Chrono.png") else img_add_fullscreen("ChronowBG.png") end img_on = img_add_fullscreen("ChronoON.png") img_light = img_add_fullscreen("ChronoONLight.png") img_UT = img_add("arrowup.png",57,213,34,6) img_FT = img_add("arrowdown.png",57,222,34,6) img_LT = img_add("arrowup.png",105,213,34,6) img_ET = img_add("arrowdown.png",105,222,34,6) if user_prop_get(prop_DO) == true then img_add_fullscreen("dimoverlay.png") end -- Load text in Z-order -- txt_time = txt_add(" ", "size:80px; color: black; halign: right;", 135, 170, 200, 100) txt_tempvolt = txt_add(" ", "size:80px; color: black; halign: center;", 45, 85, 300, 250) -- Set default visibility -- visible(img_on, false) visible(img_light, false) visible(img_UT, false) visible(img_FT, false) visible(img_LT, false) visible(img_ET, false) visible(txt_time, false) -- General vars -- local gbl_power = false local gbl_oatv_state = 0 local gbl_time_state = 0 local gbl_time_reset = 0 -- Button functions -- function new_oatv() gbl_oatv_state = gbl_oatv_state + 1 if (gbl_oatv_state > 2) then gbl_oatv_state = 0 end end function new_time() gbl_time_state = gbl_time_state + 1 if (gbl_time_state > 3) then gbl_time_state = 0 end end function new_control_pressed() if not timer_running(timer_control) and gbl_time_state == 3 and gbl_power then gbl_time_reset = 0 timer_control = timer_start(0,100,timer_control_callback) end xpl_command("sim/instruments/timer_start_stop") end function new_control_released() if timer_running(timer_control) then timer_stop(timer_control) gbl_time_reset = 0 end end function timer_control_callback() gbl_time_reset = gbl_time_reset + 0.1 if gbl_time_reset > 3 then gbl_time_reset = 0 xpl_command("sim/instruments/timer_reset") timer_stop(timer_control) end end -- Functions -- function new_timeoat(zulu_hours, zulu_minutes, local_hours, local_minutes, time_flight, elapsed_minutes, elapsed_seconds, temperature, avionics, light, voltage, bus_voltage) gbl_power = avionics == 1 and bus_voltage[1] >= 10 visible(img_on, gbl_power) visible(img_light, light >= 1 and gbl_power) if gbl_time_state == 0 then vis_time = string.format("%02.0f:%02.0f", (zulu_hours - (zulu_hours%1)), (zulu_minutes - (zulu_minutes%1))%60) elseif gbl_time_state == 1 then vis_time = string.format("%02.0f:%02.0f", (local_hours - (local_hours%1)), (local_minutes - (local_minutes%1))%60) elseif gbl_time_state == 2 then vis_time = string.format("%02.0f:%02.0f",(time_flight / 3600), ( (time_flight / 60) % 60) ) elseif gbl_time_state == 3 then vis_time = string.format("%02.0f:%02.0f", elapsed_minutes, elapsed_seconds) end visible(img_UT, gbl_time_state == 0 and gbl_power) visible(img_FT, gbl_time_state == 2 and gbl_power) visible(img_LT, gbl_time_state == 1 and gbl_power) visible(img_ET, gbl_time_state == 3 and gbl_power) if gbl_oatv_state == 0 and avionics == 1 then txt_set(txt_tempvolt, string.format("T " .. "%.0f" .. "'C", temperature ) ) elseif gbl_oatv_state == 1 and avionics == 1 then txt_set(txt_tempvolt, string.format("T " .. "%.0f" .. "'F", (temperature * 1.8) + 32 ) ) elseif gbl_oatv_state == 2 and avionics == 1 then txt_set(txt_tempvolt, var_format(voltage[1], 1) .. "E" ) else txt_set(txt_tempvolt, " ") end visible(txt_time, gbl_power) txt_set(txt_time, vis_time) end function new_timeoat_fsx(zulu_hours, zulu_minutes, local_hours, local_minutes, time_elapsed, temperature, avionics, light, voltage, bus_voltage) avionics = fif(avionics, 1, 0) light = fif(light, 1, 0) -- There is no flight time and timer elapsed time in FSX new_timeoat(zulu_hours, zulu_minutes, local_hours, local_minutes, time_elapsed, 0, 0, temperature, avionics, light, {voltage}, {bus_voltage}) end --------------------------------------------- -- Switches, buttons and dials -- --------------------------------------------- button_oatv = button_add("buttonred.png","buttonredpr.png",140,-16,120,120, new_oatv) button_time = button_add("buttonblue.png", "buttonbluepr.png", 60, 280, 120, 120, new_time) button_control = button_add("buttonblue.png", "buttonbluepr.png", 223, 280, 120, 120, new_control_pressed, new_control_released) --------------------------------------------- -- Simulator Subscriptions -- --------------------------------------------- xpl_dataref_subscribe("sim/cockpit2/clock_timer/zulu_time_hours", "INT", "sim/cockpit2/clock_timer/zulu_time_minutes", "INT", "sim/cockpit2/clock_timer/local_time_hours", "INT", "sim/cockpit2/clock_timer/local_time_minutes", "INT", "sim/time/total_flight_time_sec", "FLOAT", "sim/cockpit2/clock_timer/elapsed_time_minutes", "INT", "sim/cockpit2/clock_timer/elapsed_time_seconds", "INT", "sim/weather/temperature_ambient_c", "FLOAT", "sim/cockpit/electrical/avionics_on", "INT", "sim/cockpit/electrical/cockpit_lights_on", "INT", "sim/cockpit2/electrical/battery_voltage_indicated_volts", "FLOAT[8]", "sim/cockpit2/electrical/bus_volts", "FLOAT[6]", new_timeoat) fsx_variable_subscribe("ZULU TIME", "Hours", "ZULU TIME", "Minutes", "LOCAL TIME", "Hours", "LOCAL TIME", "Minutes", "SIM TIME", "Seconds", "TOTAL AIR TEMPERATURE", "Celsius", "ELECTRICAL MASTER BATTERY", "Bool", "LIGHT PANEL", "Bool", "ELECTRICAL BATTERY VOLTAGE", "Volts", "ELECTRICAL MAIN BUS VOLTAGE", "Volts", new_timeoat_fsx) --------------------------------------------- -- END Chronometer -- ---------------------------------------------
Code:
-- Push Button OAT-Volts -- Callback function which is called when the button is pressed function button_pressed() print("button pressed") end -- Callback function which is called when the button is released function button_released() print("button_released") end -- Bind to Arduino A, Pin 2 hw_button_add("ARDUINO_NANO_A_D2, button_pressed, button_released) -- Push Button SELECT-Volts -- Callback function which is called when the button is pressed function button_pressed() print("button pressed") end -- Callback function which is called when the button is released function button_released() print("button_released") end -- Bind to Arduino A, Pin 4 hw_button_add("ARDUINO_NANO_A_D4, button_pressed, button_released) -- Push Button CONTROL-Volts -- Callback function which is called when the button is pressed function button_pressed() print("button pressed") end -- Callback function which is called when the button is released function button_released() print("button_released") end -- Bind to Arduino A, Pin 8 hw_button_add("ARDUINO_NANO_A_D8, button_pressed, button_released)
Code:
--------------------------------------------- -- Chronometer -- -- Modification of Russ Barlows original -- -- OAT & Time indicator -- -- Brian McMullan 20180324 -- -- Property for background off/on -- -- Property for dimming overlay -- --------------------------------------------- --------------------------------------------- -- Properties -- --------------------------------------------- prop_BG = user_prop_add_boolean("Background Display",true,"Hide background?") prop_DO = user_prop_add_boolean("Dimming Overlay",false,"Enable dimming overlay?") --------------------------------------------- -- Load and display images in Z-order -- -- Loaded images selectable with prop -- --------------------------------------------- -- Load images in Z-order -- txt_load_font("digital-7-mono.ttf") if user_prop_get(prop_BG) == false then img_add_fullscreen("Chrono.png") else img_add_fullscreen("ChronowBG.png") end img_on = img_add_fullscreen("ChronoON.png") img_light = img_add_fullscreen("ChronoONLight.png") img_UT = img_add("arrowup.png",57,213,34,6) img_FT = img_add("arrowdown.png",57,222,34,6) img_LT = img_add("arrowup.png",105,213,34,6) img_ET = img_add("arrowdown.png",105,222,34,6) if user_prop_get(prop_DO) == true then img_add_fullscreen("dimoverlay.png") end -- Load text in Z-order -- txt_time = txt_add(" ", "size:80px; color: black; halign: right;", 135, 170, 200, 100) txt_tempvolt = txt_add(" ", "size:80px; color: black; halign: center;", 45, 85, 300, 250) -- Set default visibility -- visible(img_on, false) visible(img_light, false) visible(img_UT, false) visible(img_FT, false) visible(img_LT, false) visible(img_ET, false) visible(txt_time, false) -- General vars -- local gbl_power = false local gbl_oatv_state = 0 local gbl_time_state = 0 local gbl_time_reset = 0 -- Button functions -- function new_oatv() gbl_oatv_state = gbl_oatv_state + 1 if (gbl_oatv_state > 2) then gbl_oatv_state = 0 end end function new_time() gbl_time_state = gbl_time_state + 1 if (gbl_time_state > 3) then gbl_time_state = 0 end end function new_control_pressed() if not timer_running(timer_control) and gbl_time_state == 3 and gbl_power then gbl_time_reset = 0 timer_control = timer_start(0,100,timer_control_callback) end xpl_command("sim/instruments/timer_start_stop") end function new_control_released() if timer_running(timer_control) then timer_stop(timer_control) gbl_time_reset = 0 end end function timer_control_callback() gbl_time_reset = gbl_time_reset + 0.1 if gbl_time_reset > 3 then gbl_time_reset = 0 xpl_command("sim/instruments/timer_reset") timer_stop(timer_control) end end -- Functions -- function new_timeoat(zulu_hours, zulu_minutes, local_hours, local_minutes, time_flight, elapsed_minutes, elapsed_seconds, temperature, avionics, light, voltage, bus_voltage) gbl_power = avionics == 1 and bus_voltage[1] >= 10 visible(img_on, gbl_power) visible(img_light, light >= 1 and gbl_power) if gbl_time_state == 0 then vis_time = string.format("%02.0f:%02.0f", (zulu_hours - (zulu_hours%1)), (zulu_minutes - (zulu_minutes%1))%60) elseif gbl_time_state == 1 then vis_time = string.format("%02.0f:%02.0f", (local_hours - (local_hours%1)), (local_minutes - (local_minutes%1))%60) elseif gbl_time_state == 2 then vis_time = string.format("%02.0f:%02.0f",(time_flight / 3600), ( (time_flight / 60) % 60) ) elseif gbl_time_state == 3 then vis_time = string.format("%02.0f:%02.0f", elapsed_minutes, elapsed_seconds) end visible(img_UT, gbl_time_state == 0 and gbl_power) visible(img_FT, gbl_time_state == 2 and gbl_power) visible(img_LT, gbl_time_state == 1 and gbl_power) visible(img_ET, gbl_time_state == 3 and gbl_power) if gbl_oatv_state == 0 and avionics == 1 then txt_set(txt_tempvolt, string.format("T " .. "%.0f" .. "'C", temperature ) ) elseif gbl_oatv_state == 1 and avionics == 1 then txt_set(txt_tempvolt, string.format("T " .. "%.0f" .. "'F", (temperature * 1.8) + 32 ) ) elseif gbl_oatv_state == 2 and avionics == 1 then txt_set(txt_tempvolt, var_format(voltage[1], 1) .. "E" ) else txt_set(txt_tempvolt, " ") end visible(txt_time, gbl_power) txt_set(txt_time, vis_time) end function new_timeoat_fsx(zulu_hours, zulu_minutes, local_hours, local_minutes, time_elapsed, temperature, avionics, light, voltage, bus_voltage) avionics = fif(avionics, 1, 0) light = fif(light, 1, 0) -- There is no flight time and timer elapsed time in FSX new_timeoat(zulu_hours, zulu_minutes, local_hours, local_minutes, time_elapsed, 0, 0, temperature, avionics, light, {voltage}, {bus_voltage}) end --------------------------------------------- -- Switches, buttons and dials -- --------------------------------------------- button_oatv = hw_button_add("ARDUINO_NANO_A_D2, new_oatv) button_time = hw_button_add("ARDUINO_NANO_A_D4, new_time) button_control = hw_button_add("ARDUINO_NANO_A_D8, new_control_pressed, new_control_released) --------------------------------------------- -- Simulator Subscriptions -- --------------------------------------------- xpl_dataref_subscribe("sim/cockpit2/clock_timer/zulu_time_hours", "INT", "sim/cockpit2/clock_timer/zulu_time_minutes", "INT", "sim/cockpit2/clock_timer/local_time_hours", "INT", "sim/cockpit2/clock_timer/local_time_minutes", "INT", "sim/time/total_flight_time_sec", "FLOAT", "sim/cockpit2/clock_timer/elapsed_time_minutes", "INT", "sim/cockpit2/clock_timer/elapsed_time_seconds", "INT", "sim/weather/temperature_ambient_c", "FLOAT", "sim/cockpit/electrical/avionics_on", "INT", "sim/cockpit/electrical/cockpit_lights_on", "INT", "sim/cockpit2/electrical/battery_voltage_indicated_volts", "FLOAT[8]", "sim/cockpit2/electrical/bus_volts", "FLOAT[6]", new_timeoat) fsx_variable_subscribe("ZULU TIME", "Hours", "ZULU TIME", "Minutes", "LOCAL TIME", "Hours", "LOCAL TIME", "Minutes", "SIM TIME", "Seconds", "TOTAL AIR TEMPERATURE", "Celsius", "ELECTRICAL MASTER BATTERY", "Bool", "LIGHT PANEL", "Bool", "ELECTRICAL BATTERY VOLTAGE", "Volts", "ELECTRICAL MAIN BUS VOLTAGE", "Volts", new_timeoat_fsx) --------------------------------------------- -- END Chronometer -- ---------------------------------------------