a simple play button

Hello,

im trying to programm a simple play button with a normal pushbutton(not permanent).
please tell where my logic is wrong.
It should just start when pushed once, when I push him again it should stop.

currentplayState = digitalRead(playPin);
    if (currentplayState == 1 && playing == 0) {
      playing = 1;
    }
    
    if (currentplayState == 1 && playing == 1) {
      playing = 0;
    } 
    
     if (currentplayState == 0 && playing == 1) {
      playing = 1;
    } 

//Main sequence
if (playing == 1) {[...
}/code]

big thnx

It should just start when pushed once, when I push him again it should stop.

What does it do, instead?

Where is your code for setting the mode of the pin in playPin? Are you using the internal pullup resistors? External resistors?

Hello, sorry i thought for the logic it would be enough,

this is the pin declaration:

pinMode(playPin, INPUT);

i am using the button setup from the example here on this site.

i am using the button setup from the example here on this site.

Why is it so difficult to get information from you? Which example?

What does it do, instead?

No answer to this...

when I push him again it should stop.

Maybe you got a girl button instead of a boy button?

i think your problem is the way you use "=" and "=="

i think your problem is the way you use "=" and "=="

What problem do you see? In the code snippet posted, the = and == usage is correct. Of course, some of those ifs should be else ifs.

If playing is 0, and the switch is pressed, playing will be set to 1. Then, it will be set right back to 0.

I'm going to guess that the issue is that it's going on & off more times than you expected. In which case, you will need to debounce your button. Lots of examples of this in tutorials & forum posted code.