Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following code snippet: void loop() { delay(100); current_time = millis(); do_some_computation(); //this code is written by someone else Serial.println(current_time); } The intent here

Consider the following code snippet:

void loop() {

delay(100);

current_time = millis();

do_some_computation(); //this code is written by someone else

Serial.println(current_time);

}

The intent here is to compute some result 10 times per second (i.e., every 0.1 sec). Assume that the time taken in do_some_computation() is 5ms the first two times it is invoked, is 150ms the third time it is invoked, and returns to 5ms the fourth invocation. Assume that all other overheads each iteration of loop() add up to 1ms worth of time.

Assuming that setup()prints 100 on the first iteration, fill in the table below for what is printed the second through fifth times through loop():

Which iteration of loop()

Value printed by Serial.println()

1

100

2

3

4

5

(b) Next consider the following code snippet:

unsigned long next_iteration_time = 0;

void loop() {

current_time = millis();

if (current_time >= next_iteration_time) { // iteration

do_some_computation(); //this code is written by someone else

Serial.println(current_time);

next_iteration_time = next_iteration_time + 100;

}

}

Making all the same assumptions as above, again fill in the table below for what is printed the second through fifth times the print statement is called.

Which iteration

Value printed by Serial.println()

1

0

2

3

4

5

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

4. Why is job analysis the foundation of many other HR activities?

Answered: 1 week ago

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago