This is a project I'm doing and yes I'm allowed to ask for help. Ofcourse I wouldn't ask for help without trying it myself, I've been trying to do this with phototransistors for a while but only a few pins on the multiplexer seem to be working so I thought I'd test it out with LED's first as it seems many people have had a go at this.
Here's my code and schematic, its a little messy but displays what I'm doing
unsigned long time;
int sensorValue = 0;
float voltage7 = 0.0; //Pin 7 on the multiplexer
float voltage8 = 0.0; //Pin 8 on the multiplexer
int timeDelay = 50; // For reading pins after signalling multiplexer
void setup(){
Serial.begin(9600);
for (int i=0; i<8; i++){
pinMode(i,OUTPUT); //set pins as output
}
}
void loop(){
time=millis();
int sens = analogRead(A1); //read analog input 1
Serial.print("Direct readings "); //direct reading to compare
Serial.println(sens);
digitalWrite(0,HIGH); // multiplexer pin A
digitalWrite(1,HIGH); // multiplexer pin B
digitalWrite(2,HIGH); // multiplexer pin C
digitalWrite(3,LOW); // multiplexer pin D
// First read pin 7 on the Multiplexer:
//PORTD = B00000111;
digitalWrite(3,LOW); // pin 0 on multiplexer
delay(timeDelay);
sensorValue = analogRead(A0);
voltage7 = sensorValue * (5.0/1023.0);
//delay(50);
sensorValue = 0;
// Now for pin 8:
//PORTD = B00000110;
digitalWrite(3,HIGH); // pin 1 on multiplexer
delay(timeDelay);
sensorValue = analogRead(A0); //read input from common output of multiplexer
voltage8 = sensorValue * (5.0/1023.0);
sensorValue = 0;
delay(50);
//
Serial.print("Time ");
Serial.print(time+timeDelay, DEC);
Serial.print(", ");
Serial.print(voltage7, DEC);
Serial.print(", ");
Serial.print(time+2*timeDelay, DEC);
Serial.print(", ");
Serial.print(voltage8, DEC);
Serial.println();
//Keep a delay after you have finished all readings
delay(1000);
}