// This sketch needs to be adapted (change serial port config in setup())// to be used on a non-Mega, so check the board here so people notice./*#if !defined(__AVR_ATmega1280__)#error "This example is for the Mega, because it uses Serial3 for the iPod and Serial for debug messages"#endif*/

const byte BUTTON_PIN = 9;const unsigned long DEBOUNCE_MS = 50;

Bounce button(BUTTON_PIN, DEBOUNCE_MS);AdvancedRemote advancedRemote;

unsigned long chosenSongIndexIntoPlaylist;

//// our handler (aka callback) implementations;// these are what get sent data back from the iPod// when we make requests of it.//

switch (cmd) { case AdvancedRemote::CMD_SWITCH_TO_ITEM: Serial.println("(Presumably) now at the playlist zero (the main one)"); Serial.println("Asking for song count"); advancedRemote.getSongCountInCurrentPlaylist(); // wait for our song count handler to get called now break;

case AdvancedRemote::CMD_JUMP_TO_SONG_IN_CURRENT_PLAYLIST: Serial.println("Jumped to our song"); Serial.println("Asking for title"); advancedRemote.getTitle(chosenSongIndexIntoPlaylist); // wait for title handler to get called now break;

Serial.println("Turning on polling (which also seems to make it start playing"); advancedRemote.setPollingMode(AdvancedRemote::POLLING_START); Serial.println("The button will let you do play/pause now. Reset Arduino to go back to normal mode");}