if delay between button press


I want to build a morse to text convert, where I can input the morse signals with a button press and display the text on a 7-segment display. I have already figured out the button to morse signal operation, but now I whant to detect if there is a space between the characters. This would happen when I pause between the morse symbols. So the code would have to check how much time passed between every button press, and if it crosses a certain threshold it would make a space between the morse characters.

I hope my problem is understandable and you can help me. :wink:

Best regards, Lorenz


When button is released, store the value of millis() in a variable

When button is pressed again, compare this variable with the actual value of millis():

if ( millis() - buttonReleasedMillis > 1000 ) // if time between previous button release and actual button press is greater than one second

ok, I have to say I am completely new to millis. I don't know how I can save the millis in a variable, and how to set up the buttonReleasedMilli. sorry for my stupid question and thanks for your quick answer ;)

unsigned long timeNow = millis();

so I put your information int the for me only sensible order together... when I upload it I get an error message.

int button = 2
unsigned long buttonPress = millis();

void setup() {
pinMode (button, INPUT_PULLUP);


void loop() {

if(button == LOW){
  buttonPress = millis();
if ( millis() - buttonPress > 1000 ){

sorry for probably annoying every one :confused:

button has the value 2.

LOW has the value zero

They are never, ever going to be equal.

Try a “digitalRead”

int button = 2

Need a semi-colon

The demo Several Things at a Time illustrates the use of millis() to manage timing. It may help with understanding the technique.

Have a look at Using millis() for timing. A beginners guide if you need more explanation.