from machine import Pin
import time
# ==========================================
# PANEL FLIGHT SIM TEST - RP2040
# POR: Lopito96woof
# FOR DIY PRACTICE AND USE IN DCS WORLD
# ==========================================
# ------------------------------------------
# CONFIGURACION PINES
# YOU CAN DISCARD SOME PINs IN SOME FUNCTIONS
# ------------------------------------------
# GEAR SWITCH (ON-OFF-ON)
gear_up = Pin(0, Pin.IN, Pin.PULL_UP)
gear_down = Pin(1, Pin.IN, Pin.PULL_UP)
# MASTER ARM SWITCH
master_arm = Pin(2, Pin.IN, Pin.PULL_UP)
master_safe = Pin(3, Pin.IN, Pin.PULL_UP)
# LASER ARM SWITCH
laser_arm = Pin(4, Pin.IN, Pin.PULL_UP)
laser_off = Pin(5, Pin.IN, Pin.PULL_UP)
# FLAPS SWITCH (ON-OFF-ON)
flaps_norm = Pin(6, Pin.IN, Pin.PULL_UP)
flaps_extend = Pin(7, Pin.IN, Pin.PULL_UP)
# GEAR LIGHT
landing_light = Pin(8, Pin.IN, Pin.PULL_UP)
light_off = Pin(9, Pin.IN, Pin.PULL_UP)
taxi_light = Pin(10, Pin.IN, Pin.PULL_UP)
# AUTOPILOT
ap_on = Pin(11, Pin.IN, Pin.PULL_UP)
ap_path = Pin(12, Pin.IN, Pin.PULL_UP)
ap_hdg = Pin(13, Pin.IN, Pin.PULL_UP)
ap_att = Pin(14, Pin.IN, Pin.PULL_UP)
ap_alt = Pin(15, Pin.IN, Pin.PULL_UP)
ap_off = Pin(16, Pin.IN, Pin.PULL_UP)
ap_cancel = Pin(17, Pin.IN, Pin.PULL_UP)
# ------------------------------------------
# ESTADOS ANTERIORES
# ------------------------------------------
last_gear_up = gear_up.value()
last_gear_down = gear_down.value()
last_master_arm = master_arm.value()
last_master_safe = master_safe.value()
last_laser_arm = laser_arm.value()
last_laser_off = laser_off.value()
last_flaps_norm = flaps_norm.value()
last_flaps_extend = flaps_extend.value()
last_landing = landing_light.value()
last_loff = light_off.value()
last_taxi = taxi_light.value()
last_apon = ap_on.value()
last_appath = ap_path.value()
last_aphdg = ap_hdg.value()
last_apatt = ap_att.value()
last_apalt = ap_alt.value()
last_apoff = ap_off.value()
last_apcncl = ap_cancel.value()
print("FLIGHT PANEL TEST INICIADO")
time.sleep(1)
# ==========================================
# LOOP PRINCIPAL
# ==========================================
while True:
# --------------------------------------
# GEAR SWITCH
# --------------------------------------
current = gear_up.value()
if current != last_gear_up:
if current == 0:
print("GEAR UP")
last_gear_up = current
time.sleep_ms(20)
current = gear_down.value()
if current != last_gear_down:
if current == 0:
print("GEAR DOWN")
last_gear_down = current
time.sleep_ms(20)
# --------------------------------------
# MASTER ARM SWITCH
# --------------------------------------
current = master_arm.value()
if current != last_master_arm:
if current == 0:
print("MASTER ARM ON")
last_master_arm = current
time.sleep_ms(20)
current = master_safe.value()
if current != last_master_safe:
if current == 0:
print("MASTER ARM SAFE")
last_master_safe = current
time.sleep_ms(20)
# --------------------------------------
# LASER SWITCH
# --------------------------------------
current = laser_arm.value()
if current != last_laser_arm:
if current == 0:
print("LASER ARM")
last_laser_arm = current
time.sleep_ms(20)
current = laser_off.value()
if current != last_laser_off:
if current == 0:
print("LASER OFF")
last_laser_off = current
time.sleep_ms(20)
# --------------------------------------
# FLAPS SWITCH
# --------------------------------------
current = flaps_norm.value()
if current != last_flaps_norm:
if current == 0:
print("FLAPS NORM")
last_flaps_norm = current
time.sleep_ms(20)
current = flaps_extend.value()
if current != last_flaps_extend:
if current == 0:
print("FLAPS EXTEND")
last_flaps_extend = current
time.sleep_ms(20)
# --------------------------------------
# GEAR LIGHT
# --------------------------------------
current = landing_light.value()
if current != last_landing:
if current == 0:
print("LANDING LIGHT ON")
last_landing = current
time.sleep_ms(20)
current = light_off.value()
if current != last_loff:
if current == 0:
print("LIGHT OFF")
last_loff = current
time.sleep_ms(20)
current = taxi_light.value()
if current != last_taxi:
if current == 0:
print("TAXI LIGHT ON")
last_taxi = current
time.sleep_ms(20)
#---------------------------------------
# AUTOPILOT
#---------------------------------------
current = ap_on.value()
if current != last_apon:
if current == 0:
print("A/P ENGAGED")
last_apon = current
time.sleep_ms(20)
current = ap_path.value()
if current != last_appath:
if current == 0:
print("WAYPOINT FOLLOWING")
last_appath = current
time.sleep_ms(20)
current = ap_hdg.value()
if current != last_aphdg:
if current == 0:
print("HOLDING HEADING")
last_aphdg = current
time.sleep_ms(20)
current = ap_att.value()
if current != last_apatt:
if current == 0:
print("HOLDING ATITUDE")
last_apatt = current
time.sleep_ms(20)
current = ap_alt.value()
if current != last_apalt:
if current == 0:
print("HOLDING ALTITUDE")
last_apalt = current
time.sleep_ms(20)
current = ap_off.value()
if current != last_apoff:
if current == 0:
print("A/P DEACTIVATED")
last_apoff = current
time.sleep_ms(20)
current = ap_cancel.value()
if current != last_apcncl:
if current == 0:
print("DISENGAGED")
last_apcncl = current
time.sleep_ms(20)
time.sleep_ms(1)MASTER
ARM
SAFE
GEAR
UP
DOWN
LASER
ARM
OFF
FLAPS
NORM
EXTEND
LANDING
OFF
TAXI
LIGHT
BETTER WITH "ON-OFF" TYPE SWITCHES ---->
LESS WIRING
(CODE ALSO SHORTER)
ON-OFF-ON SWITCH
BETTER FOR THIS CASE ---->
------------------------A/P------------------------------
ON -------- PATH HOLD ------- HDG HOLD
ATT HOLD ------ ALT HOLD ------- OFF
----------------------CANCEL---------------------