pwm speaker

hey guys I have a pwm speaker set up, with 2 buttons, attempting to make a simple, mini synthesizer

I tested out the fader example first, to make sure it was hooked up, and the speaker changed pitches, however now it won’t - any idea why?

heres my code:

int breading;
int button = 0;
int breading2;
int button2 = 3;

void setup(){}

void loop(){
breading = analogRead(button);
breading2 = analogRead(button2);

if (breading >=1){
if (breading2 <=1){

analogWrite(9, 85);
}}

if (breading <=1){
if (breading2 >=1){

analogWrite(9, 170);
}}

if (breading <=1){
if (breading2 <=1){

analogWrite(9, 255);

}}}

ok - I checked it again, it doesn’t necessarily change tones, but it does go (bear with me) - when it is on the fader code

nerrroooooooooooooreeeeeeeewwww

the speaker changed pitches, however now it won't - any idea why?

I'll take a guess. Because PWM is always output at one of two frequencies. The noise you're hearing is the frequency used on pin 9.

hey guys I have a pwm speaker set up, with 2 buttons, attempting to make a simple, mini synthesizer

I had a whole long answer typed up, and then pasted this quote at the end with one more question. Before typing the question, though, I re-read the part I pasted to make sure I phrased my question correctly, and the source of your problem struck me.

You have two digital devices that you have connected to analog pins, and that you are using analogRead() to read. Why?

How do you have them wired up?