#include <Keypad.h>
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {2, 3, 4, 5}; // Connect to the row pinouts of the keypad
byte colPins[COLS] = {6, 7, 8, 9}; // Connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
const int ledPin = 9; // the pin number for the LED
const int ledPin1 = 8; // the pin number for the LED
const int ledPin2 = 7; // the pin number for the LED
const int ledPin3 = 6; // the pin number for the LED
const int ledPin4 = 5; // the pin number for the LED
const int ledPin5 = 4; // the pin number for the LED
const int ledPin6 = 3; // the pin number for the LED
const int ledPin7 = 2; // the pin number for the LED
//bool ledState = LOW; // current state of the LED
unsigned long buttonPressTime = 0; // time when the button was pressed
unsigned long buttonPressTime1 = 0; // time when the button was pressed
unsigned long buttonPressTime2 = 0; // time when the button was pressed
unsigned long buttonPressTime3 = 0; // time when the button was pressed
const long interval = 600; // duration to keep the LED on (milliseconds)
const long interval1 = 800; // duration to keep the LED on (milliseconds)
const long interval2 = 1000; // duration to keep the LED on (milliseconds)
const long interval3 = 1200; // duration to keep the LED on (milliseconds)
void setup() {
//pinMode(ledPin, OUTPUT); // initialize the LED pin as an output
/*pinMode(ledPin1, OUTPUT); // initialize the LED pin as an output
pinMode(ledPin2, OUTPUT); // initialize the LED pin as an output
pinMode(ledPin3, OUTPUT); // initialize the LED pin as an output
pinMode(ledPin4, OUTPUT); // initialize the LED pin as an output
pinMode(ledPin5, OUTPUT); // initialize the LED pin as an output
pinMode(ledPin6, OUTPUT); // initialize the LED pin as an output
pinMode(ledPin7, OUTPUT); // initialize the LED pin as an output*/
}
void loop() {
char key = keypad.getKey(); // Check for a keypress
////////////////////////////////////////////////////////////////////////////////////////////
// LF UP
if ( key == '1' != NO_KEY) { // If a key is pressed
// Check if the LED should be on based on the button press time
digitalWrite(ledPin, HIGH); // Turn on the LED
} else {
digitalWrite(ledPin, LOW); // Turn off the LED
}
/*//////////////////////////////////////////////////////////////////////////////////////////
// LF & RF UP
if ( key == '2' != NO_KEY) { // If a key is pressed
// Check if the LED should be on based on the button press time
digitalWrite(ledPin, LOW); // Turn on the LED
digitalWrite(ledPin1, LOW); // Turn on the LED
} else {
digitalWrite(ledPin, HIGH); // Turn off the LED
digitalWrite(ledPin1, HIGH); // Turn off the LED
}
/////////////////////////////////////////////////////////////////////////////////////////
// RF UP
if ( key == '3' != NO_KEY) { // If a key is pressed
// Check if the LED should be on based on the button press time
digitalWrite(ledPin1, LOW); // Turn on the LED
} else {
digitalWrite(ledPin1, HIGH); // Turn off the LED
}
/////////////////////////////////////////////////////////////////////////////////////////
// LF DOWN
if ( key == '4' != NO_KEY) { // If a key is pressed
// Check if the LED should be on based on the button press time
digitalWrite(ledPin2, LOW); // Turn on the LED
} else {
digitalWrite(ledPin2, HIGH); // Turn off the LED
}
/////////////////////////////////////////////////////////////////////////////////////////
// LF & RF DOWN
if ( key == '5' != NO_KEY) { // If a key is pressed
// Check if the LED should be on based on the button press time
digitalWrite(ledPin2, LOW); // Turn on the LED
digitalWrite(ledPin3, LOW); // Turn on the LED
} else {
digitalWrite(ledPin2, HIGH); // Turn off the LED
digitalWrite(ledPin3, HIGH); // Turn off the LED
}
/////////////////////////////////////////////////////////////////////////////////////////
// RF DOWN
if ( key == '6' != NO_KEY) { // If a key is pressed
// Check if the LED should be on based on the button press time
digitalWrite(ledPin3, LOW); // Turn on the LED
} else {
digitalWrite(ledPin3, HIGH); // Turn off the LED
}
/////////////////////////////////////////////////////////////////////////////////////////
// LR UP
if ( key == '7' != NO_KEY) { // If a key is pressed
// Check if the LED should be on based on the button press time
digitalWrite(ledPin4, LOW); // Turn on the LED
} else {
digitalWrite(ledPin4, HIGH); // Turn off the LED
}
/////////////////////////////////////////////////////////////////////////////////////////
// LR & RR UP
if ( key == '8' != NO_KEY) { // If a key is pressed
// Check if the LED should be on based on the button press time
digitalWrite(ledPin4, LOW); // Turn on the LED
digitalWrite(ledPin5, LOW); // Turn on the LED
} else {
digitalWrite(ledPin4, HIGH); // Turn off the LED
digitalWrite(ledPin5, HIGH); // Turn off the LED
}
/////////////////////////////////////////////////////////////////////////////////////////
// RR UP
if ( key == '9' != NO_KEY) { // If a key is pressed
// Check if the LED should be on based on the button press time
digitalWrite(ledPin5, LOW); // Turn on the LED
} else {
digitalWrite(ledPin5, HIGH); // Turn off the LED
}
/////////////////////////////////////////////////////////////////////////////////////////
// LR DOWN
if ( key == '*' != NO_KEY) { // If a key is pressed
// Check if the LED should be on based on the button press time
digitalWrite(ledPin6, LOW); // Turn on the LED
} else {
digitalWrite(ledPin6, HIGH); // Turn off the LED
}
//////////////////////////////////////////////////////////////////////////////////////////
// LR & RR DOWN
if ( key == '0' != NO_KEY) { // If a key is pressed
// Check if the LED should be on based on the button press time
digitalWrite(ledPin6, LOW); // Turn on the LED
digitalWrite(ledPin7, LOW); // Turn on the LED
} else {
digitalWrite(ledPin6, HIGH); // Turn off the LED
digitalWrite(ledPin7, HIGH); // Turn off the LED
}
/////////////////////////////////////////////////////////////////////////////////////////
// RR DOWN
if ( key == '#' != NO_KEY) { // If a key is pressed
// Check if the LED should be on based on the button press time
digitalWrite(ledPin7, LOW); // Turn on the LED
} else {
digitalWrite(ledPin7, HIGH); // Turn off the LED
}*/
/*//////////////////////////////////////////////////////////////////////////////////////////
// STANDARD HEIGHT
if ( key == 'A' != NO_KEY) { // If a key is pressed
buttonPressTime = millis(); // Record the time when the button was pressed
}
// Check if the LED should be on based on the button press time
if (millis() - buttonPressTime <= interval) {
digitalWrite(ledPin, HIGH); // Turn on the LED
digitalWrite(ledPin1, HIGH); // Turn on the LED
digitalWrite(ledPin4, HIGH); // Turn on the LED
digitalWrite(ledPin5, HIGH); // Turn on the LED
} else {
digitalWrite(ledPin, LOW); // Turn off the LED
digitalWrite(ledPin1, LOW); // Turn off the LED
digitalWrite(ledPin4, LOW); // Turn off the LED
digitalWrite(ledPin5, LOW); // Turn off the LED
}
/////////////////////////////////////////////////////////////////////////////////////////
// DAILY HEIGHT
if ( key == 'B' != NO_KEY) { // If a key is pressed
buttonPressTime2 = millis(); // Record the time when the button was pressed
}
// Check if the LED should be on based on the button press time
if (millis() - buttonPressTime1 <= interval1) {
digitalWrite(ledPin, HIGH); // Turn on the LED
digitalWrite(ledPin1, HIGH); // Turn on the LED
digitalWrite(ledPin4, HIGH); // Turn on the LED
digitalWrite(ledPin5, HIGH); // Turn on the LED
} else {
digitalWrite(ledPin, LOW); // Turn off the LED
digitalWrite(ledPin1, LOW); // Turn off the LED
digitalWrite(ledPin4, LOW); // Turn off the LED
digitalWrite(ledPin5, LOW); // Turn off the LED
}
/////////////////////////////////////////////////////////////////////////////////////////
// CRUIZING HEIGHT
if ( key == 'C' != NO_KEY) { // If a key is pressed
buttonPressTime2 = millis(); // Record the time when the button was pressed
}
// Check if the LED should be on based on the button press time
if (millis() - buttonPressTime2 <= interval2) {
digitalWrite(ledPin, HIGH); // Turn on the LED
digitalWrite(ledPin1, HIGH); // Turn on the LED
digitalWrite(ledPin4, HIGH); // Turn on the LED
digitalWrite(ledPin5, HIGH); // Turn on the LED
} else {
digitalWrite(ledPin, LOW); // Turn off the LED
digitalWrite(ledPin1, LOW); // Turn off the LED
digitalWrite(ledPin4, LOW); // Turn off the LED
digitalWrite(ledPin5, LOW); // Turn off the LED
}
/////////////////////////////////////////////////////////////////////////////////////////
// AIR OUT
if ( key == 'D' != NO_KEY) { // If a key is pressed
buttonPressTime3 = millis(); // Record the time when the button was pressed
}
// Check if the LED should be on based on the button press time
if (millis() - buttonPressTime3 <= interval3) {
digitalWrite(ledPin2, HIGH); // Turn on the LED
digitalWrite(ledPin3, HIGH); // Turn on the LED
digitalWrite(ledPin6, HIGH); // Turn on the LED
digitalWrite(ledPin7, HIGH); // Turn on the LED
} else {
digitalWrite(ledPin2, LOW); // Turn off the LED
digitalWrite(ledPin3, LOW); // Turn off the LED
digitalWrite(ledPin6, LOW); // Turn off the LED
digitalWrite(ledPin7, LOW); // Turn off the LED
}*/
/////////////////////////////////////////////////////////////////////////////////////////
}