#include <Keypad.h>
#include <Adafruit_NeoPixel.h>
const byte COLS = 4; //four columns
const byte ROWS = 4; //four rows
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
#define PIN 16 // Define the pin where the data line is connected
#define NUMPIXELS 16 // Number of LEDs in the NeoPixel ring
Adafruit_NeoPixel ring = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
uint16_t currentHue = 200; // Initial hue value (blue)
uint8_t currentSaturation = 255; // Full saturation
bool isBreathing = false;
void setup() {
Serial.begin(9600);
ring.begin(); // Initialize the NeoPixel ring
ring.show(); // Initialize all pixels to 'off'
}
void loop() {
char key = keypad.getKey();
if (key) {
Serial.println(key);
switch(key) {
case '1':
Serial.println("Key 1 pressed");
currentHue = 200; // Blue
isBreathing = true;
break;
case '4':
Serial.println("Key 4 pressed");
currentHue = random(20, 50); // Random orange/yellow
isBreathing = true;
break;
case '7':
Serial.println("Key 7 pressed");
currentHue = 21845; // Green (1/3 of 65535)
isBreathing = true;
break;
case '*':
Serial.println("Key * pressed");
isBreathing = false;
setColor(ring.Color(0, 0, 0)); // Turn off the light
ring.show();
break;
}
}
if (isBreathing) {
breathe(currentHue, currentSaturation, 255, 20);
}
}
void breathe(uint16_t hue, uint8_t saturation, uint8_t maxBrightness, int delayTime) {
// Gradually increase brightness:
for (int brightness = 0; brightness <= maxBrightness; brightness++) {
setColor(ring.ColorHSV(hue, saturation, brightness)); // Set color with variable brightness
ring.show();
delay(delayTime);
}
// Gradually decrease brightness:
for (int brightness = maxBrightness; brightness >= 0; brightness--) {
setColor(ring.ColorHSV(hue, saturation, brightness));
ring.show();
delay(delayTime);
}
}
// Helper function to set the color of all pixels
void setColor(uint32_t color) {
for (int i = 0; i < ring.numPixels(); i++) {
ring.setPixelColor(i, color);
}
}