arduino, sensor box and a button

mantaraffu's icon

Hi, I'm looking for a realize a simple series of button to launch samples using arduino and sensor box. the problem is that everytime I push the button, obviously arduino send a fast sequence of 0 and 1, so my sample start and stop. when I push a button, I need only one 1, not a series of 1 and 0. any suggestion?

Jan M's icon

[change] is your friend ;)

mantaraffu's icon

you rock!
thank you

Jan M's icon

Thanx! ;)

Another way would be to alter your Arduino script in that way that you only print to the serial port if the value has changed.

int oldButtonState = 0;
int buttonState = 0;
[...]
void loop() {
buttonState = digitalRead();
if (oldButtonState != buttonState {
Serial.write(buttonState);
oldButtonState = buttonState;
}
}

[this is untested just dirty coding to explain the mechanism]

It will have the same effect at then but be slightly more elegant, as you avoid unnecessary data transfer.

Jan

mantaraffu's icon

you right, and I'm a bit lazy on arduino programming. I'm building a simple system, maybe with time I will build a similar system using only arduino, I'm trying this code on sensor box...