src/MB4052.h
static uint8_t readADC(uint8_t ch)
	{
		static unsigned long last_on = 0UL; // time of last CS deactivated
		uint8_t val = 0;

		// select channel
		digitalWrite(C0_PIN, ch & 1);
		digitalWrite(C1_PIN, (ch >> 1) & 1);

		// wait for the minimum since CS went up time if necesarry 
		while (micros() - last_on < ADC_CSWCS)
			;
		
		digitalWrite(CS_PIN, LOW);
		delayMicroseconds(ADC_CSHCS);

		digitalWrite(CLK_PIN, HIGH);
		delayMicroseconds(ADC_TWACH);
		digitalWrite(CLK_PIN, LOW);
		delayMicroseconds(ADC_TWACL);
		//digitalRead(DATA_OUT_PIN); // start bit - ignore it

		for (int i = 0; i < 8; i++)
		{
			digitalWrite(CLK_PIN, HIGH);
			delayMicroseconds(ADC_TWACH);
			digitalWrite(CLK_PIN, LOW);
			val <<= 1;
			val |= digitalRead(DATA_OUT_PIN) ? 1 : 0;
			delayMicroseconds(ADC_TWACL);
		}

		digitalWrite(CLK_PIN, HIGH);
		delayMicroseconds(ADC_TWACH);
		digitalWrite(CLK_PIN, LOW);
		//digitalRead(DATA_OUT_PIN); // stop bit - ignore it
		//delayMicroseconds(ADC_TWACL);

		// done ADC - unselect
		digitalWrite(CS_PIN, HIGH);
		last_on = micros();

		return val;
	}
/// <summary> Performs ADC on a specified channel /// </summary>
/// <param name="ch"> chanel to read from 0-3 </param>
/// <returns> returns the value read (0-255) </returns>
 Performs ADC on a specified channel /// 
 chanel to read from 0-3 
 returns the value read (0-255) 
Performs ADC on a specified channel /// chanel to read from 0 - 3 returns the value read ( 0 - 255 )
static uint8_t readADC(uint8_t ch)
	{
		static unsigned long last_on = 0UL; 
		uint8_t val = 0;
		digitalWrite(C0_PIN, ch & 1);
		digitalWrite(C1_PIN, (ch >> 1) & 1);
		while (micros() - last_on < ADC_CSWCS)
			;
		digitalWrite(CS_PIN, LOW);
		delayMicroseconds(ADC_CSHCS);
		digitalWrite(CLK_PIN, HIGH);
		delayMicroseconds(ADC_TWACH);
		digitalWrite(CLK_PIN, LOW);
		delayMicroseconds(ADC_TWACL);
		for (int i = 0; i < 8; i++)
		{
			digitalWrite(CLK_PIN, HIGH);
			delayMicroseconds(ADC_TWACH);
			digitalWrite(CLK_PIN, LOW);
			val <<= 1;
			val |= digitalRead(DATA_OUT_PIN) ? 1 : 0;
			delayMicroseconds(ADC_TWACL);
		}
		digitalWrite(CLK_PIN, HIGH);
		delayMicroseconds(ADC_TWACH);
		digitalWrite(CLK_PIN, LOW);
		digitalWrite(CS_PIN, HIGH);
		last_on = micros();
		return val;
	}
static uint8_t readADC ( uint8_t ch ) { static unsigned long last_on = 0UL ; uint8_t val = 0 ; digitalWrite ( C0_PIN , ch & 1 ) ; digitalWrite ( C1_PIN , ( ch >> 1 ) & 1 ) ; while ( micros ( ) - last_on < ADC_CSWCS ) ; digitalWrite ( CS_PIN , LOW ) ; delayMicroseconds ( ADC_CSHCS ) ; digitalWrite ( CLK_PIN , HIGH ) ; delayMicroseconds ( ADC_TWACH ) ; digitalWrite ( CLK_PIN , LOW ) ; delayMicroseconds ( ADC_TWACL ) ; for ( int i = 0 ; i < 8 ; i ++ ) { digitalWrite ( CLK_PIN , HIGH ) ; delayMicroseconds ( ADC_TWACH ) ; digitalWrite ( CLK_PIN , LOW ) ; val <<= 1 ; val |= digitalRead ( DATA_OUT_PIN ) ? 1 : 0 ; delayMicroseconds ( ADC_TWACL ) ; } digitalWrite ( CLK_PIN , HIGH ) ; delayMicroseconds ( ADC_TWACH ) ; digitalWrite ( CLK_PIN , LOW ) ; digitalWrite ( CS_PIN , HIGH ) ; last_on = micros ( ) ; return val ; }
<summary> Performs ADC on a specified channel /// </summary>
<param name="ch"> chanel to read from 0-3 </param>
<returns> returns the value read (0-255) </returns>
<summary > Performs ADC on a specified channel /// < / summary > <param name = " ch " > chanel to read from 0 - 3 < / param > <returns > returns the value read ( 0 - 255 ) < / returns >
// time of last CS deactivated // select channel // wait for the minimum since CS went up time if necesarry  //digitalRead(DATA_OUT_PIN); // start bit - ignore it //digitalRead(DATA_OUT_PIN); // stop bit - ignore it //delayMicroseconds(ADC_TWACL); // done ADC - unselect