Information
Table Of Contents

Analog Shield: Introduction
To sample one of the analog input channels, use the function below. read() returns the voltage read on the
channel. The voltage is returned in a binary representation from 0 to 65535 for -5V to 5V.
unsigned int read(int channel, bool mode = false);
To read from channel 0 (without differential mode) the syntax will look like this:
unsigned int data;
data = analog.read(0);
This method samples the selected analog input. ‘Mode’ is an optional parameter. False (the default value) is the
normal, single-ended mode where each analog pin is referenced to ground. True enables ‘differential’ mode,
where the value returned is the difference between the voltages on pairs of adjacent inputs (i.e., A0-A1 and A2-
A3). signedRead() acts the same at read() but returns a signed integer.
signedRead(int channel, bool mode = false);
To read from channel 0 (without differential mode) the syntax will look like this:
int data;
data = analog.read(0);
To write data to the DAC, there is a function called write(). This function allows the user to write to any channel:
channel 0 and 1; channel 0, 1, and 2; or channel 0, 1, 2, and 3.
write(int channel, unsigned int value);
write(unsigned int value0, unsigned int value1, bool mode);
write(unsigned int value0, unsigned int value1, unsigned int value2,
bool mode);
write(unsigned int value0, unsigned int value1, unsigned int value2,
unsigned int value3, bool mode);
To write a value just for channel 1, the syntax will look like this:
unsigned int data = 65535;
analog.write(1, data);
Copyright Digilent, Inc. All rights reserved.
Other product and company names mentioned may be trademarks of their respective owners.
Page 4 of 5





