How does Arduino go through the code in a sketch

Hello,

I would like to know how Arduino goes through the code in a sketch. I am making a camera trigger (it triggers a camera when a sensor detects something) because I want to explore high speed photography.

I made a simple bit of code and it works great. I would write the code and upload the sketch. If I wanted a different setting I would modify the sketch and upload it again. Every time I made a change I had to do this. Because it was time consuming and I needed a computer for every change I made I decided to add a display and make a simple menu with multiple options.

After I added the display the code was slower. I tried multiple libraries. Some were faster than others but still slow. I don’t have the knowledge to make my own library or to modify existing ones to suit my needs.

I would like to know if I can tell Arduino to go through the entire sketch in the beginning while I select the options and once the options have been selected to completely ignore the part of the code with the menu and display and focus only on a tiny part of the code that does the sensor readings. And once the task has been completed to return to going through the entire sketch.

It sounds like you might be drawing all the stuff on the display on each loop. Instead, why not draw on the display only when something on the display changes.

If that's not possible you may need to look at a faster processor like an Arduino Due or a Teensy that runs faster than 16MHz.

Hello,

Thank you for the reply. I think you are correct. My problem is that I don't know how to remove the display from the loop when the information on the display remains the same. Can it be done?

Will something like this

if (displaychange == true)
{
change text
}

ignore the display if displaychange is false? Or it goes through every line of code and does nothing?

It will skip the code block if the condition isn't satisfied.

Generally the screen will only change on a button press (I assume). So your loop will poll for button presses and read the sensor. So if there are no button presses, it will just read the sensor.

That is pretty much what I did and it is slow.

if (displaychange == true)
{
Push buttons and change text
Once the OK button is pressed displaychane =false
}

if (display change == false)
{
wait for a sensor reading and display data.
Once the OK button is pressed displaychange = true
}

You are displaying the sensor data every cycle. That means the arduino is redrawing the screen every cycle. Think about ways to limit how often the screen is redrawn. Maybe only update the screen with sensor data every second or something.

I think I understand. Would something like this work?

if (SensorData != LastSensorData)
{
display sensor data
}

Possibly, assuming the sensor data is not changing constantly. Another solution would be something like the BlinkWithoutDelay example, using millis() to keep track of how much time has passed since the last update.

Thank you for your help. The sensor reading will change once every few seconds. I will also look into the BlinkWithoutDelay example.

There is probably no reason to update the screen more than once per second.

Probably it is also unnecessary to update the entire screen for each iteration of loop. Taking (say) 8 iterations to update the screen would probably not be noticeable to the human eye.

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

And really, you need to post your complete program so we can understand the context for your problem and questions.

...R