Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: Array of samples

  1. #1
    Junior Member
    Join Date
    Mar 2019
    Posts
    17

    Array of samples

    Hi,

    Trying to put the samples from the "Playing Samples" tutorial example into an array, in order to trigger them with capacitive-touch later.

    In the attached pic, you can see that I'm not declaring the array correctly.

    Can someone please help me find the correct way to do that?

    Thank you.

    Click image for larger version. 

Name:	ScreenSo=hot.jpg 
Views:	16 
Size:	102.0 KB 
ID:	16300

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,069
    Change
    Code:
    int notes[]
    to
    Code:
    const int notes[]
    A screen capture is next to useless. Next time, post your code as text, preferably in code tags (using the # icon), which would allow us to try compiling the code.
    Also, copy and paste all the error messages (in code tags).

    Pete

  3. #3
    Junior Member
    Join Date
    Mar 2019
    Posts
    17
    Hi Pete,

    Got it, sorry..

    It is still giving me that error :

    Code:
    // WAV files converted to code by wav2sketch
    #include "AudioSampleSnare.h"        // http://www.freesound.org/people/KEVOY/sounds/82583/
    #include "AudioSampleTomtom.h"       // http://www.freesound.org/people/zgump/sounds/86334/
    #include "AudioSampleHihat.h"        // http://www.freesound.org/people/mhc/sounds/102790/
    #include "AudioSampleKick.h"         // http://www.freesound.org/people/DWSD/sounds/171104/
    #include "AudioSampleGong.h"         // http://www.freesound.org/people/juskiddink/sounds/86773/
    #include "AudioSampleCashregister.h" // http://www.freesound.org/people/kiddpark/sounds/201159/
    
    /////LED//////
    #include <FastLED.h>
    #define LED_PIN     12
    #define NUM_LEDS    4
    CRGB leds[NUM_LEDS];
    ///////////////////
    
    #include <Bounce.h>
    #include "pitches.h"
    const int notes[] = {
      AudioSampleSnare, AudioSampleTomtom, AudioSampleHihat, AudioSampleKick, AudioSampleGong, AudioSampleCashregister, AudioSampleTomtom, AudioSampleTomtom
    };
    int melody1[64];
    int melody2[64];
    //int envelopeArr1[32];
    //int envelopeArr2[32];
    bool arrToggle = false;
    
    ///////CAP TOUCH///////////////////
    #include <Wire.h>
    #include "Adafruit_MPR121.h"
    #ifndef _BV
    #define _BV(bit) (1 << (bit)) 
    #endif
    
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    // GUItool: begin automatically generated code
    AudioPlayMemory          playMem1;       //xy=197,57
    AudioPlayMemory          playMem2;       //xy=207,115
    AudioPlayMemory          playMem3;       //xy=212,169
    AudioPlayMemory          playMem4;       //xy=237,246
    AudioMixer4              mixer1;         //xy=460,182
    AudioOutputI2S           i2s1;           //xy=761,184
    AudioConnection          patchCord1(playMem1, 0, mixer1, 0);
    AudioConnection          patchCord2(playMem2, 0, mixer1, 1);
    AudioConnection          patchCord3(playMem3, 0, mixer1, 2);
    AudioConnection          patchCord4(playMem4, 0, mixer1, 3);
    AudioConnection          patchCord5(mixer1, 0, i2s1, 0);
    AudioConnection          patchCord6(mixer1, 0, i2s1, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=545,444
    // GUItool: end automatically generated code
    
    
    
    //CAP TOUCH Vars//
    Adafruit_MPR121 cap = Adafruit_MPR121();
    uint16_t lasttouched = 0;
    uint16_t currtouched = 0;
    
    
    
    // Bounce objects to read pushbuttons 
    Bounce recButton = Bounce(0, 15);
    Bounce playButton = Bounce(1, 15);
    Bounce stopButton = Bounce(2, 15);
    //Bounce button4 = Bounce(3, 15);
    //Bounce button5 = Bounce(4, 15);
    //Bounce button6 = Bounce(5, 15);
    //Bounce button7 = Bounce(6, 15);
    //Bounce button8 = Bounce(8, 15);
    
    //TEMPO Vars//
    elapsedMillis blinkTime;
    elapsedMillis loopTime;
    int tempoPin = A0; 
    int millisBPM = 0;
    int bars;
    int bpm;
    int tempoCounter = 0;
    int barsCounter = 0;
    bool didPlay = false;
    bool didBarPlay = false;
    
    ///////////////////
    
    void setup() {
      Serial.begin(9600);
    
    //int timing[];
    
    ////////LED Vars//////
    FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
    //////////////////
        while (!Serial) { // needed to keep leonardo/micro from starting too fast!
        delay(10);
      }
      
    //  Serial.println("Adafruit MPR121 Capacitive Touch sensor test"); 
      
      // Default address is 0x5A, if tied to 3.3V its 0x5B
      // If tied to SDA its 0x5C and if SCL then 0x5D
      if (!cap.begin(0x5A)) {
    //    Serial.println("MPR121 not found, check wiring?");
        while (1);
      }
    //  Serial.println("MPR121 found!");
    
    
      pinMode(0, INPUT_PULLUP);
      pinMode(1, INPUT_PULLUP);
      pinMode(2, INPUT_PULLUP);
    //  pinMode(3, INPUT_PULLUP);
    //  pinMode(4, INPUT_PULLUP);
    //  pinMode(5, INPUT_PULLUP);
    //  pinMode(6, INPUT_PULLUP);
    //  pinMode(8, INPUT_PULLUP);
      
      AudioMemory(10);
      sgtl5000_1.enable();
      sgtl5000_1.volume(0.5);
      mixer1.gain(0, 0.4);
      mixer1.gain(1, 0.4);
      mixer1.gain(2, 0.4);
      mixer1.gain(3, 0.4);
    
     //Envelope///
    //  envelope1.attack(0.3);
    //  envelope1.hold(0);
    //  envelope1.decay(0.1);
    //  envelope1.sustain(0.3);
    //  envelope1.release(1000);
    
      
    }
    
    
    
    
    
    bool preCount = false;
    bool isRec = false;
    bool isPlay = false;
    
    
    
    void loop() {
    ////////////MAKE LEDS BLACK////////////
    if (!isPlay && !isRec){
      for (int i = 0; i < NUM_LEDS; i++){
        leds[i] = CRGB::Black;
        FastLED.show();  
      }
    }
    /////////////////BPM///////////////////////
    bpm = map(analogRead(tempoPin),0,1023,60,140);
    
    millisBPM = 60000/bpm;
    
    bars = millisBPM/2;
    ///////////BUTTON CHECK////////////
    recButton.update();
    if (recButton.fallingEdge()){
      preCount = true;
      barsCounter = 0; 
      memset(melody1, 0, sizeof(melody1));
      memset(melody2, 0, sizeof(melody2));
        Serial.println("record");
      arrToggle = false;
    }
    playButton.update();
    if (playButton.fallingEdge()){
      barsCounter = 0; 
      isPlay = true;
        Serial.println("play");
    }
    stopButton.update();
    if (stopButton.fallingEdge()){
      isPlay = false;
      isRec = false;
      tempoCounter = 0;
      barsCounter = 0;
    //  envelope1.noteOff();
        Serial.println("stop");
    }
    ////////////PRECOUNT/////////////////////
    if (preCount){
         playMem1.play(AudioSampleTomtom);
       leds[0] = CRGB::Red;
          FastLED.show();  
       delay(millisBPM);
       playMem1.play(AudioSampleSnare);
       leds[0] = CRGB::Green;
          FastLED.show();  
       delay(millisBPM);
       playMem1.play(AudioSampleSnare);
       leds[0] = CRGB::Green;
          FastLED.show();  
       delay(millisBPM);
       playMem1.play(AudioSampleSnare);
       leds[0] = CRGB::Green;
          FastLED.show();  
       delay(millisBPM);
       playMem1.play(AudioSampleTomtom);
       leds[0] = CRGB::Red;
          FastLED.show();  
       delay(millisBPM);
       playMem1.play(AudioSampleSnare);
       leds[0] = CRGB::Green;
          FastLED.show();  
       delay(millisBPM);
       playMem1.play(AudioSampleSnare);
       leds[0] = CRGB::Green;
          FastLED.show();  
       delay(millisBPM);
       playMem1.play(AudioSampleSnare);
       leds[0] = CRGB::Green;
          FastLED.show();  
       delay(millisBPM);
        isRec = true;
    }
      preCount = false;
      
    ///////////////////SEQUENCE////////////////////
    if(isRec || isPlay){
      
    //////////////////Couner of bars///////////
    if(blinkTime > millisBPM/4 ){
          barsCounter ++;
          didPlay = false;
          didBarPlay = false;
          blinkTime = 0;
    //      envelope1.noteOff();
          Serial.println(barsCounter);
          }
    ///////////////////CLICK////////////////////
      if (barsCounter == 4 && !didPlay){
        leds[3] = CRGB::Black;
    //    Serial.println('!');
    //    Serial.println(bpm);
            playMem1.play(AudioSampleTomtom);
        didPlay = true;
        leds[0] = CRGB::Red;
        FastLED.show(); 
      } else if (barsCounter == 8 && !didPlay){
        leds[0] = CRGB::Black;
    //    Serial.println('/');
            playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[1] = CRGB::Green;
        FastLED.show();  
        
      } else if (barsCounter == 12 && !didPlay){
        leds[1] = CRGB::Black;
    //    Serial.println('/');
            playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[2] = CRGB::Green;
        FastLED.show(); 
         
      } else if (barsCounter == 16 && !didPlay){
        leds[2] = CRGB::Black;
    //    Serial.println('/');
            playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[3] = CRGB::Green;
        FastLED.show();  
      } else if(barsCounter == 20 && !didPlay){
        leds[3] = CRGB::Black;
    //    Serial.println('!');
    //    Serial.println(bpm);
            playMem1.play(AudioSampleTomtom);
        didPlay = true;
        leds[0] = CRGB::Red;
        FastLED.show();  
        
      } else if (barsCounter == 24 && !didPlay){
        leds[0] = CRGB::Black;
    //    Serial.println('/');
            playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[1] = CRGB::Green;
        FastLED.show();  
        
      } else if (barsCounter == 28 && !didPlay){
        leds[1] = CRGB::Black;
    //    Serial.println('/');
            playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[2] = CRGB::Green;
        FastLED.show(); 
         
      } else if (barsCounter == 32 && !didPlay){
        leds[2] = CRGB::Black;
    //    Serial.println('/');
            playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[3] = CRGB::Green;
        FastLED.show();  
      }else if(barsCounter == 36 && !didPlay){
        leds[3] = CRGB::Black;
    //    Serial.println('!');
    //    Serial.println(bpm);
            playMem1.play(AudioSampleTomtom);
        didPlay = true;
        leds[0] = CRGB::Red;
        FastLED.show();  
        
      } else if (barsCounter == 40 && !didPlay){
        leds[0] = CRGB::Black;
    //    Serial.println('/');
            playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[1] = CRGB::Green;
        FastLED.show();  
        
      } else if (barsCounter == 44 && !didPlay){
        leds[1] = CRGB::Black;
    //    Serial.println('/');
            playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[2] = CRGB::Green;
        FastLED.show(); 
         
      } else if (barsCounter == 48 && !didPlay){
        leds[2] = CRGB::Black;
    //    Serial.println('/');
            playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[3] = CRGB::Green;
        FastLED.show();  
      }else if(barsCounter == 52 && !didPlay){
        leds[3] = CRGB::Black;
    //    Serial.println('!');
    //    Serial.println(bpm);
            playMem1.play(AudioSampleTomtom);
        didPlay = true;
        leds[0] = CRGB::Red;
        FastLED.show();  
        
      } else if (barsCounter == 56 && !didPlay){
        leds[0] = CRGB::Black;
    //    Serial.println('/');
            playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[1] = CRGB::Green;
        FastLED.show();  
        
      } else if (barsCounter == 60 && !didPlay){
        leds[1] = CRGB::Black;
    //    Serial.println('/');
            playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[2] = CRGB::Green;
        FastLED.show(); 
         
      } else if (barsCounter == 64 && !didPlay){
        leds[2] = CRGB::Black;
    //    Serial.println('/');
            playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[3] = CRGB::Green;
        FastLED.show();  
      }
      
    
    }
    ///////////////////PLAY THE LOOP//////////////////
    if (isPlay){
      if(didBarPlay == false){
        if(arrToggle == true){
          if(melody1[barsCounter]!= NULL){
            if(melody1[barsCounter] != melody1[barsCounter-1]){
    //         waveform1.begin(0.75,melody1[barsCounter],WAVEFORM_SAWTOOTH);
    //         waveform1.pulseWidth(0.15);
    ////         envelope1.noteOn();
          }
        } else{
    //      envelope1.noteOff();
          }
       }else if(arrToggle == false){
        if(melody2[barsCounter]!= NULL){
            if(melody2[barsCounter] != melody2[barsCounter-1]){
    //         waveform1.begin(0.75,melody2[barsCounter],WAVEFORM_SAWTOOTH);
    //         waveform1.pulseWidth(0.15);
    ////         envelope1.noteOn();
          }
        }else{
    //      envelope1.noteOff();
          }
         }
        }
     
        didBarPlay = true;
      
      }
    ////////////////Counter reset/////////////////
        if (barsCounter >= 64){
          barsCounter = 0;
          if (isPlay){
                  if (arrToggle){
            Serial.println("playing array 1");
    //      for(int i = 0; i < sizeof(melody1); i++){
    //        Serial.println(melody1[i]);
    //        
    //      }
            } else {
              Serial.println("playing array 2");
              }
            }
    
          if (isRec){
            arrToggle = !arrToggle;  
            if (arrToggle){
               memset(melody2, 0, sizeof(melody2));
              }else {
              memset(melody1, 0, sizeof(melody1));
              } 
            } 
          }
    
    
    //////////////KEYBOARD////////////////////
    currtouched = cap.touched();
    
     for (uint8_t i=0; i<12; i++) {
        // it if *is* touched and *wasnt* touched before, alert!
        if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
          playMem2.play(AudioSampleHihat);
        } 
        // if it *was* touched and now *isnt*, alert!
        if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {
    //        envelope1.noteOff();
        }
        if(isRec){ ////////////////REC/////////////////
           
    //       if((currtouched & _BV(i))){
    //          if (!arrToggle){
    //          melody1[barsCounter] = notes[i];
    //         }else{
    //          melody2[barsCounter] = notes[i];
    //         }
    //        }
    //      }
      }
     }
      // reset our state
      lasttouched = currtouched;
    
    
    }
    Here are the error messages :

    Code:
    Arduino: 1.8.8 (Mac OS X), TD: 1.45, Board: "Teensy 3.2 / 3.1, Serial, 96 MHz (overclock), Faster, US English"
    
    In file included from /Users/ayalrosenberg/Documents/Arduino/Thesis/Looper_Rec_sampleTest/Looper_Rec_sampleTest.ino:11:0:
    /Users/ayalrosenberg/Documents/Arduino/libraries/FastLED/FastLED.h:14:21: note: #pragma message: FastLED version 3.002.006
     #    pragma message "FastLED version 3.002.006"
                         ^
    Looper_Rec_sampleTest:21: error: invalid conversion from 'const unsigned int*' to 'int' [-fpermissive]
     };
     ^
    Looper_Rec_sampleTest:21: error: invalid conversion from 'const unsigned int*' to 'int' [-fpermissive]
    Looper_Rec_sampleTest:21: error: invalid conversion from 'const unsigned int*' to 'int' [-fpermissive]
    Looper_Rec_sampleTest:21: error: invalid conversion from 'const unsigned int*' to 'int' [-fpermissive]
    Looper_Rec_sampleTest:21: error: invalid conversion from 'const unsigned int*' to 'int' [-fpermissive]
    Looper_Rec_sampleTest:21: error: invalid conversion from 'const unsigned int*' to 'int' [-fpermissive]
    Looper_Rec_sampleTest:21: error: invalid conversion from 'const unsigned int*' to 'int' [-fpermissive]
    Looper_Rec_sampleTest:21: error: invalid conversion from 'const unsigned int*' to 'int' [-fpermissive]
    Looper_Rec_sampleTest: In function 'void loop()':
    Looper_Rec_sampleTest:231: warning: comparison between signed and unsigned integer expressions 
     if(blinkTime > millisBPM/4 ){
                  ^
    Looper_Rec_sampleTest:375: warning: NULL used in arithmetic 
           if(melody1[barsCounter]!= NULL){
                                     ^
    Looper_Rec_sampleTest:385: warning: NULL used in arithmetic 
         if(melody2[barsCounter]!= NULL){
                                   ^
    Multiple libraries were found for "FastLED.h"
     Used: /Users/ayalrosenberg/Documents/Arduino/libraries/FastLED
     Not used: /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/FastLED
    Multiple libraries were found for "SD.h"
     Used: /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/SD
     Not used: /Applications/Arduino.app/Contents/Java/libraries/SD
    invalid conversion from 'const unsigned int*' to 'int' [-fpermissive]
    
    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

    Thanks.

  4. #4
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,069
    This gets rid of the first error:
    Code:
    const unsigned int *notes[] = {
    Pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •