Skip to main content
Commonmark migration
Source Link

I have a keypad like this: [![][1]][1]

[here][2]here is another, closer look at the bottom part.

m+1, m+4 & m+7 is because m is my columns so if I press 0 and the row is 0 then I add 1, same goes with everything else. Can anyone help me? [1]: https://i.sstatic.net/QcMwH.png [2]: https://i.sstatic.net/rUwS5.png

I have a keypad like this: [![][1]][1]

[here][2] is another, closer look at the bottom part.

m+1, m+4 & m+7 is because m is my columns so if I press 0 and the row is 0 then I add 1, same goes with everything else. Can anyone help me? [1]: https://i.sstatic.net/QcMwH.png [2]: https://i.sstatic.net/rUwS5.png

I have a keypad like this:

here is another, closer look at the bottom part.

m+1, m+4 & m+7 is because m is my columns so if I press 0 and the row is 0 then I add 1, same goes with everything else. Can anyone help me?

Bumped by Community user
Source Link

Keypad giving random inputs

I have a keypad like this: [![][1]][1]

[here][2] is another, closer look at the bottom part.

Basically, I want the LED to power the amount that I pressed.

this is my code:

int LED = 1;
int inputs[4] {
  6,
  4,
  2,
  0
};
int outputs[4] {
  13,
  12,
  10,
  8
};
void outputAllBut(short int);
int numberInputCheck();
int inputCheck();

void setup() {
  for (int i = 0; i < 4; i++) {
    pinMode(outputs[i], OUTPUT);
    pinMode(inputs[i], INPUT_PULLUP);
  }
  pinMode(LED, OUTPUT);
}

void loop() {
  while (true) {
    int x = numberInputCheck();

    if (x == 500) {
      break;
    }

    delay(500);

    for (int i = 0; i < x; i++) {
      digitalWrite(LED, HIGH);
      delay(500);
      digitalWrite(LED, LOW);
      delay(300);
    }
  }
}

int numberInputCheck() {
  while (true) {
    for (int i = 0; i < 4; i++) {
      outputAllBut(i);
      for (int m = 0; m < 4; m++) {
        if (digitalRead(inputs[m]) == LOW) {
          switch (i) {
          case 0:
            if (m == 3) {
              return 500;
            } else {
              return m + 7;
            }
          case 1:
            if (m == 3) {
              return 500;
            } else {
              return m + 4;
            }
          case 2:
            if (m == 3) {
              return 500;
            } else {
              return m + 1;
            }
          case 3:
            return 500;
          }
        }
      }
    }
  }
}

void outputAllBut(short int b) {
  for (int i = 0; i < 4; i++) {
    if (i != b) {
      digitalWrite(outputs[i], HIGH);
    }
  }
}

int inputCheck() {
  for (int i = 0; i < 4; i++) {
    if (digitalRead(inputs[i]) == LOW) {
      return i;
    }
  }
  return 5;
}

for reference, the numberInputCheck function is the one that might go wrong here, I want it to wait for an input and return the number that I pressed. i is the rows and m is the columns. My problem is that whenever I press the keypad at one of the numbers, it will give me a random amount of times that the LED turns on, there doesn't seem to be any pattern.

m+1, m+4 & m+7 is because m is my columns so if I press 0 and the row is 0 then I add 1, same goes with everything else. Can anyone help me? [1]: https://i.sstatic.net/QcMwH.png [2]: https://i.sstatic.net/rUwS5.png