]>
vault307.fbx.one Git - ir_remote.git/blob - primitives/tests/adctest.py
3 # Copyright (c) 2020 Peter Hinch
4 # Released under the MIT License (MIT) - see LICENSE file
6 import uasyncio
as asyncio
7 from machine
import ADC
9 from primitives
import AADC
11 async def signal(): # Could use write_timed but this prints values
12 dac
= pyb
.DAC(1, bits
=12, buffering
=True)
16 print('write', v
<< 4) # Make value u16 as per ADC read
20 await asyncio
.sleep_ms(50)
23 asyncio
.create_task(signal())
24 adc
= AADC(ADC(pyb
.Pin
.board
.X1
))
25 await asyncio
.sleep(0)
26 adc
.sense(normal
=False) # Wait until ADC gets to 5000
27 value
= await adc(5000, 10000)
28 print('Received', value
, adc
.read_u16(True)) # Reduce to 12 bits
29 adc
.sense(normal
=True) # Now print all changes > 2000
31 value
= await adc(2000) # Trigger if value changes by 2000
32 print('Received', value
, adc
.read_u16(True))
34 st
= '''This test requires a Pyboard with pins X1 and X5 linked.
35 A sawtooth waveform is applied to the ADC. Initially the test waits
36 until the ADC value reaches 5000. It then reports whenever the value
38 Issue test() to start.
44 asyncio
.run(adctest())
45 except KeyboardInterrupt:
48 asyncio
.new_event_loop()