2014-05-03 16:43:27 +01:00
|
|
|
from pyb import ADC
|
|
|
|
from pyb import Pin
|
|
|
|
|
2015-03-13 22:11:50 +00:00
|
|
|
pin = Pin('X22', mode=Pin.IN, pull=Pin.PULL_DOWN)
|
2014-05-03 16:43:27 +01:00
|
|
|
adc = ADC('X22')
|
|
|
|
print(adc)
|
|
|
|
|
2015-03-13 22:11:50 +00:00
|
|
|
# read single sample
|
|
|
|
val = adc.read()
|
|
|
|
assert val < 500
|
2014-05-03 16:43:27 +01:00
|
|
|
|
2015-03-13 22:11:50 +00:00
|
|
|
# read into bytearray
|
|
|
|
buf = bytearray(50)
|
2014-05-03 16:43:27 +01:00
|
|
|
adc.read_timed(buf, 500)
|
2015-03-13 22:11:50 +00:00
|
|
|
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, 500)
|
|
|
|
print(len(ar))
|
|
|
|
for i in buf:
|
|
|
|
assert i < 500
|
|
|
|
ar = array.array('i', 30 * [0])
|
|
|
|
adc.read_timed(ar, 500)
|
|
|
|
print(len(ar))
|
|
|
|
for i in buf:
|
|
|
|
assert i < 500
|