Go Down

Topic: Need my code tweaked, will PayPal $25 to person who helps (Read 317 times) previous topic - next topic

laughingcamera

Can somebody help me? I want the loop to run one time when the button is pushed one time. I have got to be doing something wrong. E-mail directly if interested. mark@laughingcamera.com

el_supremo

If you had All warnings turned on in the IDE you would get this informative message:
Code: [Select]
C:\Users\Peter\AppData\Local\Temp\arduino_modified_sketch_591412\sketch_jun24b.ino: In function 'void loop()':

C:\Users\Peter\AppData\Local\Temp\arduino_modified_sketch_591412\sketch_jun24b.ino:22:27: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]

   if (buttonState == HIGH); {   //run the loop

                           ^


The semicolon shouldn't be there.

Pete
Don't send me technical questions via Private Message.

laughingcamera

Sorry but I do not understand what you mean by "If you had All warnings turned on in the IDE you would get this informative message:"

I tried it without the ; and still does not run when I press the button.

el_supremo

I presume you are using the IDE and not the online Create thingy.
In the File menu, select Preferences. In the dialog which pops up in "Show verbose output during" select "compilation" and just under that select "Compiler Warnings" All.
Then you may get extra warning messages during compilation. These warnings are often just as important as a compiler message. In the case of the warning message I posted, that semicolon definitely shouldn't be there.

If the code still isn't working, at least removing the semicolon is progress :)

You would usually use INPUT_PULLUP instead of INPUT when setting the pinMode of a button. This will hold the pin HIGH until the button is pushed, in which case you need to look for LOW instead of HIGH.

In setup do this:
Code: [Select]
  pinMode(buttonPin, INPUT_PULLUP);

and in loop do this:
Code: [Select]
  if (buttonState == LOW) {   //run the loop

Pete
Don't send me technical questions via Private Message.

laughingcamera

I am using the Mac desktop version and that choice is not in the preferences. Will try your suggestion. Thank you.

laughingcamera

Just got the answer from a forum member. Thanks for the help folks and pointing me in the correct direction.


patduino

There are 10 types of people in the world, those who understand binary, and those that don't.

PaulMurrayCbr

What a shame - I was looking forward to that $25.

I bet he had the sense of his button the wrong way around.
http://paulmurraycbr.github.io/ArduinoTheOOWay.html

Go Up