#!/usr/bin/python

from ABElectronics_ADCDACPi import ADCDACPi
import time


# ================================================
# ABElectronics ADCDAC Pi 2-Channel ADC, 2-Channel DAC | ADC Read Demo
# Version 1.0 Created 17/05/2014
#
# run with: python demo-adcread.py
# ================================================

# this demo reads the voltage from channel 2 on the ADC inputs

adcdac = ADCDACPi() # create an instance of ADCDACPi

adcdac.setADCrefvoltage(3.3) # set the reference voltage.  this should be set to the exact voltage measured on the raspberry pi 3.3V rail.

while True:
    print adcdac.readADCvoltage(2) # read the voltage from channel 2 and display on the screen
    time.sleep(0.5)

#!/usr/bin/python

from ABElectronics_ADCDACPi import ADCDACPi
import time
import math

# ================================================
# ABElectronics ADCDAC Pi 2-Channel ADC, 2-Channel DAC | DAC sine wave generator demo
# Version 1.0 Created 17/05/2014
#
# run with: python demo-dacsinewave.py
# ================================================

# this demo uses the setDACraw method to generate a sine wave from a predefined set of values 

adcdac = ADCDACPi()

DACLookup_FullSine_12Bit = \
[ 2048, 2073, 2098, 2123, 2148, 2174, 2199, 2224,
  2249, 2274, 2299, 2324, 2349, 2373, 2398, 2423,
  2448, 2472, 2497, 2521, 2546, 2570, 2594, 2618,
  2643, 2667, 2690, 2714, 2738, 2762, 2785, 2808,
  2832, 2855, 2878, 2901, 2924, 2946, 2969, 2991,
  3013, 3036, 3057, 3079, 3101, 3122, 3144, 3165,
  3186, 3207, 3227, 3248, 3268, 3288, 3308, 3328,
  3347, 3367, 3386, 3405, 3423, 3442, 3460, 3478,
  3496, 3514, 3531, 3548, 3565, 3582, 3599, 3615,
  3631, 3647, 3663, 3678, 3693, 3708, 3722, 3737,
  3751, 3765, 3778, 3792, 3805, 3817, 3830, 3842,
  3854, 3866, 3877, 3888, 3899, 3910, 3920, 3930,
  3940, 3950, 3959, 3968, 3976, 3985, 3993, 4000,
#!/usr/bin/python

from ABElectronics_ADCDACPi import ADCDACPi
import time


# ================================================
# ABElectronics ADCDAC Pi 2-Channel ADC, 2-Channel DAC | DAC Write Demo
# Version 1.0 Created 17/05/2014
#
# run with: python demo-dacwrite.py
# ================================================

# this demo will generate a 1.5V p-p square wave at 1Hz

adcdac = ADCDACPi()

while True:
   adcdac.setDACvoltage(1, 1.5) # set the voltage on channel 1 to 1.5V
   time.sleep(0.5) # wait 0.5 seconds
   adcdac.setDACvoltage(1, 0) # set the voltage on channel 1 to 0V
   time.sleep(0.5) # wait 0.5 seconds