I have this sample code for the Mux Shield II and I want it to read through all 16 input on IO1, all 16 input on IO2, all 16 input on IO3. one at a time and only once. Then print all 16 inputs for each IO once.
//This example shows how to use the Mux Shield for digital inputs #include <MuxShield.h>
//Initialize the Mux Shield
MuxShield muxShield;
void setup()
{
//Set IO1, IO2, and IO3 as digital inputs
muxShield.setMode(1,DIGITAL_IN_PULLUP);
//use DIGITAL_IN in place of DIGITAL_IN_PULLUP if internal pullups are not needed
muxShield.setMode(2,DIGITAL_IN_PULLUP);
muxShield.setMode(3,DIGITAL_IN_PULLUP);
Serial.begin(28800);
}
//Arrays to store digital values
int IO1DigitalVals[16];
int IO2DigitalVals[16];
int IO3DigitalVals[16];
void loop()
{
for (int i=0; i<16; i++)
{
//Digital read on all 16 inputs on IO1, IO2, and IO3
IO1DigitalVals = muxShield.digitalReadMS(1,i);
_ IO2DigitalVals = muxShield.digitalReadMS(2,i);_ _ IO3DigitalVals = muxShield.digitalReadMS(3,i);
* }*_
* //Print IO 1 values for inspection* * Serial.print("IO1 analog values: ");* * for (int i=0; i<16; i++)* * {* _ Serial.print(IO1DigitalVals*); Serial.print(’\t’); } Serial.println(); }*_
//This example shows how to use the Mux Shield for digital inputs #include <MuxShield.h>
//Initialize the Mux Shield
MuxShield muxShield;
void setup()
{
//Set IO1, IO2, and IO3 as digital inputs
muxShield.setMode(1,DIGITAL_IN_PULLUP);
//use DIGITAL_IN in place of DIGITAL_IN_PULLUP if internal pullups are not needed
muxShield.setMode(2,DIGITAL_IN_PULLUP);
muxShield.setMode(3,DIGITAL_IN_PULLUP);
Serial.begin(28800);
}
//Arrays to store digital values
int IO1DigitalVals[16];
int IO2DigitalVals[16];
int IO3DigitalVals[16];
void loop()
{
for (int i=0; i<16; i++)
{
//Digital read on all 16 inputs on IO1, IO2, and IO3
IO1DigitalVals = muxShield.digitalReadMS(1,i);
IO2DigitalVals = muxShield.digitalReadMS(2,i);
IO3DigitalVals = muxShield.digitalReadMS(3,i);
}
//Print IO 1 values for inspection
Serial.print("IO1 analog values: ");
for (int i=0; i<16; i++)
{
Serial.print(IO1DigitalVals);
Serial.print(’\t’);
}
Serial.println();
}[code][/code]
//This example shows how to use the Mux Shield for digital inputs
#include <MuxShield.h>
//Initialize the Mux Shield
MuxShield muxShield;
void setup()
{
//Set IO1, IO2, and IO3 as digital inputs
muxShield.setMode(1,DIGITAL_IN_PULLUP);
//use DIGITAL_IN in place of DIGITAL_IN_PULLUP if internal pullups are not needed
muxShield.setMode(2,DIGITAL_IN_PULLUP);
muxShield.setMode(3,DIGITAL_IN_PULLUP);
Serial.begin(28800);
}
//Arrays to store digital values
int IO1DigitalVals[16];
int IO2DigitalVals[16];
int IO3DigitalVals[16];
void loop()
{
for (int i=0; i<16; i++)
{
//Digital read on all 16 inputs on IO1, IO2, and IO3
IO1DigitalVals = muxShield.digitalReadMS(1,i);
IO2DigitalVals = muxShield.digitalReadMS(2,i);
IO3DigitalVals = muxShield.digitalReadMS(3,i);
}
//Print IO 1 values for inspection
Serial.print("IO1 analog values: ");
for (int i=0; i<16; i++)
{
Serial.print(IO1DigitalVals);
Serial.print('\t');
}
Serial.println();
}
OK, Sorry!!! I am new to this, and to coding all together but I have did some change to the code and I have it printing to serial like this:
IO1 analog values: 1111111111111111 IO2 analog values: 1111111111111111 IO3 analog values: 1111…
Printing once.
Can’t seem to get the code to print in list form?
//This example shows how to use the Mux Shield for digital inputs
#include <MuxShield.h>
//Initialize the Mux Shield
MuxShield muxShield;
//Arrays to store digital values
int IO1DigitalVals[16];
int IO2DigitalVals[16];
int IO3DigitalVals[16];
void setup() {
//Set IO1, IO2, and IO3 as digital inputs
muxShield.setMode(1,DIGITAL_IN_PULLUP);
//use DIGITAL_IN in place of DIGITAL_IN_PULLUP if internal pullups are not needed
muxShield.setMode(2,DIGITAL_IN_PULLUP);
muxShield.setMode(3,DIGITAL_IN_PULLUP);
Serial.begin(9600);
delay(2000);
for (int i=0; i<16; i++)
{
//Digital read on all 16 inputs on IO1, IO2, and IO3
IO1DigitalVals[i] = muxShield.digitalReadMS(1,i);
}
//Print IO 1 values for inspection
Serial.print("IO1 analog values: ");
for (int i=0; i<16; i++)
{
Serial.print(IO1DigitalVals[i]);
}
Serial.print('\t');
delay(500);
for (int i=0; i<16; i++)
{
//Digital read on all 16 inputs on IO1, IO2, and IO3
IO2DigitalVals[i] = muxShield.digitalReadMS(2,i);
}
//Print IO 2 values for inspection
Serial.print("IO2 analog values: ");
for (int i=0; i<16; i++)
{
Serial.print(IO2DigitalVals[i]);
}
Serial.print('\t');
delay(500);
for (int i=0; i<16; i++)
{
//Digital read on all 16 inputs on IO1, IO2, and IO3
IO3DigitalVals[i] = muxShield.digitalReadMS(3,i);
}
//Print IO 3 values for inspection
Serial.print("IO3 analog values: ");
for (int i=0; i<16; i++)
{
Serial.print(IO3DigitalVals[i]);
}
Serial.println();
delay(500);
exit(0);
}
If you want to put each on a separate line, put "Serial.println();" instead of "Serial.print('\t');" between them. The '\t' is a tab character. The .println() sends a newline character to start a new line.