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

Thread: Issue Modifying the SimpleDrum Example - Any help appreciated

  1. #1
    Junior Member
    Join Date
    Nov 2020
    Posts
    2

    Issue Modifying the SimpleDrum Example - Any help appreciated

    I have connected a Read() function that reads from a 32 key 64 switch keyboard by reading the rows and columns

    When I call that function in the SimpleDrum example no sound is generated. I am not using any pins shared with the audio shield. I honestly have no idea what the issue is. I would also like to add that the Serial Monitor displays no information when Read() is called. Any help would be greatly appreciated

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    // GUItool: begin automatically generated code
    AudioSynthSimpleDrum     drum2;          //xy=399,244
    AudioSynthSimpleDrum     drum3;          //xy=424,310
    AudioSynthSimpleDrum     drum1;          //xy=431,197
    AudioSynthSimpleDrum     drum4;          //xy=464,374
    AudioMixer4              mixer1;         //xy=737,265
    AudioOutputI2S           i2s1;           //xy=979,214
    AudioConnection          patchCord1(drum2, 0, mixer1, 1);
    AudioConnection          patchCord2(drum3, 0, mixer1, 2);
    AudioConnection          patchCord3(drum1, 0, mixer1, 0);
    AudioConnection          patchCord4(drum4, 0, mixer1, 3);
    AudioConnection          patchCord5(mixer1, 0, i2s1, 0);
    AudioConnection          patchCord6(mixer1, 0, i2s1, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=930,518
    // GUItool: end automatically generated code
    
    static uint32_t next;
    boolean keyTable[8][8];
    byte cols[] = {24,25,26,27,28,29,30,31};
    byte rows[] = {32,33,34,35,36,37,38,39};
    
    void setup() {
      // put your setup code here, to run once:
    
      Serial.begin(9600);
    
      // audio library init
      AudioMemory(15);
    
      next = millis() + 1000;
    
      AudioNoInterrupts();
    
      drum1.frequency(60);
      drum1.length(1500);
      drum1.secondMix(0.0);
      drum1.pitchMod(0.55);
      
      drum2.frequency(60);
      drum2.length(300);
      drum2.secondMix(0.0);
      drum2.pitchMod(1.0);
      
      drum3.frequency(550);
      drum3.length(400);
      drum3.secondMix(1.0);
      drum3.pitchMod(0.5);
    
      drum4.frequency(1200);
      drum4.length(150);
      drum4.secondMix(0.0);
      drum4.pitchMod(0.0);
      
      sgtl5000_1.enable();
      sgtl5000_1.volume(0.5);
    
      AudioInterrupts();
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    
      static uint32_t num = 0;
      
      if(millis() == next)
      {
        next = millis() + 1000;
    
        switch(num % 4)
        {
          case 0:
            drum1.noteOn();
            break;
          case 1:
            drum2.noteOn();
            break;
          case 2:
            drum3.noteOn();
            break;
          case 3:
            drum4.noteOn();
            break;
        }
        num++;
    
        Serial.print("Diagnostics: ");
        Serial.print(AudioProcessorUsageMax());
        Serial.print(" ");
        Serial.println(AudioMemoryUsageMax());
        AudioProcessorUsageMaxReset();
      }
    
      Read();
    }
    
    void Read()
    {
      for(int i = 0; i < 8; i++)
      {
        //change pinMode
        pinMode(cols[i], OUTPUT);
        delay(10);
        digitalWrite(cols[i], HIGH); //write the col high
        
    
        for(int j = 0; j < 8; j++)
        {
          pinMode(rows[j], INPUT_PULLDOWN);
          delay(10);
          keyTable[j][i] = digitalRead(rows[j]);
          
          if(digitalRead(rows[j]) == HIGH && digitalRead(cols[i] == HIGH))// if the current key is pressed
          {
            Serial.println("Played?");
            //Velocity calculation
            drum1.noteOn();
            
          }
          
          pinMode(rows[j], INPUT);
        }
    
        pinMode(cols[i], INPUT);
      }
    }

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,546
    Code:
          if(digitalRead(rows[j]) == HIGH && digitalRead(cols[i] == HIGH))// if the current key is pressed
    There's a parenthesis in the wrong place. It should be:
    Code:
          if(digitalRead(rows[j]) == HIGH && digitalRead(cols[i]) == HIGH)// if the current key is pressed
    Pete

  3. #3
    Junior Member
    Join Date
    Nov 2020
    Posts
    2
    Wow! Thank you for the help. I have a follow up question, is the reason it didn't work was because I was providing digitalRead with a boolean type that I would guess is always false? Instead of a pin number? Or does this cause some kind of run time error?

  4. #4
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,546
    Code:
    digitalRead(cols[i] == HIGH)
    The value of HIGH is probably 1 and cols[i] is never 1 so the result is FALSE which is zero. The result will be that it will try to read pin 0. In a test on a T4.1 the result of reading pin 0 with nothing connected was also zero.
    So, the if statement as a whole would never evaluate to true. It is an error but it won't cause a specific run-time error, other than it won't work as expected.
    The compiler doesn't generate a warning.

    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
  •