=head1 NAME

PINE64::MCP300x - Perl interface to the MCP300x family of 10-bit 
analog to digital converters. 

=head1 SYNOPSIS

	use PINE64::MCP300x;

	my $adc = PINE64::MCP300x->new(10,12,11,13); 
	#5 bits because the first is the start bit
	my @ch0 = (1,1,0,0,0);

	for(my $s=0;$s<200;$s++){
		my ($reading, $binval, $voltage ) = $adc->read300x(\@ch0, 50, 5.01);
		$voltage = sprintf("%.3f", $voltage);
		print "binval: $binval\tvoltage: $voltage vdc\n";
		usleep(500000);
	}#end for

=head1 DESCRIPTION

This module allows you to control an MCP3004 or MCP3008 10-bit
analog to digital controller via bit-banged SPI using Perl on the
PINE64A+ single board computer. Works in single channel or 
differential mode. 

=head1 METHODS

=head2 new($clock,$data_in,$data_out,$chip_select) 

Takes clock pin number, SPI data in pin number, SPI data out pin
number, SPI chip select pin number, and returns a PINE64::MAX300x
object.  Pin numbers are valid PINE64::GPIO objects on the Pi-2
bus.

=head2 read300x($channel_number,$clk_pls_delay,$voltage_reference); 

This is the main function of the package.  It takes an array 
reference to select the channel number and mode (single/differential)
that you want to sample

The following are valid single channel array values:
@ch0 = (1,1,0,0,0);
@ch1 = (1,1,0,0,1);
@ch2 = (1,1,0,1,0);
@ch3 = (1,1,0,1,1);
@ch4 = (1,1,1,0,0);
@ch5 = (1,1,1,0,1);
@ch6 = (1,1,1,1,0);
@ch7 = (1,1,1,1,1);

The following are valid differential channel array values
@ch0_diff = (1,0,0,0,0);
@ch1_diff = (1,0,0,0,1);
@ch2_diff = (1,0,0,1,0);
@ch3_diff = (1,0,0,1,1);

So, when calling read300x, you would pass a reference of the 
channel you want to sample

$adc->read300x(\@ch0, 50, $vref);

The second argument is the delay between clock pulses in 
milliseconds.  This is a crude way to control the sample
speed.  I almost always use 50msec, and have had good
results.  

The third argument is a reference voltage and is optional. 
This method will calculate the returned voltage value based
on the output code of the converter in proportion of the
reference voltage.  So if the reference voltage is 50V, and
the output code is 512,  the method will return 25V.  

The reference voltage can be useful if you are using a voltage
divider circuit to step-down a voltage higher that the 
maximum input reference voltage of the MCP300x.  

read300x() returns an array that contains an array reference 
of the 10-bit binary result i.e. 1011010001, the output code 
in decimal i.e. 1024, 567, 311, etc., and the calculated
voltage based on the supplied reference voltage.   
		
Below is an example call to the read300x() method:
my ($reading, $binval, $voltage ) = $adc->read300x(\@ch0, 50, 5.01);
