Robin2:
Maybe when you remove the line with return you also have to change the function definition from
bool checkForButtonPress() {
to
void checkForButtonPress() {
The code in the link I gave you in Reply #7 uses several functions - each using different timing. And there is a more comprehensive example in Planning and Implementing a Program
...R
Hi Robin2
Yes, you're right I updated the code as you suggested and the LED works as programmed
Robin2 the link with the chapters that you wrote I will read until it is clear, Good work that you did.
Thanks for your help
MorganS:
My previous comment was a bit short because I was typing it on my phone. I've re-read your code and it makes more sense to me. The single-letters were confusing. x is the current value of the digital read and i is the previous value. It will toggle the runBlink1 when the button is currently pressed and previously wasn't, and not more often than once every 50 millseconds.
So this simple single-blink works now? You have it working in a way that you expect? Now you want to go back to the original question of "entering" a function...
When we plan to write a computer program, usually there is some "flowchart" of a linear sequence of actions. "Do A" is followed by "Do B". When we're actually writing the code, we also have a linear sequence of actions. "x = digitalRead(PULSET);" is followed by "if(!x&&i)" and so on. But there's a middle layer in between those two levels which is absolutely not linear. Your project might have an "emergency stop" button. Every box on the flowchart has an invisible arrow leading out of it that would say "stop button pushed". You don't draw those arrows on the chart because the chart would get messy.
Similarly, in the actual code, you don't have every single function check the emergency stop button after every 4 lines of code. That would be unbelievably messy. You must structure your code so that no function ever gets stuck for more than a few milliseconds. Then you can have another function check the emergency-stop button and any other inputs. If you stick to the rule about functions running quickly, you can make it look like it stops "instantly" but really it took a few milliseconds because it was doing something else at the exact moment you pressed the button.
Read and re-read Robin's link above. Then try to ask your question again in a different way.
Hi MorganS
Thanks for the support, I personally still do not have advanced knowledge, so I welcome the help.
Whenever I need this forum I hope they help me, I do not want anything done, but rather tips, advice, correct the mistakes I have made in my code .etc
Thank you for understanding