I'm new in the Arduino-world, starting out with the starterkit and trying something of my own for the first time.
When I press the button on my project a servo starts to swing between a certain number of degrees and two leds start to burn.
Now, when I press the button again, the servo stops swinging and the leds stop burning.
At least, that's what I intended, strange thing though, turning everything on works just fine every time, turning it off not, sometimes when I push the button it switches off immediately but most of the time I have to push it a few times, or a few seconds before it switches off.
Anybody who's got an idea what I did wrong?
Thanks a lot!
I'm just going to guess it's the 500mS delays... You are not reading the switch while delay() is "running".
The Blink Without Delay example shows you how to set-up a timer, and check if the time is up every time through a fast-loop without holding everything up with a delay().
I'l probably try this tomorrow. With all the different topics etc. here I couldn't find a solution myself, that's why I asked. Like I said, new in Arduino-world and didn't come up with the "delay"-problem myself. Thanks a lot!
Thanks a lot both of you, i've studied the "several things at a time" topic, and then rewrote all of my code for my own project based on that one.
Now everything works except for one small problem:
When I push the button I want the leds to turn on and the servo to begin swinging and it does that.
The problem is that the moment I push the butten the servo doesn't start to swing slowly but first "jumps" a part of it's movement and then sings slowly.
MaartenCal:
Starting position doesn't matter as long as it swings between 65 and 115 degrees and back.
I'm lost now. Maybe I misunderstood Reply #4. I thought what you meant was that (for example) the servo would be at 85deg and would jump to 65 before smoothly moving to 115.
No, when I push the button I want it to smoothly move betweet 65 & 115 all the time, it can just stop where it is at the point I release the button and start from there when I push it again.
MaartenCal:
No, when I push the button I want it to smoothly move betweet 65 & 115 all the time, it can just stop where it is at the point I release the button and start from there when I push it again.
And does it do that now?
If not what does it do that you don't want it to do?