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_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_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_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()
# files (the "Software"), to deal in the Software without # restriction, including without limitation the rights to use, copy, # modify, merge, publish, distribute, sublicense, and/or sell copies # of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # # This file is part of the Pumbaa project. # import time import board from drivers import Pin LED = Pin(board.PIN_LED, Pin.OUTPUT) while True: LED.toggle() time.sleep(0.5)
def test_set_mode(): led = Pin(board.PIN_LED, Pin.INPUT) led.set_mode(Pin.OUTPUT) with assert_raises(ValueError, "bad pin mode 6"): led.set_mode(6)
def test_input(): led = Pin(board.PIN_LED, Pin.INPUT) print(led)
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()
# restriction, including without limitation the rights to use, copy, # modify, merge, publish, distribute, sublicense, and/or sell copies # of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # # This file is part of the Pumbaa project. # import time import board from drivers import Pin LED = Pin(board.PIN_LED, Pin.OUTPUT) while True: LED.toggle() time.sleep(0.5)