Send signal to multiple pins in sequence

Is there a way to send a signal to 2 different pins with one cap touch button in a sequence? For instance if the first sensor is touched, can that be programmed to send a signal to pins 20 and 40 and the next sensor to 21/41 and so on?

``````#include <Wire.h>

uint16_t lasttouched = 0;
uint16_t currtouched = 0;

int pins[] = {(20,40)(21,41)(22,42)(23,43)};

void setup() {

pinMode(20, OUTPUT);
pinMode(21, OUTPUT);
pinMode(22, OUTPUT);
pinMode(23, OUTPUT);

pinMode(40, OUTPUT);
pinMode(41, OUTPUT);
pinMode(42, OUTPUT);
pinMode(43, 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(20+i, LOW);

}
if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {

digitalWrite(20+i, HIGH);

}
}

lasttouched = currtouched;
}
``````

Please edit your post to include [ code ] tags. The forum software might eat some of your code.

Of course you can make a sequence. You just have to write down what the sequence is. Then decide on what makes it move from one state to the next. For example, the first state waits until the sensor is touched. Then the second state might light an output and wait for a number of milliseconds. What happens if the sensor is touched again while in the second state? What happens if it is held continuously?

When it has done the sequence, does it go back to the beginning or does it 'remember' that it did it once and the next sequence will be different? That would indicate that there's several 'wait' states, which go to different sequences. Basically make one very long sequence with several different waits.

I notice that you made a pins[] array. But you never use it? I don't know what the brackets do in that array definition - I've never written an array that way. You probably don't need them.