Hello, i need some help i think. working code below, but i want when i pushed button, "10 times read sensor and print serial port and then stop until push button again". below code works but only when i hold the button. i dont know what is my fault.
the code inside the if statement only executes while the button is high, just as you wrote it
you'll need to recognize when the button has been pressed (possibly debounce) to toggle the value of a flag and only do the code inside the "if" when the flag is set
i am trying about 1 weeks, i tried millis; and it didnt work and there is no much time for finish this work. ok i will try but i know nothing will change because i didnt understand what is problem. i tried button state, but didnt work because one loop after button state is changing
i think it is working.. anybody comment for changes ?
pinMode(2, INPUT_PULLUP);
}
void loop()
{
int sensorVal = digitalRead(2);
if (sensorVal == HIGH) {
I do not think the button is wired correctly. The unpressed state of INPUT_PULLUP should be HIGH, and your code should be running over and over without any button press.