Exemple #1
0
def test_bad_arguments():
    # Bad device.
    with assert_raises(ValueError, "bad device"):
        Adc(67, 0)

    # Bad pin device.
    with assert_raises(ValueError, "bad pin device"):
        Adc(board.ADC_0, -5)

    # Bad reference.
    with assert_raises(ValueError, "bad reference"):
        Adc(board.ADC_0, PIN_A0, -1)

    # Bad sampling rate.
    with assert_raises(ValueError, "bad sampling rate"):
        Adc(board.ADC_0, PIN_A0, Adc.REFERENCE_VCC, 0)
Exemple #2
0
def test_convert():
    a0 = Adc(board.ADC_0, PIN_A0, Adc.REFERENCE_VCC, 100)
    a1 = Adc(board.ADC_0, PIN_A1)
    a0_sample = a0.convert(1)
    a1_sample = a1.convert(1)
    assert len(a0_sample) == 2
    assert len(a1_sample) == 2
    print("A0 sample:", a0_sample, struct.unpack('H', a0_sample)[0])
    print("A1 sample:", a1_sample, struct.unpack('H', a1_sample)[0])
Exemple #3
0
def test_async_convert():
    a0 = Adc(board.ADC_0, PIN_A0)
    a0.async_convert(2)
    a0_sample = a0.async_wait()
    assert len(a0_sample) == 4
    print("A0 sample:", a0_sample, struct.unpack('HH', a0_sample))
Exemple #4
0
def test_print():
    print(Adc)
    help(Adc)
    a0 = Adc(board.ADC_0, PIN_A0, Adc.REFERENCE_VCC, 100)
    print(a0)