#include <SPI.h>
const int ltcs = 3; //active low ADC enable
float ch0=0.0;
float ch1=0.0;
byte b0;
void setup() {
SPI.begin();
SPI.beginTransaction(SPISettings(200000, MSBFIRST, SPI_MODE0));
Serial.begin(9600); // set the baud rate
pinMode(ltcs, OUTPUT);
digitalWrite(ltcs, LOW);
}
void loop() {
if(Serial.available()){
int data = Serial.read() - '0';
if(data>0){
getdata2(ch0,ch1);
//getdata2(ch0,ch1); //run multiple getdata2 to test multiple conversions
//getdata2(ch0,ch1);
//getdata2(ch0,ch1);
//getdata2(ch0,ch1);
Serial.println(0.2);
Serial.println(0.4);
}
}
}
void getdata2(float &ch0, float &ch1) {
ch0 = 0.0;
ch1 = 0.0;
for (int i = 0; i < 2; i++) {
//Do twice to retrieve delayMicroseconds(1);both Channels
while (digitalRead(MISO) == HIGH) {
}
if (digitalRead(MISO) == LOW) {
b0 = SPI.transfer(0x00);
b0 = SPI.transfer(0x00);
b0 = SPI.transfer(0x00);
b0 = SPI.transfer(0x00);
}
}
}