This is sample code to drive the Sparkfun Button Pad 2x2 from an Arduino.
It lights up the LEDs different colors each time you press it.
You will need:
- Button Pad
- Button Pad 2x2 (silicone pad): Sparkfun || Little Bird
- Button Pad 2x2 PDB: Sparkfun || Little Bird
- RGB LEDs (Common Cathode): Sparkfun || Little Bird
- Diodes 1N4148: DX
- Top bezel: Sparkfun || Little Bird
- Right angle pin headers: Little Bird
- On the breadboard
- Wires: DX
- What you get for this depends on your use case, but I used these to plug into my breadboard.
To drive the LEDs we are going to use PWM/AnalogWrite to drive the common pin on each LED, then cycle through each color one at a time. You need to put the resistors where it will not be supplying current for more than one LED at a time, so we put it on the common pins of each LED.
For reading the buttons, I used the Keypad library. It handles all the debouncing and pin IO for you, which is handy.
PCB Label | Arduino Pin |
---|---|
SWITCH | A0 |
SWT-GND1 | A1 |
SWT-GND2 | A2 |
SWT-GND3 | A3 |
SWT-GND4 | A4 |
LED-GND1 | 3 |
LED-GND2 | 5 |
LED-GND3 | 6 |
LED-GND4 | 9 |
RED | 4 |
GREEN | 7 |
BLUE | 8 |