#include <Keypad.h>
#include <FastLED.h>
using namespace std;
#define nl 16
CRGB leds[nl]; // Array to control LEDs
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = { // Keypad layout
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[COLS] = { 5, 6, 7, 8 };
uint8_t rowPins[ROWS] = { 1, 2, 3, 4 };
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS); // Setting up the Keypad
String curN;
// Room numbers and their corresponding LED positions
int ucilnice[] = {323, 341, 331, 332,"A1"}; // Mixed data type might cause issues
int ledPos[] = {1, 2, 3, 4,10};
void setup() {
Serial.begin(9600); // Initialize Serial communication
FastLED.addLeds<NEOPIXEL, 9>(leds, nl); // Initialize LED strip
}
// Function to find LED position for a given room number
int dispLed(int selected) {
for (size_t i = 0; i < sizeof(ucilnice) / sizeof(ucilnice[0]); ++i) {
if (ucilnice[i] == selected) {
Serial.println("Works");
return ledPos[i]; // Return the LED position
}
}
return -1; // If the room number is not found
}
int curLed = 0;
int prevLed;
void loop() {
char key = keypad.getKey(); // Get the pressed key from the keypad
if (key != NO_KEY) {
if (curN.length() >= 3) {
curN = curN.substring(1); // Remove first character if the length is already 3
}
curN += key; // Add the pressed key to the current number
Serial.println(curN); // Print the current number to Serial monitor
// Get LED position for the current number
curLed = dispLed(curN.toInt());
if (curLed != -1) {
leds[curLed] = CRGB::Red; // Turn on the corresponding LED in red
FastLED.show(); // Show changes in the LED strip
if (prevLed != curLed){
leds[prevLed] = CRGB::Black; // Turn off the previously lit LED
}
FastLED.show(); // Show changes in the LED strip
delay(30); // Delay for stability
prevLed = curLed; // Update the previously lit LED
}
}
}