Help with my code (potentiometer)

The board I have is a Redboard. I’m trying to use a potentiometer to speed up the tempo of the melody that is playing. That’s not happening though. Here is the code:

#include "pitches.h"

const int piezoPin = 11;
const int yPin = 5;
const int gPin = 4;
const int bPin = 3;
const int pPin = 1;
const int sensorPin = A0;

int ledState = 0;
int ledOn = false;
int sensorValue = 0;
int noteValue = 0; 

int duration = 0;
int noteDuration = 0;
int tempo = 0;

//notes
int melody[] = {
  NOTE_C4, NOTE_C4, NOTE_A3, NOTE_C4,
  NOTE_AS3, NOTE_D4, NOTE_D4, NOTE_E4, 
  NOTE_E4, NOTE_D4, NOTE_E4, NOTE_G4,
  NOTE_F4, NOTE_F4
};

// durations: 2 = half note, and 8/2.9,4,6,8,12.
float noteDurations[] = {
  12, 12, 12, 12,
  12, 12, 12, 12, 
  12, 12, 12, 12,
  12, 6
};

int musicLength=sizeof(melody)/sizeof('NOTE_C5');

void setup() {  
  pinMode(pPin, INPUT);
  pinMode(yPin, OUTPUT);
  pinMode(gPin, OUTPUT);
  pinMode(bPin, OUTPUT);
  pinMode(piezoPin, OUTPUT);  
}

void loop() {
  // put your main code here, to run repeatedly:
  int pPinState=digitalRead(pPin);
  if(pPinState==HIGH) {
    ledState = 1;
  }
  if (pPinState==LOW and ledState ==1) {
    ledState = 2;
    ledOn = not ledOn;
  }
  if (ledOn && pPinState!=HIGH) {
    for (int thisNote = 0; thisNote < musicLength; thisNote++) {
      // blink the three LEDs in sequence
      if (thisNote%3==0){    
        digitalWrite(yPin, HIGH);
        digitalWrite(gPin, LOW);
        digitalWrite(bPin, LOW);
      }
      else if (thisNote%3==1){    
        digitalWrite(yPin, LOW);
        digitalWrite(gPin, HIGH);
        digitalWrite(bPin, LOW);
      }
      else if (thisNote%3==2){    
        digitalWrite(yPin, LOW);
        digitalWrite(gPin, LOW);
        digitalWrite(bPin, HIGH);
      }

      // calculate the note duration. change tempo by changing 2000 to other values
      int noteDuration = 2500/noteDurations[thisNote];
      tone(piezoPin, melody[thisNote],noteDuration);
      
      // to distinguish the notes, set a minimum time between them.
      // the note's duration + 30% seems to work well
      float pauseBetweenNotes = noteDuration * 1.30;
      
      //split the delay into two parts and check to see
      //whether the pushbutton is pressed to turn off
      //the sound and light
      delay(pauseBetweenNotes/2);
      if(digitalRead(pPin)==HIGH) {
        break;      
      }
      delay(pauseBetweenNotes/2);
      if(digitalRead(pPin)==HIGH) {
        break;      
      }
    }
  }
  else if (not ledOn) {
    digitalWrite(yPin, LOW);
    digitalWrite(gPin, LOW);
    digitalWrite(bPin, LOW);
  }

  // get potentiometer input

    int tempo = map(analogRead(sensorPin), 0, 1023, 10000, 10500);

       int delayValue = map(analogRead(sensorPin), 0, 1023, 0, 200);

  

   duration = noteDuration * tempo;

   Serial.println(duration);

  

delay(delayValue);

}

As for the connection of the pot, I have the two outer legs to 3.3V and Gnd. The middle is to Analog 0.

Since I took coding from several resources, it’s kind of a horrible hybrid. This is my first attempt at Arduino and it’s for a class project so I’m not too familiar yet. I apologize!

shuli:
The board I have is a Redboard. I’m trying to use a potentiometer to speed up the tempo of the melody that is playing. That’s not happening though. Here is the code:

#include "pitches.h"

const int piezoPin = 11;
const int yPin = 5;
const int gPin = 4;
const int bPin = 3;
const int pPin = 1;
const int sensorPin = A0;

int ledState = 0;
int ledOn = false;
int sensorValue = 0;
int noteValue = 0;

int duration = 0;
int noteDuration = 0;
int tempo = 0;

//notes
int melody = {
  NOTE_C4, NOTE_C4, NOTE_A3, NOTE_C4,
  NOTE_AS3, NOTE_D4, NOTE_D4, NOTE_E4,
  NOTE_E4, NOTE_D4, NOTE_E4, NOTE_G4,
  NOTE_F4, NOTE_F4
};

// durations: 2 = half note, and 8/2.9,4,6,8,12.
float noteDurations = {
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 6
};

int musicLength=sizeof(melody)/sizeof(‘NOTE_C5’);

void setup() { 
  pinMode(pPin, INPUT);
  pinMode(yPin, OUTPUT);
  pinMode(gPin, OUTPUT);
  pinMode(bPin, OUTPUT);
  pinMode(piezoPin, OUTPUT); 
}

void loop() {
  // put your main code here, to run repeatedly:
  int pPinState=digitalRead(pPin);
  if(pPinState==HIGH) {
    ledState = 1;
  }
  if (pPinState==LOW and ledState ==1) {
    ledState = 2;
    ledOn = not ledOn;
  }
  if (ledOn && pPinState!=HIGH) {
    for (int thisNote = 0; thisNote < musicLength; thisNote++) {
      // blink the three LEDs in sequence
      if (thisNote%3==0){   
        digitalWrite(yPin, HIGH);
        digitalWrite(gPin, LOW);
        digitalWrite(bPin, LOW);
      }
      else if (thisNote%3==1){   
        digitalWrite(yPin, LOW);
        digitalWrite(gPin, HIGH);
        digitalWrite(bPin, LOW);
      }
      else if (thisNote%3==2){   
        digitalWrite(yPin, LOW);
        digitalWrite(gPin, LOW);
        digitalWrite(bPin, HIGH);
      }

// calculate the note duration. change tempo by changing 2000 to other values
      int noteDuration = 2500/noteDurations[thisNote];
      tone(piezoPin, melody[thisNote],noteDuration);
     
      // to distinguish the notes, set a minimum time between them.
      // the note’s duration + 30% seems to work well
      float pauseBetweenNotes = noteDuration * 1.30;
     
      //split the delay into two parts and check to see
      //whether the pushbutton is pressed to turn off
      //the sound and light
      delay(pauseBetweenNotes/2);
      if(digitalRead(pPin)==HIGH) {
        break;     
      }
      delay(pauseBetweenNotes/2);
      if(digitalRead(pPin)==HIGH) {
        break;     
      }
    }
  }
  else if (not ledOn) {
    digitalWrite(yPin, LOW);
    digitalWrite(gPin, LOW);
    digitalWrite(bPin, LOW);
  }

// get potentiometer input

int tempo = map(analogRead(sensorPin), 0, 1023, 10000, 10500);

int delayValue = map(analogRead(sensorPin), 0, 1023, 0, 200);

duration = noteDuration * tempo;

Serial.println(duration);

delay(delayValue);

}




As for the connection of the pot, I have the two outer legs to 3.3V and Gnd. The middle is to Analog 0. 

Since I took coding from several resources, it's kind of a horrible hybrid. This is my first attempt at Arduino and it's for a class project so I'm not too familiar yet. I apologize!

in void setup
add line pinMode(sensorPin,input);

in your code

use  !=            but not  " not"

use  &&            but not   "and"

also int ledOn = false;

I would use boolean here