Button matrix to SIP output controlling MAX395

Hello Arduino Forum!

I've gone in way over my head here, but I thought maybe you guys could show me the next step, if anyone has a second.

The Idea

Use 8 pushbuttons connected to 8 digital ins on the arduino, controlling two max395 piggybacked on one another.

The Schematic

Note that pins 2-9 all have the same switching connection, but there wasn't enough room to put them all on each pin, so only pins 2 and 9 are shown.

The Reason

Each switch toggles one switch in each 395, the same in each, which controls an audio pathway in one 395, and an LED in the second. That one, when one button is pushed, the corresponding LED is lit, showing that pathway is activated.

The Code

Now the part I noob out. The basic idea of this was based on a good fellow named Arnoud on another forum, who used a different voltage divider on each switch, reading the voltage on one pin to determine which button was pushed. He used a 395 for switching and a 4015 for the LED's. I'd like to keep it simple and just use 395.

I have this as the setup:

const int rep1 = 2; //Repeat button 1 to digital pin 2
const int rep2 = 3; //Repeat button 2 to digital pin 3
const int rep3 = 4; //Repeat button 3 to digital pin 4
const int rep4 = 5; //Repeat button 4 to digital pin 5

const int reg1 = 6; //Regeneration button 1 to digital pin 6
const int reg2 = 7; //Regeneration button 1 to digital pin 7
const int reg3 = 8; //Regeneration button 1 to digital pin 8
const int reg4 = 9; //Regeneration button 1 to digital pin 9

int max_clock = 13; //Output clock for max395
int max_data = 12; //Output data for max395
int max_cs = 11; //Output cs for max395

void setup () {
pinMode (rep1, INPUT); //Initialize repeat pins as inputs
pinMode (rep2, INPUT);
pinMode (rep3, INPUT);
pinMode (rep4, INPUT);
pinMode (reg1, INPUT); //Initialize regen pins as inputs
pinMode (reg2, INPUT);
pinMode (reg3, INPUT);
pinMode (reg4, INPUT);
pinMode (max_clock, OUTPUT); //Initialize 13,12,11 as outputs
pinMode (max_data, OUTPUT);
pinMode (max_cs, OUTPUT);
}

Then, I get confused ::slight_smile: I have seen code similar to what the predisesor of the idea used, which may or may not have looked something like this

void loop () {

int sum = 0; //Setting max395
if(digitalRead(rep1) == HIGH){
sum += 128;
}
if(digitalRead(rep2) == HIGH){
sum += 64;
}
if(digitalRead(rep3) == HIGH){
sum += 32;
}
if(digitalRead(rep4) == HIGH){
sum += 16;
}

if(digitalRead(reg1) == HIGH){
sum += 8;
}
if(digitalRead(reg2) == HIGH){
sum += 4;
}
if(digitalRead(reg3) == HIGH){
sum += 2;
}
if(digitalRead(reg4) == HIGH){
sum += 1;
}

return sum;
}

However, I don't quite understand what is going on or if anything like that is close to being correct. I also understand that there may need to be some debounce code somewhere, but I couldn't quite get that into my head either >:(

Does anybody have advice on how to continue this project? Any advice is much appreciated. Thank you!

Ciao,
Die Fenster

Man, totally posted this in the wrong forum. Any moderator care to move it to the right one for me? Thank you :slight_smile:

I have seen code similar to what the predisesor of the idea used, which may or may not have looked something like this

That is the bit that is taking the readings from the analogue input connected to the resistor chain and sorting out what button is pressed.
With your wiring you don't need any of this.

You need to read an input pin and then set or clear the appropriate bit in a variable that will later be sent out to the shift registers.
So something like:-
outVlaue = 0;
if(digitalRead(rep1) == HIGH) outValue = outValue | 0x1;
if(digitalRead(rep2) == HIGH) outValue = outValue | 0x2;
if(digitalRead(rep3) == HIGH) outValue = outValue | 0x4;
if(digitalRead(rep4) == HIGH) outValue = outValue | 0x8;
You are using the OR operator | to add logic ones in the bits corresponding to the inputs to the variable outValue.
Then you have to send outValue to your shift register.

Hey, thanks Grumpy Mike!

Ok, so once I set the outValue to a certain value, then I need to convert that using the byte() function, then shift that out? I know this isn't right, but am I going in the right direction?

const int rep1 = 2; //Repeat button 1 to digital pin 2
const int rep2 = 3; //Repeat button 2 to digital pin 3
const int rep3 = 4; //Repeat button 3 to digital pin 4
const int rep4 = 5; //Repeat button 4 to digital pin 5

const int reg1 = 6; //Regeneration button 1 to digital pin 6
const int reg2 = 7; //Regeneration button 1 to digital pin 7
const int reg3 = 8; //Regeneration button 1 to digital pin 8
const int reg4 = 9; //Regeneration button 1 to digital pin 9

int max_clock = 13; //Output clock for max395
int max_data = 12; //Output data for max395
int max_cs = 11; //Output cs for max395

int outValue = 0

void setup () {
pinMode (rep1, INPUT); //Initialize repeat pins as inputs
pinMode (rep2, INPUT);
pinMode (rep3, INPUT);
pinMode (rep4, INPUT);
pinMode (reg1, INPUT); //Initialize regen pins as inputs
pinMode (reg2, INPUT);
pinMode (reg3, INPUT);
pinMode (reg4, INPUT);
pinMode (max_clock, OUTPUT); //Initialize 13,12,11 as outputs
pinMode (max_data, OUTPUT);
pinMode (max_cs, OUTPUT);
}

void loop () {
outVlaue = 0;
if(digitalRead(rep1) == HIGH) outValue = outValue | 0x1;
if(digitalRead(rep2) == HIGH) outValue = outValue | 0x2;
if(digitalRead(rep3) == HIGH) outValue = outValue | 0x4;
if(digitalRead(rep4) == HIGH) outValue = outValue | 0x8;
if(digitalRead(reg1) == HIGH) outValue = outValue | 0x16;
if(digitalRead(reg2) == HIGH) outValue = outValue | 0x32;
if(digitalRead(reg3) == HIGH) outValue = outValue | 0x64;
if(digitalRead(reg4) == HIGH) outValue = outValue | 0x128;

byte(outValue);
digitalWrite(max_cs, LOW);
delay(100);
shiftOut(max_data, max_clock, outValue);
digitalWrite(max_cs, HIGH);
}

Sorry if this is so easy, I'm a little dense when it comes to coding :cry:

Thanks a lot :slight_smile:

Bump for ideas!