I'm relatively new to writing my own code (most of my experience is in R for data analysis purposes). Anyways, I have a research project that I'm working on and I have some questions about how I can manipulate my arduino code to print voltage changes from multiple IR receivers to my excel doc using PLX DAQ v.11. Basically, I'm using a multiplexer to group my receiver data and I know that the setup is wired correctly. My problem is that I can't seem to get the voltages to print out in excel. My code for an individual diode pair works perfectly, but when I add in multiple inputs, things get odd.
Here is my code for the individual pair:
void setup() {
Serial.begin(9600);
Serial.println("CLEARSHEET");
Serial.println("LABEL,Time, Voltage");
}
void loop() {
//int aVal = analogRead(A0);
unsigned int ADCValue;
double Voltage;
double Vcc;
Vcc = readVcc()/1000.0;
ADCValue = analogRead(A0);
Voltage = (ADCValue / 1024.0) * Vcc;
int aVal = (int)(Voltage*100);
Serial.print("DATA, TIME");
Serial.print(",");
Serial.println((int)(Voltage*100));
delay(60);
}
long readVcc() {
long result;
// Read 1.1V reference against AVcc
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Convert
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result =1135200L / result; //1149852L / result; // Back-calculate AVcc in mV
return result;
}
Here is what I have for the multiplexer version
int pin1 = 8;
int pin2 = 9;
int pin3 = 10;
// digital pins to be switched
void setup() {
Serial.begin(9600);
pinMode(pin1, OUTPUT);
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
Serial.println("LABEL, Time, Cage 1, Cage 2");
}
void loop() {
set(1,0,0); // set pin 4
Serial.println(analogRead(0));
delay(10);
set(1,0,1); // set pin 5
Serial.println(analogRead(0));
delay(10);
set(0,1,0);// set pin 2
Serial.println(analogRead(0));
delay(10);
Serial.print("DATA, TIME");
Serial.print(",");
Serial.print(digitalWrite(pin1, HIGH));
Serial.print(",");
Serial.println(digitalWrite(pin2, HIGH));
delay(60);
}
void set(int a, int b, int c) //selects which pin on the multiplexer to read from
{
if(a == 1)
{digitalWrite(pin1, HIGH);}
else{digitalWrite(pin1, LOW);}
if(b == 1)
{digitalWrite(pin2, HIGH);}
else{digitalWrite(pin2, LOW);}
if(c == 1)
{digitalWrite(pin3, HIGH);}
else{digitalWrite(pin3, LOW);}
}
Any help would be greatly appreciated!
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.