74hc595 buttons

i have a button matrix (2x8) the 8 rows are connected to a shift register (74hc595) and the 2 collums to pin 2 and 3 so the can read the value as an input (pull down), so I send values to the shift register one at a time, than read the pins and than to the next value. the values are in bit (128 = 10000000), read 2 and 3,if they are HIGH then a button is pressed and they do an action. Than send 64(=01000000) and read 2 and 3 but my code doesn't work at all anybody any idea how to make a code for this?

Welcome to the Forum. We need to see your code. Please read the two posts How to use this forum - please read. and Read this before posting a programming question ...

at the top of this Forum on guidelines for posting here, especially the use of code tags which make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons.

Many questions can be answered by simply reading the documentation which is provided with the IDE, available under the help tab, or online here.

There are many other things that programmers do to make their code understandable. Please do them, as a courtesy to the members who volunteer their time to help you here. One is to use a standard indentation to clearly show the code blocks. So before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read. Another is to give things descriptive names. You can name numerical constants, pin numbers, variables and many other things in this way. For example, you can refer to a pin and an output level by number, like digitalWrite(3,0). But such a statement doesn't reveal anything about the purpose. digitalWrite(hornRelayPin, LOW) does. You can do that by declaring const byte hornRelayPin = 3; before setup() in your program. Many such names are already defined for you by the compiler and the Arduino IDE. Here are some:

#define HIGH 0x1
#define LOW  0x0
#define PI 3.1415926535897932384626433832795

Use them. There are many more. Use compiler math to compute values so you can see where they came from (or at least document them). For example, if you see the number 73, you would be hard put to explain the significance of it. But if you see "daysPerYear/5", it is obvious. One more thing. When you work on program continuously, you become familiar with it. So many things seem obvious even if they are not spelled out explicitly. But try looking at your own code six months later. It will be as if a stranger wrote it. So write for strangers, not yourself.

int latchPin = 6;
int clockPin = 9;
int dataPin = 7;
int button0 = 2;
int xOld0 = 0;
int x0 = 0;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(button0, INPUT);
}

int value[] = {128, 64, 32, 16, 8, 4, 2, 1}; //128=10000000, 64=01000000 etc

void loop() {
  for(int y=0;y<8;y++){
 digitalWrite(latchPin, LOW);
 shiftOut(dataPin, clockPin, MSBFIRST, value[y]);        //128 = 10000000
 digitalWrite(latchPin, HIGH);
 
 x0 = digitalRead(button0);
       Serial.println(y);
 if (x0 == HIGH && xOld0 == LOW) {
      Serial.println("on");
      xOld0 = x0;}
 if (x0 == LOW && xOld0 == HIGH) {
      Serial.println("off");
      xOld0 = x0;}
 delay(10);}
}

Thank you. What is wrong? I do see that you are not saving state information for every key.

Yeah, that is the problem, if I knew that I wouldn’t ask :wink:

kayakkie87: Yeah, that is the problem, if I knew that I wouldn't ask ;)

You could create an array to hold the states, index it in the same way that you index the column enables. Substitute that for your "x0" variable.