Need to run two code chunks simultaneously Arduino Uno

Hi guys, I am currently programming an Osepp Uno R3 Plus to control a robotic arm for a science fair project. My end goal is to have a basic UI with five buttons controlling various actuators connected to the arm, but when these buttons aren't in use, the arm executes some demo actions. I have come upon the issue that the delay function halts everything, while I need to be running a constant check in the background for user input from the buttons. Anyone have any ideas? Thanks

Anyone have any ideas?

Don't use delay().

Seriously, this question gets asked about once a week in some form or another, and the answer is always the same - look at the blink without delay example.

Okay, I have been reviewing that example code, and am trying to implement it in my mine. However, I am wondering about doing math with the millis() function. According to the example, you can start running into issues when working with other data types?

To which the simple, obvious answer is "only use unsigned long, and there won't be any problems"

Thanks for not being condescending and arrogant in response to my noobish questions friend.

Glad to help.

IN3RT1A: However, I am wondering about doing math with the millis() function. According to the example, you can start running into issues when working with other data types?

Well as far I've seen, the only maths is arithmetic between a "previous" time and the "current" time to arrive at some kind of "elapsed" time and compare that to a "threshold". So as AWOL said, as long as all those variables are UL, no problem. Admittedly, they use 4 bytes each, but you'll likely only need a handful of them so it's not likely to chow all your memory. (Especially if you save a byte every time you declare other variables as byte when most of us use int out of habit, unless int is really needed.)

Understand that the microcontroller can only be executing a single instruction an any one finite point in time. That is why 'Delay' causes noobs such problems. You can have the micro processing some piece of code while other pieces are waiting for something to do. Hence the concept presented in 'Blink without Delay'.

As to "being condescending and arrogant in response to my noobish questions", try not to be put off. when you ask the pros for help, you gotta take it thier way. This particular issue seems to be a real sore spot with them (it happens way too much, when a little bit of research would probablly have avoided it). and the 'if it hurts when you do that, then don't do that' response to data types is in response to a really 'no brainer' solution.... think about it. Duh!

Take it with a pinch of salt and get on with it. Keep learning. Don't be afraid to ask questions and be prepared for the responses you might get from those who might think that they are stupid questions. Above all, have fun. It's only a hobby and learning experience..

Sorry for the dbbl. post, but ,,,

I, for one, think that the Delay() function shouls be dropped.

123Splat: Understand that the microcontroller can only be executing a single instruction an any one finite point in time. That is why 'Delay' causes noobs such problems. You can have the micro processing some piece of code while other pieces are waiting for something to do. Hence the concept presented in 'Blink without Delay'.

As to "being condescending and arrogant in response to my noobish questions", try not to be put off. when you ask the pros for help, you gotta take it thier way. This particular issue seems to be a real sore spot with them (it happens way too much, when a little bit of research would probablly have avoided it). and the 'if it hurts when you do that, then don't do that' response to data types is in response to a really 'no brainer' solution.... think about it. Duh!

Take it with a pinch of salt and get on with it. Keep learning. Don't be afraid to ask questions and be prepared for the responses you might get from those who might think that they are stupid questions. Above all, have fun. It's only a hobby and learning experience..

I have a pretty solid understanding of threads and computers in general, that is why I knew delay is not what I wanted as the arduino uno is single threaded. However, I was (am) unfamiliar with the libraries of function available for arduino production. Also, I had the wrong idea of what an unsigned long was, which is why i thought i needed to do math with other data types. I did put some research into it, but I was not understanding the code snippets very well. As to the last two paragraphs of your message I'm not worried about what the pros here think of me, and was not put off. Thanks for your concern though. I was just calling him on his BS.

JimboZA:

IN3RT1A: However, I am wondering about doing math with the millis() function. According to the example, you can start running into issues when working with other data types?

Well as far I've seen, the only maths is arithmetic between a "previous" time and the "current" time to arrive at some kind of "elapsed" time and compare that to a "threshold". So as AWOL said, as long as all those variables are UL, no problem. Admittedly, they use 4 bytes each, but you'll likely only need a handful of them so it's not likely to chow all your memory. (Especially if you save a byte every time you declare other variables as byte when most of us use int out of habit, unless int is really needed.)

Thank you, that explanation cleared things up a great deal for me. How do I close the thread?

Glad you're sorted.

You don't close the thread as such- you never know, further posts in future may shed further light.

But it's an idea to edit the original post and add [SOLVED] to the title. Make sure you do it in the original post though: that's the one whose title appears in the index.