looks for some input,... on multiplexing an input to 1 digital pin...

Hello All,

I am fairly new to the ARDUINO movement, and am looking for some constructive input on my project. It is for now just a proof of concept, but may be useful in using micro controllers with a limited amount of ports in the future.

I am using, (2) 4017 decade counters, (1) 4081 quad 2 input and gates, (1) 4078 8 input nor/or gate to multiplex a 3 x 4 button array,
everything is working and I plan to expand the array to up to 10 x 10.

My code is written for the arduino micro, because I am writing directly to the ports instead of using digitalWrite().

Here is my code:

/*Sketch Written By: Jeff Robbins
Purpose: as proof of concept in multplexing input into 1 Port
Note: This sketch is taylored for Micro Only because of direct
port communication...
*/

byte printFlag = false;//setting flag so variable is only printed once
char xVal[13] = "69#2580147*3";//lookup table for output to screen
void setup() {
Serial.begin(9600);// open serial prot
delay(5000);//wait 5 seconds for micro to intialize
pinMode(6,OUTPUT);//use pinMode to set dpin 6 for output
//direct port setup
//DDRD = DDRD | 0b00001000;// D3 Clock Enable Pin for OUTPUT (PD0)
DDRD = DDRD | 0b00010000;// D4 Clock Pin for OUTPUT (PD4)
DDRC = DDRC | 0b01000000;// D5 Reset Pin for OUTPUT (PC6)
DDRE = DDRE | 0b01000000;// D7 Set for OUTPUT (PE6)
//end of proy setup
Serial.print(DDRD, BIN);//display port D data direction register
Serial.print("(PD4)D4 = ");
Serial.println((DDRD>>4&1), BIN);//display port D bit 4
Serial.print(DDRC, BIN);//display port C data direction register
Serial.print("(PC6)D5 = ");
Serial.println((DDRC>>6&1), BIN);//display port C bit 6
Serial.print(DDRE, BIN);//display port E data direction register
Serial.print("(PE6)D7 = ");
Serial.println((DDRE>>6&1), BIN);//display port E bit 6

//sequence to reset decade counter
PORTC = PORTC | 0b01000000;
delay(250);
PORTC = PORTC ^ 0b01000000;
delay(250);
//end reset sequence
}

void loop() {
for(byte x = 0; x < 12; x++){

//strobe clock on decade counter
PORTD = PORTD | 0b00010000;
delay(1);
PORTD = PORTD ^ 0b00010000;
delay(1);
//end clock strobe sequence

while(PIND&1 == 1){//execute this while Dpin 2 is high
if(printFlag == false){//check to see if input was previously high
Serial.print(xVal[x]);//if not print xVal[x]
}
printFlag = true;//set flag to true if it was false
}
printFlag = false;//set flag to false if it was true

/*used for debugging perposes
Serial.println("Pin 3 is LOW.");
*/
}
}

Any input would be greatly appreciated, hardware or software that is...
Thanks All,
jrobbins0959

If number of inputs is not enough, there are serial-to-paralel shift regieters, why complicate with counters?
Alternative I2C port extenders, MCP23017 or MCP23008. Other things, is analog buttons.

Read this before posting a programming question

Code tags, please.

Hello Magician,

Thanks for your input...

As I said, I am fairly new at this, and don't know much about using the devices you are talking about... That is why I am asking for input from more experienced users, because I don't know the correct way. I thought by expanding my horizons it would allow me to think more on the lines of using code and logic together to achieve my goal. Maybe you can show me what you are talking about?

I know how counters work, and gates, but have no knowledge of port extenders and such. Also would the distance that the inputs are from the micro controller make a difference when using an analog signal???

Happy coding,
jarobbins0959.

I know how counters work, and gates, but have no knowledge of port extenders and such.

http://playground.arduino.cc//Main/InterfacingWithHardware#keyb

http://playground.arduino.cc//Main/InterfacingWithHardware#phi_interfaces

Also would the distance that the inputs are from the micro controller make a difference when using an analog signal???

Yes, sure it would. What distance do you need?

35 to 50 meters...

It looks to me, that your question is more on transmitting/ receiving matter, than on multiplexing. The truth is , you can't connect more than one button to one digital pin w/o extra hardware. So, why to try invent a wheel , building multiple button multiplexer based on counters, when it's well known matrix pad with column and row scanner. If there is not enough digital pins, it;s one problem, more logical and simple solution is using external uCPU , with more digital pins. If distance 50m, than there is absolutely different problem, and that can be addressed using serial protocol, I2C, over RF, zigbee etc.