The Adafruit NeoKey 1x4 QT is a versatile and compact key switch module that features four individual keys. Each key is equipped with a NeoPixel RGB LED, allowing for customizable color feedback. The module communicates over I2C, making it simple to integrate into projects with limited GPIO availability. It also includes STEMMA QT connectors for quick and solderless connections. This component is ideal for creating custom keyboards, input devices, or interactive projects that require user input with visual feedback.
Common applications include:
Pin Number | Name | Description |
---|---|---|
1 | VCC | Power supply (3.3V to 5V) |
2 | GND | Ground connection |
3 | SDA | I2C Data Line |
4 | SCL | I2C Clock Line |
5-8 | K1-K4 | Key inputs (not directly accessible, used internally) |
#include <Wire.h>
#include <Adafruit_NeoPixel.h>
#include <Adafruit_NeoKey_1x4.h>
// Define the I2C address for the NeoKey 1x4
#define NEOKEY_I2C_ADDRESS 0x30
// Create the NeoKey object
Adafruit_NeoKey_1x4 neokey = Adafruit_NeoKey_1x4();
void setup() {
// Initialize serial communication for debugging
Serial.begin(9600);
// Initialize the NeoKey 1x4
if (!neokey.begin(NEOKEY_I2C_ADDRESS)) {
Serial.println("Failed to find NeoKey, check wiring!");
while (1) delay(10);
}
}
void loop() {
// Read the key states
uint8_t keyState = neokey.read();
// Check each key and set the color accordingly
for (int i = 0; i < 4; i++) {
if (keyState & (1 << i)) {
// If key is pressed, set to red
neokey.setPixelColor(i, 255, 0, 0);
} else {
// If key is not pressed, set to green
neokey.setPixelColor(i, 0, 255, 0);
}
}
// Update the NeoPixels
neokey.show();
// Small delay to debounce
delay(10);
}
Wire
library's Wire.setClock()
function to lower the I2C clock speed if experiencing communication issues.Q: Can I use the NeoKey 1x4 with a 3.3V microcontroller? A: Yes, the NeoKey 1x4 is compatible with both 3.3V and 5V logic levels.
Q: How do I chain multiple NeoKey 1x4 modules together? A: Connect the STEMMA QT connectors from one module to the next, ensuring that each module has a unique I2C address.
Q: What type of key switches can I use with the NeoKey 1x4? A: The NeoKey 1x4 is designed to be compatible with Cherry MX style mechanical key switches.
Q: How do I change the color of the NeoPixels?
A: Use the neokey.setPixelColor(index, red, green, blue)
function, where index
is the key number (0-3) and red
, green
, blue
are the color values (0-255).