#include <Plaquette.h>
#include <light_CD74HC4067.h>
const int N_CHANNELS = 4; //define how many channels you are using
CD74HC4067 mux(2, 3, 4, 5); //remember to NOT use pin 0 or 1
SquareWave wave(0.1); //the frequency of reading channels
AnalogIn commonInput(A0);
float myVals[N_CHANNELS]; //the array automatically has enough space for your channels now
int currentChannel = 0;
void begin()
{
}
void step() {
///I would probably run this continually in the background
//It would be cleaner to have this in a function and away from your main code.
if (wave.rose()) {
// Set channel.
mux.channel(currentChannel);
}
else if (wave.fell()) {
// Print value.
print(commonInput);
print(" ");
// Store value in an array
myVals[currentChannel] = commonInput;
currentChannel++;
if (currentChannel >= N_CHANNELS) {
currentChannel = 0;
println();
}
}
//code anything you want here.
//you can access myVals but remember to start at index 0.
}
Loading
cd74hc4067
cd74hc4067