Bird
0
0
Arduinoprogramming~5 mins

Why displays enhance projects in Arduino - Performance Analysis

Choose your learning style9 modes available
Time Complexity: Why displays enhance projects
O(n)
Understanding Time Complexity

When we add displays to Arduino projects, the program spends time updating what shows on the screen.

We want to know how the time to update the display grows as we show more information.

Scenario Under Consideration

Analyze the time complexity of the following code snippet.


#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  lcd.begin(16, 2);
}

void loop() {
  for (int i = 0; i < 16; i++) {
    lcd.setCursor(i, 0);
    lcd.print('*');
  }
  delay(1000);
}
    

This code prints a row of 16 stars on the display, updating each position one by one.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: The for-loop that updates each of the 16 positions on the display.
  • How many times: 16 times per loop cycle, once for each column on the display.
How Execution Grows With Input

As the number of characters to display grows, the time to update grows too.

Input Size (n)Approx. Operations
1010 updates
1616 updates
100100 updates

Pattern observation: The time grows directly with how many characters we update on the display.

Final Time Complexity

Time Complexity: O(n)

This means the time to update the display grows in a straight line with the number of characters shown.

Common Mistake

[X] Wrong: "Updating the display always takes the same time no matter how much we show."

[OK] Correct: Actually, each character update takes time, so more characters mean more time spent.

Interview Connect

Understanding how display updates affect program speed helps you write smooth, responsive projects that users enjoy.

Self-Check

What if we only update changed characters instead of all? How would the time complexity change?