1""" 2ADC test for the CC3200 based boards. 3""" 4 5from machine import ADC 6import os 7 8mch = os.uname().machine 9if "LaunchPad" in mch: 10 adc_pin = "GP5" 11 adc_channel = 3 12elif "WiPy" in mch: 13 adc_pin = "GP3" 14 adc_channel = 1 15else: 16 raise Exception("Board not supported!") 17 18adc = ADC(0) 19print(adc) 20adc = ADC() 21print(adc) 22adc = ADC(0, bits=12) 23print(adc) 24 25apin = adc.channel(adc_channel) 26print(apin) 27apin = adc.channel(id=adc_channel) 28print(apin) 29apin = adc.channel(adc_channel, pin=adc_pin) 30print(apin) 31apin = adc.channel(id=adc_channel, pin=adc_pin) 32print(apin) 33 34print(apin.value() > 3000) 35print(apin() > 3000) 36 37# de-init must work 38apin.deinit() 39print(apin) 40 41adc.deinit() 42print(adc) 43print(apin) 44adc.init() 45print(adc) 46print(apin) 47apin.init() 48print(apin) 49print(apin() > 3000) 50 51# check for memory leaks... 52for i in range(0, 1000): 53 adc = ADC() 54 apin = adc.channel(adc_channel) 55 56# next ones should raise 57try: 58 adc = ADC(bits=17) 59except: 60 print("Exception") 61 62try: 63 adc = ADC(id=1) 64except: 65 print("Exception") 66 67try: 68 adc = ADC(0, 16) 69except: 70 print("Exception") 71 72adc = ADC() 73try: 74 apin = adc.channel(4) 75except: 76 print("Exception") 77 78try: 79 apin = adc.channel(-1) 80except: 81 print("Exception") 82 83try: 84 apin = adc.channel(0, pin="GP3") 85except: 86 print("Exception") 87 88apin = adc.channel(1) 89apin.deinit() 90try: 91 apin() 92except: 93 print("Exception") 94 95try: 96 apin.value() 97except: 98 print("Exception") 99 100adc.deinit() 101try: 102 apin.value() 103except: 104 print("Exception") 105 106try: 107 apin = adc.channel(1) 108except: 109 print("Exception") 110 111# re-init must work 112adc.init() 113apin.init() 114print(apin) 115print(apin() > 3000) 116