def irq_handler(): """ irq_handler contains the code you want to execute when the interrupt occurs. Define your own callback function here by rewriting the code. We make an LED flash in this example. """ # open an LED session with academicIO.LEDs() as LED: # specify the LED which you want to control led = Led.LED1 # specify the LED status led_on_off = True # writes values 10 times, which makes LED1 flash for 3 seconds for x in range(0, 10): # turn LED0 on or off LED.write(led, led_on_off) # add a short delay time.sleep(0.3) # if the LED is on, set the parameter to off # if the LED is off, set the parameter to on led_on_off = not led_on_off
# turn LED0 on or off LED.write(led, led_on_off) # add a short delay time.sleep(0.3) # if the LED is on, set the parameter to off # if the LED is off, set the parameter to on led_on_off = not led_on_off # specify the span of time, in milliseconds, between when the program # starts and when an interrupt occurs irq_interval = 5000000 # 5000000us = 5s # configure a timer interrupt session with academicIO.TimerIRQ(irq_handler, irq_interval) as Timer_IRQ: # open the LED session LED = academicIO.LEDs() # specify the LED which you want to control led = Led.LED0 # specify the LED status led_on_off = True # create a thread to wait for the interrupt thread.start_new_thread(Timer_IRQ.wait, ()) # writes values 50 times, which makes LED0 flash for 25 seconds for x in range(0, 50): # turn LED0 on or off LED.write(led, led_on_off) # add a short delay time.sleep(0.5) # if the LED is on, set the parameter to off
""" Output: LED0 turns on and then LED1, LED2, LED3, LED0 turns off and then LED2, LED2, LED3 """ import time import sys sys.path.append('source/nielvisiii') import academicIO from enums import * with academicIO.LEDs() as LED: LED.write() # The default values are - led: led0, value_to_set = True. time.sleep(1) LED.write(led=Led.LED1) # The default 'value_to_set' is True time.sleep(1) LED.write(Led.LED2, True) time.sleep(1) LED.write(Led.LED3, True) time.sleep(1) LED.write(value_to_set=False) # the default 'led' is 'led0' time.sleep(1) LED.write(Led.LED1, False) time.sleep(1) LED.write(Led.LED2, False) time.sleep(1) LED.write(Led.LED3, False) time.sleep(1)