/***************************************************************************
	ad2.c
	
   Z-World, 2001
	This sample program is used the BL2100 series controllers.

	This program demonstrates how to access the A/D channels with the API
	anaInVolt function. With using the anaInVolt function the program
	will continuously display the voltage that is being monitored.

	Instructions:
	-------------
	1. Connect a voltmeter to the output of the power supply that your
	going to use.

	2. Preset the voltage on the power supply to be within the voltage
	range of the A/D converter channel that your going to test. For A/D
	channels 0 - 10 the input voltage range is -10 to +10 volts.

	3. Power-on the controller.
	
	4. Connect the output of power supply to one of the A/D channels.

	5. Compile and run this program.

	6. Vary the voltage to the A/D channel, the voltage displayed in the
	STDIO	window and voltmeter should track each other.

***************************************************************************/

#define NUM_CHANNELS 11 	

// set the STDIO cursor location and display a string
void DispStr(int x, int y, char *s)
{
   x += 0x20;
   y += 0x20;
   printf ("\x1B=%c%c%s", x, y, s);
}

///////////////////////////////////////////////////////////////////////////
main ()
{
	auto int channel;
	auto float voltage;
	auto char s[80];

	brdInit();		// Required for BL2100 series boards
	
	sprintf(s, "A/D input voltages for channels 0 - %d", NUM_CHANNELS - 1 );
	DispStr(2, 2, s);
	DispStr(2, 3, "--------------------------------------");

	for(;;)
	{
		for(channel = 0; channel <= 10; channel++)
		{
			if((voltage = anaInVolts(channel)) < -10.99 || voltage > 10.99)
			{
				sprintf(s, "Channel = %d Voltage = out of range (voltage range -10 to +10)  ", channel);
				DispStr(2,channel + 4, s);
			}
			else
			{
				sprintf(s, "Channel = %d Voltage = %.4f (voltage range -10 to +10)  ", channel, voltage);
				DispStr(2,channel + 4, s);
			}
		}
	}
}
///////////////////////////////////////////////////////////////////////////

