#define triggerCodeChannels 3 //declaring that there are three input leads encoding a signal #define padCount 8 int padPins[] = { A0, A1, A2, A3, A4, A5, A6, A7}; // inputs from the pads #define padCount 8 int potPins[] = { A8, A9, A10, A11, A12, A13, A14, A15}; //inputs from the calibration potentiometers int threshLow = 170; //lowest possible value from potentiometer output int threshHigh = 1024; //highest possible value from pot output (1024 = 5V) int debounceDelay = 10; //ms delay between readings of the pads to check that the signal is real int padReadDelay = 150; //ms delay between loops, to see if anyone has stepped on a new pad int testInputPins[] = { 2, 3, 4, 5, 6, 7, 8, 9}; int musicControlPins[][triggerCodeChannels] = {{22, 23, 24}, {26, 27, 28}, {30, 31, 32}, {34, 35, 36}, {38, 39, 40}, {2, 3, 4}, {46, 47, 48}, {50, 51, 52} }; int musicControlSignal[8][3]; int tiles[padCount]; //this variable is where the raw input from the pad goes int thresholds[padCount]; //the raw input from the calibration pot goes here int padsTriggered[padCount]; //this is going to hold a boolean (on/off) for which pads are stepped on int padsTriggeredRaw1[padCount]; int padsTriggeredRaw2[padCount]; int padsTriggered_Historical[padCount] = {0,0,0,0,0,0,0,0}; int padsTriggered_New[padCount]; int padConditions[][padCount+1] = {{1, 0, 0, 0, 0, 0, 0, 0, 1}, //pad 1 has been stepped on = situation 1 {0, 1, 0, 0, 0, 0, 0, 0, 1}, //pad 2 has been stepped on = situation 1 {0, 0, 1, 0, 0, 0, 0, 0, 1}, //etc... {0, 0, 0, 1, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 1, 0, 0, 0, 1}, {0, 0, 0, 0, 0, 1, 0, 0, 1}, {0, 0, 0, 0, 0, 0, 1, 0, 1}, {0, 0, 0, 0, 0, 0, 0, 1, 1}, {1, 0, 1, 0, 1, 0, 1, 0, 2}, // odd pads = situation 2 (only odd pads play) {0, 1, 0, 1, 0, 1, 0, 1, 2}, // even pads = situation 2 (only even pads play) {1, 1, 1, 1, 1, 1, 1, 1, 4}}; //ALL pads stepped on = situation 4 int numberOfConditions = 12; //IMPORTANT - update 'numberOfConditions' //if you add more rows to 'padConditions'. int situationNumber; int situationNumberNew; int musicSituationCodes[][triggerCodeChannels] = { {0, 0, 0}, //no music {0, 0, 1}, //situation 1 {0, 1, 0}, //situation 2 {0, 1, 1}, //situation 3 {1, 0, 0}, //situation 4 {1, 0, 1}, //etc... {1, 1, 0}, {1, 1, 1}}; //for any given 'situation' trigger, the bare conductive then is able to play the appropriate //mp3 track, or can cycle through a number of tracks allocated to that trigger. void setup() { //DECLARING INPUTS AND OUTPUTS for (int i = 0; i < padCount; i++) { pinMode(testInputPins[i], INPUT_PULLUP); for (int j = 0; j < triggerCodeChannels; j++) { pinMode(musicControlPins[i][j], OUTPUT); } } Serial.begin(9600); } void loop() { //PART 1: READING THE PADS AND CREATING THE padsTriggered ARRAY // first the board cycles through the pins to read both tile signals and thresholds //PART 1: READING THE PADS AND CREATING THE padsTriggered ARRAY // first the board cycles through the pins to read both tile signals and thresholds for (int i = 0; i < padCount; i++) { // read button state tiles[i] = analogRead(padPins[i]); thresholds[i] = map(analogRead(padPins[i]), threshLow, threshHigh, 0, 1024); if (tiles[i]> thresholds[i]){ padsTriggeredRaw1[i] = 1; } else { padsTriggeredRaw1[i] = 0; } } // after a short delay, the board does the same thing again, to debounce the signal // (ie checks that the tiles have really been stepped on and it's not // just some random electrical noise) delay(debounceDelay); for (int i = 0; i < padCount; i++) { // read tile & pot state tiles[i] = analogRead(padPins[i]); thresholds[i] = map(analogRead(padPins[i]), threshLow, threshHigh, 0, 1024); if (tiles[i] > thresholds[i]){ padsTriggeredRaw2[i] = 1; } else { padsTriggeredRaw2[i] = 0; } // This bit checks to see that the signal is still the same after the delay // and decides that, if it is, it's real. if (padsTriggeredRaw1[i] == 1 && padsTriggeredRaw2 ==1){ padsTriggered[i]=1; } else {padsTriggered[i] = 0;} } // // so now we have the padsTriggered array consisting of eight 1's and 0's // (1 if that pad has been stepped on and 0 if it hasn't). // Now we need to figure out if anyone has recently stepped on a pad. // //Verbose outputs Serial.print("SWITCH STATES "); //Verbose outputs for(int i = 0; i < padCount; i++) { Serial.print(padsTriggered[i]); } Serial.print(" "); //PART 2: WHO'S STEPPING ON NEW PADS?? // // This section compares the signal now to the signal 0.1 seconds ago, so if // anyone has stepped on a new pad, we have a 'New' variable which can tell us. for (int i = 0; i situationNumber){ newTriggers = true; situationNumber = situationNumberNew; } else{ newTriggers = false; } //Verbose outputs Serial.print("Situation: "); Serial.print(situationNumber); ////PART 4 - sending the music signal. // Create the musicControlSignal array corresponding to that music situation. // (this is the array of 3-digit signals that would go to all the Touchboards) // // So we need to do the following: // - look up the signal code for this Situation Number, // - then copy this signal code into musicControlSignal - but ONLY for those // boards that have been stepped on. // - if we're using a 'new' trigger then only play the new sound on that touchboard. // (making sure we use the right 'trigger' conditions - new/old)... // Fill in the elements of musicControlSignal array by multiplying // the eight members of padsTriggered (1 or 0), with the three digit code for this situation. // -- This means signals only go to the pad or pads that are stepped on right now. if(newTriggers){ for (int a = 0; a < padCount; a++) { for (int b = 0; b < triggerCodeChannels; b++) { musicControlSignal[a][b] = padsTriggered_New[a] * musicSituationCodes[situationNumber][b]; } } } else { for (int a = 0; a < padCount; a++) { for (int b = 0; b < triggerCodeChannels; b++) { musicControlSignal[a][b] = padsTriggered[a] * musicSituationCodes[situationNumber][b]; } } } // write the music control signal to the output pins for (int i = 0; i < padCount; i++) { for (int j = 0; j < triggerCodeChannels; j++){ digitalWrite(musicControlPins[i][j], musicControlSignal[i][j]); } } //Verbose outputs (loop and line return) Serial.print(" code for pad 1: "); for (int i = 0; i < triggerCodeChannels; i ++){ Serial.print(musicControlSignal[0][i]); } Serial.println(" "); // Pause current state so the touchboards can listen for // the signal (and start playing the music). delay(padReadDelay); // Finally, update padsTriggered_Historical so you can compare new/old next time. for (int i = 0; i