#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
//key pad conected to pins 22-28
byte rowPins[ROWS] = {3,2,1,0}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6,5,4}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int timer = 175; // Higher number = longer scan.
int indLED = 175; //This is the delay on the meet in the middle sequence, updated to use an integer function
int var = 0;
//***********************************************************//
// digital Pins Outlets are hooked up to
int thisPin5 =7;
int thisPin6 =8;
int thisPin7 =9;
int thisPin8 = 10;
int thisPin9 = 11;
int thisPin10 = 12;
int thisPin11 =13;
int incomingByte;
//**********************************************************//
void setup()
{
// set digital pins as outputs to switch relays
pinMode(thisPin5, OUTPUT);
pinMode(thisPin6, OUTPUT);
pinMode(thisPin7, OUTPUT);
pinMode(thisPin8, OUTPUT);
pinMode(thisPin9, OUTPUT);
pinMode(thisPin10, OUTPUT);
pinMode(thisPin11, OUTPUT);
//for keypad
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
}
void loop()
{
////////////////////////////////////////////////////////////////////////////
//listen for keypad press
char key = keypad.getKey();
//print key to serial for communicate over serial
if (key)
{
Serial.println(key);
}
}
/////////////////////////////////////////////////////////////////////////////
// Void key events
//take care of some special events
void keypadEvent(KeypadEvent key)
{
switch (keypad.getState())
{
case PRESSED:
switch (key)
{
///////////////////////////////////////////////////////////////////////////////
case '1':
var = 0;
if(var < 10){
// loop from right to left:
for (int thisPin = 7; thisPin < 13; thisPin++) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
}
// loop from left to right:
for (int thisPin = 12; thisPin >= 7; thisPin--) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
var++;
}
}
else
break;
///////////////////////////////////////////////////////////////////////////////
case '2':
break;
///////////////////////////////////////////////////////////////////////////////
}
}
}