Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*******************************************************************************
- Bare Conductive Touch MP3 player for the Interactive Wall Kit
- -------------------------------------------------------------
- https://github.com/BareConductive/touch_mp3_iwk
- Touch_MP3_IWK.ino - touch triggered MP3 playback
- This is a slightly modified version of the Touch_MP3.ino
- You need twelve MP3 files named TRACK000.mp3 to TRACK011.mp3 in the root of the
- microSD card.
- When you touch electrode E0, TRACK000.mp3 will play. When you touch electrode
- E1, TRACK001.mp3 will play, and so on.
- SD card
- │
- TRACK000.mp3
- TRACK001.mp3
- TRACK002.mp3
- TRACK003.mp3
- TRACK004.mp3
- TRACK005.mp3
- TRACK006.mp3
- TRACK007.mp3
- TRACK008.mp3
- TRACK009.mp3
- TRACK010.mp3
- TRACK011.mp3
- Based on code by Jim Lindblom and plenty of inspiration from the Freescale
- Semiconductor datasheets and application notes.
- Bare Conductive code written by Stefan Dzisiewski-Smith and Peter Krige.
- This work is licensed under a MIT license https://opensource.org/licenses/MIT
- Copyright (c) 2019, Bare Conductive
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
- ///////////////////////////
- SOUS-MARIN
- Toutes les électrodes bananent du MP3
- +
- Les électrodes 0, 1, 2 bananent sur des rubans LEDS sur les sorties 0, 1, 10
- Les autres électrodes bananent du 5V pour ce que l'on veut (leds, relay,....)
- *******************************************************************************/
- // neopixel includes
- #include <Adafruit_NeoPixel.h>
- int nb_ledstip_1 = 10; // nombre de leds sur la première partie du ruban de led
- int nb_ledstip_2 = 10; // nombre de leds sur la seconde partie du ruban de led
- int nb_ledstip_3 = 10; // nombre de leds sur la troisième partie du ruban de led
- int NUMPIXELS = nb_ledstip_1 + nb_ledstip_2 + nb_ledstip_3 ;// nombre total de leds
- int led_array[6]={0,nb_ledstip_1,nb_ledstip_1+1,nb_ledstip_2+nb_ledstip_1,nb_ledstip_2+nb_ledstip_1+1,NUMPIXELS};
- int pin_led_strip = 10; //broche du ruban de led
- Adafruit_NeoPixel strip0 = Adafruit_NeoPixel(NUMPIXELS, pin_led_strip, NEO_GRB + NEO_KHZ800);
- // touch includes
- #include <MPR121.h>
- #include <Wire.h>
- #define MPR121_ADDR 0x5C
- #define MPR121_INT 4
- // mp3 includes
- #include <SPI.h>
- #include <SdFat.h>
- #include <FreeStack.h>
- #include <SFEMP3Shield.h>
- // mp3 variables
- SFEMP3Shield MP3player;
- byte result;
- int lastPlayed = 0;
- // mp3 behaviour defines
- #define REPLAY_MODE FALSE
- // #define REPLAY_MODE TRUE
- /*TRUE=toucher à plusieurs reprises rejoue la piste à chaque fois depuis le début.
- FALSE=appuyez plusieurs fois arrêtera la piste si elle est déjà jouer, ou jouer depuis le début s'il ne l'est pas.*/
- // touch behaviour definitions
- #define firstPin 0
- #define lastPin 11
- // sd card instantiation
- SdFat sd;
- void setup() {
- Serial.begin(57600);
- Serial.println("Bare Conductive Touch MP3 player");
- if (!sd.begin(SD_SEL, SPI_HALF_SPEED)) sd.initErrorHalt();
- if (!MPR121.begin(MPR121_ADDR)) Serial.println("error setting up MPR121");
- MPR121.setInterruptPin(MPR121_INT);
- // valeur modifiable et valable pour l'ensemble des électrodes - Valeur initiale 40/20
- MPR121.setTouchThreshold(20);
- MPR121.setReleaseThreshold(10);
- /* il est également possible de définir certaines électrodes
- comme contact et les autres comme proximité.
- par exemple :
- Régler uniquement l'électrode 11 avec les valeurs de seuil respectives.
- MPR121.setTouchThreshold (11, 20);
- MPR121.setReleaseThreshold (11, 10);
- */
- MPR121.setFFI( FFI_10 ); //modifier le nombre d'échantillons mesurés. Remplacer le filtre par l'une des valeurs suivantes FFI_6, FFI_10, FFI_18, FFI_34
- MPR121.setSFI( SFI_10 );
- MPR121.setGlobalCDT( CDT_4US ); // reasonable for larger capacitances at the end of long cables
- MPR121.autoSetElectrodeCDC(); // autoset all electrode settings
- // digitalWrite(LED_BUILTIN, LOW);
- result = MP3player.begin();
- MP3player.setVolume(10, 10);
- if (result != 0) {
- Serial.print("Error code: ");
- Serial.print(result);
- Serial.println(" when trying to start MP3 player");
- }
- ///////////////////////////
- //Gestion des rubans LED : strip0, strip1, strip2
- strip0.begin();
- strip0.show(); // initialize all pixels to "off"
- //TEST des 3 rubans lED dans le setup
- colorWipe(strip0.Color(0, 255, 0), 50,0); // premiere bande
- colorWipe(strip0.Color(0, 255, 0), 50,1); // seconde bande
- colorWipe(strip0.Color(0, 255, 0), 50,2); // troisieme bande
- }
- void loop() {
- readTouchInputs();
- }
- void colorWipe(uint32_t c, uint8_t wait,int num_strip) {
- for(uint16_t i=led_array[num_strip*2]; i<led_array[num_strip*2+1]; i++) {
- strip0.setPixelColor(i, c);
- strip0.show();
- delay(wait);
- }
- }
- void theaterChaseRainbow(uint8_t wait) {
- for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
- for (int q=0; q < 3; q++) {
- for (uint16_t i=0; i < strip0.numPixels(); i=i+3) {
- strip0.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
- }
- strip0.show();
- delay(wait);
- for (uint16_t i=0; i < strip0.numPixels(); i=i+3) {
- strip0.setPixelColor(i+q, 0); //turn every third pixel off
- }
- }
- }
- }
- // Input a value 0 to 255 to get a color value.
- // The colours are a transition r - g - b - back to r.
- uint32_t Wheel(byte WheelPos) {
- WheelPos = 255 - WheelPos;
- if(WheelPos < 85) {
- return strip0.Color(255 - WheelPos * 3, 0, WheelPos * 3);
- }
- if(WheelPos < 170) {
- WheelPos -= 85;
- return strip0.Color(0, WheelPos * 3, 255 - WheelPos * 3);
- }
- WheelPos -= 170;
- return strip0.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
- }
- void readTouchInputs() {
- if (MPR121.touchStatusChanged()) {
- MPR121.updateTouchData();
- // only make an action if we have one or fewer pins touched
- // ignore multiple touches
- if (MPR121.getNumTouches() <= 1) {
- for (int i = 0; i < 12; i++) { // Check which electrodes were pressed
- if (MPR121.isNewTouch(i)) {
- //pin i was just touched
- Serial.print("pin ");
- Serial.print(i);
- Serial.println(" was just touched");
- //digitalWrite(LED_BUILTIN, HIGH);
- if (i <= lastPin && i >= firstPin) {
- if (MP3player.isPlaying()) {
- if (lastPlayed == i && !REPLAY_MODE) {
- // if we're already playing the requested track, stop it
- // (but only if we're not in REPLAY_MODE)
- MP3player.stopTrack();
- Serial.print("stopping track ");
- Serial.println(i - firstPin);
- // switch off the relevant LED output
- // digitalWrite(ledPins[lastPlayed], LOW);
- } else {
- // if we're already playing a different track (or we're in
- // REPLAY_MODE), stop and play the newly requested one
- MP3player.stopTrack();
- MP3player.playTrack(i - firstPin);
- Serial.print("playing track ");
- Serial.println(i - firstPin);
- // switch off the relevant LED output
- //digitalWrite(ledPins[lastPlayed], LOW);
- // switch on the new LED output
- // digitalWrite(ledPins[i], HIGH);
- // don't forget to update lastPlayed - without it we don't
- // have a history
- lastPlayed = i;
- }
- } else {
- // if we're playing nothing, play the requested track
- // and update lastplayed
- MP3player.playTrack(i - firstPin);
- Serial.print("playing track ");
- Serial.println(i - firstPin);
- // switch on the new LED output
- // digitalWrite(ledPins[i], HIGH);
- lastPlayed = i;
- }
- }
- } else {
- if (MPR121.isNewRelease(i)) {
- Serial.print("pin ");
- // Serial.print(i);
- Serial.println(" is no longer being touched");
- //digitalWrite(LED_BUILTIN, LOW);
- // digitalWrite(ledPins[lastPlayed], LOW);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement