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

Thread: A simple Keyboard

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

    A simple Keyboard

    Hi Forum, newby here.

    - making a quick prototype of a keyboard with teensy-3.2, Audio-shield, 8 tick-switches that plays 8 different notes. using digi-Inputs 0-7.

    - using waveform >> envelope >> mixer >> I2S

    Click image for larger version. 

Name:	IMG_7158.jpg 
Views:	27 
Size:	192.7 KB 
ID:	16173

    The code :

    #include <Bounce.h>

    Bounce button1 = Bounce(0, 15);
    Bounce button2 = Bounce(1, 15);
    Bounce button3 = 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(7, 15);


    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>

    // GUItool: begin automatically generated code
    AudioSynthWaveform waveform1; //xy=64,187
    AudioEffectEnvelope envelope1; //xy=238,176
    AudioMixer4 mixer1; //xy=485,164
    AudioOutputI2S i2s1; //xy=810,169
    AudioConnection patchCord1(waveform1, envelope1);
    AudioConnection patchCord2(envelope1, 0, mixer1, 0);
    AudioConnection patchCord3(mixer1, 0, i2s1, 0);
    AudioConnection patchCord4(mixer1, 0, i2s1, 1);
    AudioControlSGTL5000 sgtl5000_1; //xy=495,480
    // GUItool: end automatically generated code


    void setup() {
    Serial.begin(9600);
    AudioMemory(20);
    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(7, INPUT_PULLUP);


    mixer1.gain(0, 0.9);

    sgtl5000_1.enable();
    sgtl5000_1.volume(0.32);

    envelope1.attack(0.1);
    envelope1.hold(0);
    envelope1.decay(0.1);
    envelope1.sustain(0.3);
    envelope1.release(2000);
    }

    void loop() {
    button1.update();
    button2.update();
    button3.update();
    button4.update();
    button5.update();
    button6.update();
    button7.update();
    button8.update();

    if (button1.risingEdge()){
    Serial.println("C");
    waveform1.begin(0.75,262,WAVEFORM_SAWTOOTH);
    waveform1.pulseWidth(0.15);
    envelope1.noteOn();

    } else if (button1.fallingEdge()){
    envelope1.noteOff();
    }
    .
    .
    .
    .
    if (button7.risingEdge()){
    Serial.println("B");
    waveform1.begin(0.75,493,WAVEFORM_SAWTOOTH);
    waveform1.pulseWidth(0.15);
    envelope1.noteOn();

    } else if (button7.fallingEdge()){
    envelope1.noteOff();
    }
    if (button8.risingEdge()){
    Serial.println("C");
    waveform1.begin(0.75,523,WAVEFORM_SAWTOOTH);
    waveform1.pulseWidth(0.15);
    envelope1.noteOn();

    } else if (button8.fallingEdge()){
    envelope1.noteOff();
    }



    }


    What I hear:

    - most of the switches are not triggering anything. the ones that do - are not playing the allocated frequency
    - the audio is not consistent - sometimes it plays some times it doesn't.

    I am sure that I am doing fundamental mistakes both code and wiring. If anyone can shine a light on those mistakes I'd be very happy.

    also - is there a better way to play notes without explicitly writing the frequency? i.e something like C4, D5 etc

    Thank you so much

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,914
    Looks like the buttons are connected incorrectly. DO NOT wire the buttons to 3.3V power. Connect each button only to GND and to the signal input.

    Also, if you use pin 7, remove that SD card.

  3. #3
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,565
    Mounting the buttons this way is very unreliable, too. Are you sure they have connections?

  4. #4
    Junior Member
    Join Date
    Mar 2019
    Posts
    17
    Quote Originally Posted by PaulStoffregen View Post
    Looks like the buttons are connected incorrectly. DO NOT wire the buttons to 3.3V power. Connect each button only to GND and to the signal input.

    Also, if you use pin 7, remove that SD card.
    Works ! Thank you So much!

    two small ones :

    - If i want to make this polyphonic, do I need to give each button its own waveform? is there a more efficient way?
    - is there a way to write notes rather than frequencies?

  5. #5
    Junior Member houtson's Avatar
    Join Date
    Aug 2015
    Location
    Scotland
    Posts
    16
    Have a look at https://www.arduino.cc/en/Tutorial/toneMelody for notes rather than frequencies

  6. #6
    Junior Member
    Join Date
    Mar 2019
    Posts
    17
    Thank you!

    Moving on to make a simple looper - press a button >> play something on the keyboard >> press another button >> play the recording

    trying to work with the "recorder" example:

    1. how do I make my "waveform" object (my synth keyboard above) the input for the recording?
    2. https://www.youtube.com/watch?v=RsCtGyrawKA - a reference to what I'm imagining, unfortunately no documentation for this.

    appreciate it...

Posting Permissions

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