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