def test_output(): led = Pin(board.PIN_LED, Pin.OUTPUT) print(led) led.write(1) value = led.read() if os.uname().machine != "Linux with Linux": assert value == 1 led.toggle() value = led.read() if os.uname().machine != "Linux with Linux": assert value == 0
def test_bad_arguments(): # Bad mode. with assert_raises(ValueError, "bad pin mode 3"): Pin(board.PIN_LED, 3) # bad device. with assert_raises(ValueError, "bad pin device -1"): Pin(-1, Pin.OUTPUT) with assert_raises(ValueError, "bad pin device 500"): Pin(500, Pin.OUTPUT) led = Pin(board.PIN_LED, Pin.OUTPUT) with assert_raises(ValueError, "bad pin value 2"): led.write(2)
def test_falling_edge(): pin = Pin(board.PIN_D4, Pin.OUTPUT) pin.write(1) event = Event() exti = Exti(board.EXTI_D3, Exti.FALLING, event, 0x1) exti.start() # Make sure no interrupt has already occured. assert event.size() == 0 # Trigger the interrupt and wait for the event. pin.write(0) if not 'Linux' in os.uname().machine: print("Waiting for the interrupt to occur... ") assert event.read(0x1) == 0x1 exti.stop()
def test_falling_edge(): pin = Pin(board.PIN_D4, Pin.OUTPUT) pin.write(1) event = Event() exti = Exti(board.EXTI_D3, Exti.FALLING, event, 0x1) exti.start() # Make sure no interrupt has already occured. assert event.size() == 0 # Trigger the interrupt and wait for the event. pin.write(0) if not 'Linux' in os.uname().machine: print("Waiting for the interrupt to occur... ", end="") assert event.read(0x1) == 0x1 print("ok.") exti.stop()
def test_rising_edge_two_pins(): pin_a = Pin(board.PIN_D4, Pin.OUTPUT) pin_b = Pin(board.PIN_D6, Pin.OUTPUT) pin_a.write(0) pin_b.write(0) queue = Queue() exti_a = Exti(board.EXTI_D3, Exti.RISING, queue, 'a') exti_b = Exti(board.EXTI_D5, Exti.RISING, queue, 'b') exti_a.start() exti_b.start() # Make sure no interrupt has already occured. assert queue.size() == 0 # Trigger interrupts to create the character sequence 'aaba'. pin_a.write(1) pin_a.write(0) pin_a.write(1) pin_a.write(0) pin_b.write(1) pin_b.write(0) pin_a.write(1) pin_a.write(0) if not 'Linux' in os.uname().machine: print("Waiting for the character sequence... ") assert queue.read(4) == b'aaba' exti_a.stop() exti_b.stop()