#include "Adafruit_Keypad.h"
// blauw is etage 0 up and down buttons
// yellow is etage 1
// black is etage 2
#define upBtn 9 // rows
#define downBtn 8 // columns
int curLevel = 0;
const byte ROWS = 4; // four rows
const byte COLS = 4; // eight columns
//define the symbols on the buttons of the keypads
byte trellisKeys[ROWS][COLS] = {
{1, 2, 3, 11},
{4, 5, 6, 11},
{7, 8, 9, 11},
{11, 0, 11, 11}
};
byte rowPins[ROWS] = {22, 23, 24, 25 }; //connect to the row pinouts of the keypad
byte colPins[COLS] = {26, 27, 28 }; //connect to the column pinouts of the keypad
Adafruit_Keypad customKeypad = Adafruit_Keypad( makeKeymap(trellisKeys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(9600);
pinMode(upBtn, INPUT_PULLUP);
pinMode(downBtn, INPUT_PULLUP);
customKeypad.begin();
}
void loop() {
digitalWrite(6, HIGH);
customKeypad.tick();
while(customKeypad.available()){
keypadEvent e = customKeypad.read();
int desiredLevel = (int)e.bit.KEY;
if(e.bit.EVENT == KEY_JUST_PRESSED) {
Serial.print(desiredLevel);
Serial.println(" pressed");
} else if(e.bit.EVENT == KEY_JUST_RELEASED) {
Serial.print("current level is ");
Serial.println(curLevel);
Serial.print("you want to go to ");
Serial.println();
if(curLevel - desiredLevel > 0){
Serial.println("going down");
}else if (curLevel - desiredLevel < 0){
Serial.println("going up");
}else {
Serial.println("same level");
}
turnOffAllLeds();
digitalWrite(curLevel + 40 ,HIGH);
while(!digitalRead(desiredLevel + 2)){
Serial.println("LETS GOOOOOOOO");
}
turnOffAllLeds();
digitalWrite(curLevel + 41, HIGH);
Serial.print("you have arrived at level");
Serial.println( desiredLevel);
curLevel = desiredLevel;
}
}
}
void turnOffAllLeds(){
for(int i; i > 6; i++){
digitalWrite(40+i, LOW);
}
}