Tone/PWM project, CODE WONT COMPILE! IS IT ILLOGICAL?

Have a project where I want to output a square wave using a push-button trigger and generate a tone simultaneously with that trigger. I need a momentary wave, 3 second wave, and 5 second wave with corresponding tone. I also need these to trigger with a single push-button input (ie the user would push the button once and a 5 second pulse would trigger without having to hold switch). The code shown is just a test to try and make 3 second pulse work. The different pulse channels are controlled by a triple throw switch. The error shows that trying to read the tone pin for my while loop is causing issues. Any ideas on how to fix this or work around it?

const int pushButton = 26;

const int Sec3Switch = 50;

float Sec3Signal = 3;

float Sec3Tone = 9;

void setup()
{
pinMode(pushButton, INPUT);
pinMode(Sec3Switch, INPUT);
pinMode(Sec3Signal, OUTPUT);
pinMode(Sec3Tone, OUTPUT);
}

void loop()
{
if(digitalRead(pushButton) == HIGH && digitalRead(Sec3Switch) == HIGH)
{
tone(9,200,3000);

    while(digitalRead(Sec3Tone) = HIGH)
    {
      analogWrite(3,255);
    }
}

}

Oops.

It would have saved time if you'd posted the error message(s) you'd seen.
(You can't assign a value to a function, maybe you meant to compare instead?)

Please remember to use code tags when posting code.

Also, please don't SHOUT

You should begin by learning how to detect a key change event:
https://www.arduino.cc/en/Tutorial/BuiltInExamples/StateChangeDetection

thanks, i meant to use == and not =

also thank you for using 75% of your message to whine about how i posted. you didnt have to respond

Not a good thing for someone who hasn't read or followed the forum guidelines to say...

People have gone to great lengths to post helpful texts about the best way to use the forum, and get answers.
They're dotted all over the forum, to make them easy to find.

But you chose to ignore them.

There are numerous other problems with your sketch. With the attitude that you've displayed, you won't get any help with them, though... people will read that and just pass.

Adds a whole new meaning to "floating inputs"

1 Like

thats weird because its working now. thank u keyboard warrior and your other friend mr keyboard warrior. i hope you have a long life spent on arduino forum following rules and getting upset

I'm not upset. Enjoying a fine sunny day drinking my coffee here. I solve on average about 3-8 member problems each day. So I'm not concerned if someone doesn't want my help, or doesn't value it.

1 Like

Having a beer here, but no popcorn.

@ chrisholton,
Most people who are looking for free help have enough good sense not to show up with a pissy attitude or antagonize those who might be willing to provide that help. Congratulations on being an exception on both accounts.

what a great way to shoot yourself in the foot.

good luck coming back from this...

Good work. You may decide not to, but ppl try to learn on these fora. It would help if you could post the complete code as you have adjusted it.

TIA

Oh, welcome to the forum!

alto777

Code that runs is not necessarily okay ... :wink: Just a hint: Experienced programmers would generally try to avoid float variables on microcontrollers if ever possible, and never for digital pin assignment (no need for floating point pin numbers like Pin #3.14159, do you agree?).

Reason for the advises regarding the rules is the massive amount of time and misinterpretation that can be avoided by clear and sufficient error description.

People (even most helpful people) get tired and annoyed to spent time on getting the basic information. I know they could just ignore those posts, but then beginners would probably stay alone with their problems....

...and... all that is covered quite well in the forum introduction threads...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.