#include <Keypad.h>
const int analogPin = A0;
const int ledCount = 10;
int ledPins[] = {
2, 3, 4, 5, 6, 7, 8, 9, 10, 11
};
const uint8_t ROWS = 3;
const uint8_t COLS = 3;
char keys[ROWS][COLS] = {
{ '1', '2', '3' },
{ '4', '5', '6' },
{ '7', '8', '9' }
};
uint8_t colPins[COLS] = { 5, 4, 3, 2 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 9, 8, 7, 6 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(9600);
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT);
}
}
void loop() {
char key = keypad.getKey(); // Keypad
int sensorReading = analogRead(analogPin); // Potentiometer
int ledLevel = map(sensorReading, 0, 1023, 0, ledCount); // Potentiometer
for (int thisLed = 0; thisLed < ledCount; thisLed++) { // Potentiometer
if (thisLed < ledLevel) {
digitalWrite(ledPins[thisLed], HIGH);
}
else {
digitalWrite(ledPins[thisLed], LOW);
}
}
if (key != NO_KEY) { // Keypad
Serial.println(key);
}
}