micropython/tests/pyb/adc.py
Damien George d3bb3e38df tests/pyb: Adjust tests so they can run on PYB and PYBLITE.
A few tests still fail on PYBLITE, and that's due to differences in the
available peripheral block numbers on the different MCUs (eg I2C(2)
exists on one, but it's I2C(3) on the other).
2017-02-06 13:50:34 +11:00

34 lines
615 B
Python

from pyb import ADC
from pyb import Pin
pin = Pin('X22', mode=Pin.IN, pull=Pin.PULL_DOWN)
adc = ADC('X22')
print(adc)
# read single sample
val = adc.read()
assert val < 500
# timer for read_timed
tim = pyb.Timer(5, freq=500)
# read into bytearray
buf = bytearray(50)
adc.read_timed(buf, tim)
print(len(buf))
for i in buf:
assert i < 500
# read into arrays with different element sizes
import array
ar = array.array('h', 25 * [0])
adc.read_timed(ar, tim)
print(len(ar))
for i in buf:
assert i < 500
ar = array.array('i', 30 * [0])
adc.read_timed(ar, tim)
print(len(ar))
for i in buf:
assert i < 500