Push button options

Hey everybody,

I'm willing to set up a project in which a push button would recognize two different kinds of pushes by the length of pressing on it so that it would be useful for Morse code. I'm new to Arduino so I haven't seen any solution to this. Ideas anyone?

If you are new to Arduino then by definition you have not seen any solution for anything. Keep looking! What you want is perfectly possible and there will be lots of examples out there. The functions you need to be looking for are digitalRead() and millis(). Also look for examples which deal with "state change" and "switch debouncing".

I'm glad you are willing. You should first work through some beginner lessons. It won't take long before you figure out for yourself how to make this project. Come back when you've tried and get stuck. You won't understand or learn anything if someone were to start talking code now.

guyg: Hey everybody,

I'm willing to set up a project in which a push button would recognize two different kinds of pushes by the length of pressing on it so that it would be useful for Morse code. I'm new to Arduino so I haven't seen any solution to this. Ideas anyone?

I know. How about a button which, if pressed for a short time, sends a dot, and for a long time, sends a dash... wait a minute... that is what a Morse key does. :)

aarg: I know. How about a button which, if pressed for a short time, sends a dot, and for a long time, sends a dash... wait a minute... that is what a Morse key does. :)

Yep, that's the idea and the pressing time right now is the mystery.

And now for a more focused question - Can I call the millis() function as an interrupt?

Try it.

guyg: Yep, that's the idea and the pressing time right now is the mystery.

And now for a more focused question - Can I call the millis() function as an interrupt?

You could but it doesn't do anything except return a value. There is no return value from an interrupt so it would do nothing. You can call millis() in an ISR but it doesn't increment while it is in the ISR. So you can capture the value of millis() once during the ISR. It's not uncommon to do that.

guyg: Yep, that's the idea

I fear you have not thought this thing through. Draw yourself a timing diagram, showing an example of what the button does, and what the response should be. Now try to imagine how you would implement the logic of the response. Only then will you be ready to begin to code.

What is the purpose of this program, if the output is identical with the input as you have described? Is it to enforce proper timing on sloppy Morse sending? That seems more complicated than you can do with simple means.

At the beginning of a press, it is unknown whether it will be a long or a short. If you have defined specific timing, you can differentiate a short from a long after the period of one short (because of the release). But the sender can't be listening to the output as it would confuse the daylights out of them. It would be like trying to talk while listening to an echo playback of yourself. Thus the sender could get ahead or behind the output by several characters.

Take this to the drawing board and come back with a clearer description of what you want to do.

In Morse code you get the timing during the attention signal, _ . _ . _, I started with Morse flags in 69 working on my 2nd Class badge. Always start with a start signal and send an end to sign off.

So pick up the timing from the sender. 3 longs and 2 shorts, take the shortest dah and the longest dit.

In Arduino time even the dits are going to be big numbers. You can divide the width of the longest dit by 4 or 5 and only read the input state that often since consistent dits will be maybe < 8 HIGH in a row at most and dahs will perhaps be > 12 depends on what the sender does and how many segments you divide the initial input.

Annnnd the spaces should likewise be checked to find the minimum LOW reads to qualify!

If your code does not block, it will be like 1000x faster than you need, hehehe.
If you’re making a trainer then there’s room for feedback and time-stamped logging.

I'm still confused about what it's supposed to do. Is it a "sloppy Morse cleaner-upper", or what?

Read human sent Morse code which is so slow you can check about once every 10 or 20 millis and still tell the dits, dahs and spaces apart with a degree of tolerance.

Dits should be not just like < 8 but more like > 3 and < 8 for a 100ms average dit polled every 20ms, for example.

But the average should be set by the sender since senders vary at key speed just as listeners do. Some of them blaze.

What timing would you use to make a text to Morse sender that a human will hear? Bet you add a speed set option!

Don’t we set serial baudrate in the sketch and monitor to match?
Trying to remember about Morse, the attention signal got a go ahead before sending the message.
I -could- check my old handbook but I’d have to dig it up.

Maybe the OP has lost their willingness. :)

It's not the same time everywhere. Might have had to go to or leave work.