Unless I made a mistake, this should do what you want using the RCSwitch library:
#include <RCSwitch.h>
#define maxStates 3 //change this and the number of strings (char*) below to match the total number of codes you want to decipher.
byte state = 0; //variable to keep track of the states
char* prompts[]={"Press Light Toggle: ", "Press Fan Toggle: ", "Press next button name"}; //Serial strings for the various prompts
char* codes[]={"Light Toggle: ", "Fan Toggle: ", "Next button code: "}; //Serial strings for the names of the codes
RCSwitch mySwitch = RCSwitch(); //Make an instance of the RCSwitch library
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
Serial.println(prompts[state]); //This will print the first prompt in the array of prompts to get things started
}
void loop() {
if (mySwitch.available()) { //This code only runs when a button was decoded
int value = mySwitch.getReceivedValue();
if (value == 0) { //Something was seen, but the code couldn't decode it
Serial.print("Unknown encoding");
}
else { //Or a valid code was found
Serial.print(codes[state]); //Displays the name of the code based on the state
Serial.print( mySwitch.getReceivedValue() );
Serial.print(" / ");
Serial.print( mySwitch.getReceivedBitlength() );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.println( mySwitch.getReceivedProtocol() );
Serial.println(" ");
state++; //increment to the next state
if(state > maxStates) state = 0; //reset the state counter if we reach the maximum step
Serial.println(prompts[state]); //prints the next prompt. Starts back at the beginning if max was exceeded.
}
mySwitch.resetAvailable(); //reset the "available" flag after getting a code
}
}