Causing one event only

I want my arduino to serial print in to the computer "hello" or something of the sort every time a button is pressed but only want it to do it once not 10 times for one button press like im currently getting, any idea how to go about it?

swilliams1284:
I want my arduino to serial print in to the computer "hello" or something of the sort every time a button is pressed but only want it to do it once not 10 times for one button press like im currently getting, any idea how to go about it?

You need to detect when the signal edge on the button changes. To do that, keep track of what the last reading of the button was and compare it to the current. If it's different, a transition occurred.

any idea how to go about it?

Yes. You are probably sending a value when the switch pin IS high, rather than when the switch pin GOES high. You need to keep track of the previous state of the switch, so that you can recognize when the state changes (when the switch is pressed and when the switch is released). Do something only at the transitions.

I'll disagree with PaulS( smile). You need too look for the change in the debounced value of the input.

Mark

You need too look for the change in the debounced value of the input.

True. The Serial.print() that used to take time (while the bouncing stopped) is now buffered so the function returns a lot sooner.

so what code should i have for "looking too see if the pin goes high" im relatively new to this.

so what code should i have for "looking too see if the pin goes high"

int currState;
int prevState = LOW;
int somePin = someNumber;

void setup() {}

void loop()
{
   currState = digitalRead(somePin);
   if(currState != prevState)
   {
      // A transition occurred - from pressed to released or from released to pressed
      // The value of the current state defines which transition occurred.
   }
   prevState = currState;
}