def DAQC2Interrupt(args):
    global AD
    global DINInterrupt
    global DINByte
    # get DIN digital inputs values
    DINByte = DAQC2.getDINall(AD)
    # debounce button before clearing interrupt (! software deboucining slow down OSC send rate, including CANs)
    # sleep(0.01)
    DINInterrupt = DAQC2.getINTflags(AD)
    pass
#####################
# Main
OSCLED("off")

# GPIO 22 is used as external interrupt from DAQC2. Enable interrupts on this pin
GPIO.setmode(GPIO.BCM)
GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# set interrupt callback
# ? strange behaviour of bouncetime>1, see sleep() in interrupt callback alternative ? worth check with GPIO module update
GPIO.add_event_detect(22, GPIO.FALLING, callback=DAQC2Interrupt, bouncetime=1)
# enable interrupt also on 0-7 DAQC2 Digital Inputs for both edges
for i in range(8):
    DAQC2.enableDINint(AD, i, "b")
# reset interrupt flag, pin GPIO.22 should be high
DINInterrupt = DAQC2.getINTflags(AD)
if (DAQC2.GPIO.input(22) == 1):
    print(str(datetime.datetime.now()), "External interrupts OK.")

# Start the OSC system.
osc_startup()
print(str(datetime.datetime.now()), "OSC system started.")

# Make server channels to receive and send packets with LOCAL IP
osc_udp_server("127.0.0.1", rxPort, "OSCRx")
print(
    str(datetime.datetime.now()),
    "Local OSC server up and running on port " + str(rxPort) + " @" + localIP)
osc_udp_client(ipAddress, txPort, "OSCTx")
print(str(datetime.datetime.now()),
      "OSC client up and running on port " + str(txPort) + " @" + ipAddress)