How to use a pot to change pitch in audio?

Hey guys,

I'm new to the arduino and so far am loving it! this is also my first post so please bare with me.

I have recently purchased the starter pack, and finished the keyboard project. Im trying to figure out how to get the notes in this project to receive dynamic data from the pot to change the pitch up and down according to the pot. my code so far looks like this:

int buttons;
int potVal;
int const potPin = A1;

int notes = potPin;
void setup () {
buttons = potVal;

Serial.begin(9600);
}
void loop (){
int keyVal = analogRead(A0);

potVal = analogRead(potPin);
map(potVal, 0, 1023, 0, 179);
if(keyVal = potVal){
tone(8, notes);

}
}

All this does is play 1 tone if i move the pot at all. Any suggestions?

Thanks

Try this one.

int buttons;
int potVal;
int const potPin = A1;
const float stp=pow(2,1.0/12);
const int ToneA=220;
int notes = potPin;
int frequency,tone_number;

void setup () 
{
  buttons = potVal;
  Serial.begin(9600);
  
}
void loop ()
{
  potVal = analogRead(potPin);
  int tone_number=map(potVal, 0, 1023, 0,25); //two octavs
  frequency=ToneA*pow(stp,tone_number);
 // Serial.print(potVal);
 // Serial.print("  ");
 // Serial.println(frequency);
  tone(8, frequency,200);
  delay(200);
}