Go Down

Topic: Arduino Uno - Send a serial message when button pressed. (Read 360 times) previous topic - next topic

AntoineLive

Hi all.
Sorry for my bad english, i speak french.

Today i wan't to send message when a button is pressed but if i use the sketch:

Code: [Select]
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(2, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly
   if (digitalRead(2) == HIGH) {
         Serial.println("1");
   }
}


In the serial i have 20-30x "1"

I want to have just one "1", what can i do plz ?

Koepel

The change should be detected. That means a variable is needed to remember the previous change.
This is the state change example : http://www.arduino.cc/en/Tutorial/StateChangeDetection

Sorry that no one has answered your other question yet ( http://forum.arduino.cc/index.php?topic=392295.0 ).

AntoineLive

Thank you for your answer !

For my first post, i have found the problem :)

Go Up