#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'FF', '0', '#', 'D'}
};
byte rowPins[ROWS] = {13, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
char user[6]; // assuming user input is 6 characters long
int index = 0;
void setup() {
Serial.begin(9600);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
}
void loop() {
char customKey = customKeypad.getKey();
if (customKey) {
// Store the input from the keypad
user[index] = customKey;
index++;
// Check if user input is complete (6 characters)
if (index >= 6) {
Serial.print("Input: ");
for (int i = 0; i < 6; i++) {
Serial.print(user[i]);
}
Serial.println(); // Print a newline after displaying the input
// Concatenate and print the individual color components
String red = String(user[0]) + String(user[1]);
String green = String(user[2]) + String(user[3]);
String blue = String(user[4]) + String(user[5]);
Serial.print("Red: ");
Serial.print(red);
Serial.print(" Green: ");
Serial.print(green);
Serial.print(" Blue: ");
Serial.println(blue);
// Parse hexadecimal strings to long integers
long redValue = strtol(red.c_str(), NULL, 16);
long greenValue = strtol(green.c_str(), NULL, 16);
long blueValue = strtol(blue.c_str(), NULL, 16);
// Control RGB LEDs
analogWrite(11, redValue);
analogWrite(10, greenValue);
analogWrite(9, blueValue);
// Reset the index for the next input
index = 0;
}
}
}