Pages: [1]   Go Down
Author Topic: Push Button - Servo Motor - Variable problem  (Read 326 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey guys need help on some programming logic...
i'll go straight through the important part of my code:
Code:
.
.
.
void loop(){
buttonstate = digitalRead(button);
if (buttonstate == HIGH){
   num = num - 1;
   myservo.write(45);
}
lcd.setCursor (0,5);
lcd.write(num);
}

So here's the thing,
I know the logic of the code would be if you press the push button the servo motor would move to the programmed degree and the "num" variable would be subtracted by 1. I imagine if the user pressed and hold the push button the servo motor would move (but in real life it would seem like it wouldn't) and the variable "num" would continuously decrement by 1.

The outcome i'm trying to pursue is that even if you push and hold the button, the "num" variable will only decrement once. After releasing and pushing the button again would the "num" variable decrement again.

Any advise/codes on how can i do this?
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 106
Posts: 3765
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There is an example provided to you in the IDE called "button state change" This will do exactly what your discribing.
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks a lot... smiley-grin
Logged

Pages: [1]   Go Up
Jump to: