The Adafruit MacroPad RP2040 is a versatile and compact mechanical keypad featuring the powerful Raspberry Pi RP2040 microcontroller. With programmable keys and individual RGB backlighting, it is an ideal tool for creating custom macro keyboards, game controllers, and various automation interfaces. Its ease of use and flexibility make it suitable for hobbyists, gamers, and professionals looking to streamline their workflows.
Pin Number | Function | Description |
---|---|---|
1 | GND | Ground |
2 | VBUS | USB input voltage (5V) |
3 | 3V3 | 3.3V output from the onboard voltage regulator |
4-15 | GPIO 0 - GPIO 11 | General Purpose I/O pins for keys and rotary encoder |
16 | SDA | I2C Data line for OLED display and external I2C devices |
17 | SCL | I2C Clock line for OLED display and external I2C devices |
18 | EN | Enable pin for the 3.3V regulator |
Below is an example code snippet for initializing the MacroPad and setting up a simple key press event. This code is intended for use with the Arduino IDE.
#include <Adafruit_Keypad.h>
#include <Adafruit_NeoPixel.h>
// Define the number of keys and LEDs
#define NUM_KEYS 12
#define NUM_LEDS 12
// Create the keypad and LED objects
Adafruit_Keypad keypad = Adafruit_Keypad(makeKeymap(keys), 4, 3, ROWS, COLS);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// Initialize the keypad and LEDs
keypad.begin();
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
// Put your main code here, to run repeatedly:
keypad.tick();
while (keypad.available()) {
keypadEvent e = keypad.read();
// Handle the key press event
if (e.bit.EVENT == KEY_JUST_PRESSED) {
// Example: Light up the corresponding LED when a key is pressed
strip.setPixelColor(e.bit.KEY, strip.Color(100, 0, 0)); // Red color
strip.show();
}
else if (e.bit.EVENT == KEY_JUST_RELEASED) {
// Turn off the LED when the key is released
strip.setPixelColor(e.bit.KEY, strip.Color(0, 0, 0)); // Off
strip.show();
}
}
}
Remember to replace makeKeymap(keys)
, ROWS
, COLS
, and PIN
with the appropriate values for your setup. This code is a basic starting point and can be expanded to include more complex functionality such as handling multiple key presses, custom macros, and dynamic lighting effects.