Keypad

The library keypad.cpp contains a small mistake.  It is probably left over code from when it was using a 2D array. I emailed him even if it is only a few extra cycles.  It would be my first contribution to "open source".

version 1.8
author Mark Stanley, Alexander Brevig
contact mstanley@technologist.com, alexanderbrevig@gmail.com
 

/* @file EventSerialKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates using the KeypadEvent.
|| #
*/
#include

const byte ROWS = 4; //four rows
const byte COLS = 3; //four columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {15,13,19,17}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {16,14,18};    //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
byte pin_speaker = 9;
unsigned long temp = 0;

void setup(){
  Serial.begin(9600);
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
  keypad.setDebounceTime(50);
}
 
void loop(){
  char key = keypad.getKey();
 
  if (key != NO_KEY) {
    //Serial.println(key);
  }
}

//take care of some special events
void keypadEvent(KeypadEvent key){
  switch (keypad.getState()){
    case PRESSED:
      switch (key){
        case '#':
          Serial.print("Value: ");
          Serial.println(temp);
          temp = 0;
          tone(pin_speaker, 587, 20);
          break;
        case '*':
          tone(pin_speaker, 698, 20);
          break;
        default:
          tone(pin_speaker, 440, 20);
          temp = (temp * 10) + key - 48;
       }
    break;
    case HOLD:
      switch (key){
        case '*':
        break;
      }
      tone(pin_speaker, 880, 200);

    break;
  }
}



void Keypad::initializePins(){
  for (byte r=0; r
    for (byte c=0; c
      pinMode(columnPins[c],OUTPUT);
      digitalWrite(columnPins[c],HIGH);
    }
    //configure row pin modes and states
    pinMode(rowPins[r],INPUT);
    digitalWrite(rowPins[r],HIGH);
  }
}


void Keypad::initializePins(){
  //configure row & column pin modes and turn on internal pull up resistors

  for (byte r=0; r
    pinMode(rowPins[r],INPUT);
    digitalWrite(rowPins[r],HIGH);
  }

  for (byte c=0; c
    pinMode(columnPins[c],OUTPUT);
    digitalWrite(columnPins[c],HIGH);
  }
}

Dullbits.com

©DullBits.com 2017, All rights reserved and stuff like that...
Now featuring newly broken pages.