Relay "Poly-function"

Hi Arduino community,

Very new to Arduino and programming in general. This is one of my first micro controller projects and any help or advice would be greatly appreciated.

Working on a project using a Mega 2560, Adafruit MPR121 touch sensor and the Sparkfun wav trigger to make a 12 note polyphonic touch keyboard. Now just need to add the same “poly function” to 12 relays, so that when one of the keys is touched it plays a note and turns on a light. The key functionality would be that multiple lights and notes can be activated simultaneously. Is there a board out there that does what the WAV trigger does, but instead of triggering a wav file it triggers a relay and can trigger multiple relays simultaneously?

So far have been able to get the code to trigger the relays, but every key just triggers the same relay…

#include <Wire.h>
#include "Adafruit_MPR121.h"

Adafruit_MPR121 cap = Adafruit_MPR121();

uint16_t lasttouched = 0;
uint16_t currtouched = 0;

int pins[] = {52,53};

void setup() {

pinMode(52, OUTPUT);
pinMode(53, OUTPUT);

if (!cap.begin(0x5A)) {

  while (1);


void loop() {
currtouched = cap.touched();

for (uint8_t i=0; i<12; i++) {
  if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
     digitalWrite(52, LOW);
  if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {

   digitalWrite(52, HIGH);


lasttouched = currtouched;



but every key just triggers the same relay...

Yes because that is what you have written it to do.
You are only ever triggering output 52.

Basically that statement needs to say something like

digitalWrite(52+i, LOW);

Assuming you have initialised all those pins as outputs and you have 64 pins. But you get the idea. Make the fixed number the lowest of your relay pins.

That worked and all 12 relays can be activated simultaneously