Tone not changing notes or length

So I wanted to test the ToneLibrary on my Pro Mini, that’s my code. The thing is it doesn’t matter what values I chose when I call .play(), lenght or tone never vary. Why is that?

#include <Keypad.h>
#include <Tone.h>

Tone tone1;

//#include "pitches.h"

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
  Serial.begin(9600);
  tone1.begin(A0);
}

void loop(){
  char key = keypad.getKey();

  if (key != NO_KEY){
    Serial.println(key);

    if (key = '1'){
        tone1.play(NOTE_D4, 200); 
    }

    if (key = '2'){
        tone1.play(NOTE_D5, 1000); 
    }

    if (key = '3'){
        tone1.play(NOTE_D6, 2000); 
    }

    if (key = 'A'){
        tone1.play(NOTE_D7, 200); 
    }

    if (key = '4'){
        tone1.play(NOTE_E4, 200); 
    }

    if (key = '5'){
        tone1.play(NOTE_E5, 200); 
    }

    if (key = '6'){
        tone1.play(NOTE_E6, 1000); 
    }

    if (key = 'B'){
        tone1.play(NOTE_E7, 200); 
    }

    if (key = '7'){
        tone1.play(NOTE_F4, 200); 
    }

    if (key = '8'){
        tone1.play(NOTE_F5, 200); 
    }

    if (key = '9'){
        tone1.play(NOTE_F6, 200); 
    }

    if (key = 'C'){
        tone1.play(NOTE_F7, 200); 
    }

    if (key = '*'){
        tone1.play(NOTE_G4, 200); 
    }

    if (key = '0'){
        tone1.play(NOTE_G5, 200); 
    }

    if (key = '#'){
        tone1.play(NOTE_G6, 200); 
    }

    if (key = 'D'){
        tone1.play(NOTE_G7, 200); 
    }   
  }

  delay(100);
}
    if (key = '1'){

ALL these if statements are incorrect. You are not comparing key to ‘1’, you are assigning ‘1’ to key, so it always plays the first one no matter what.
Fix them up to look like this:

    if (key == '1'){

Pete

el_supremo:     if (key = '1'){

ALL these if statements are incorrect. You are not comparing key to '1', you are assigning '1' to key, so it always plays the first one no matter what. Fix them up to look like this:

    if (key == '1'){

Pete

Oh frak, I swear every time something fails, it's because I've messed up the == and = (I used to program in Pascal), and this time I copypasted the error all of the times. Thank you!

el_supremo:     if (key = '1'){

ALL these if statements are incorrect. You are not comparing key to '1', you are assigning '1' to key, so it always plays the first one no matter what.

Pete

Update: I've changed as you told me. Now it produces a different tone but's still the same for all keys. Also duration is the same for all.

Post your new code.

Pete

el_supremo: Post your new code.

Pete

Nevermind, I was obviously forgetting another =