Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Starting from your sketch in question (3), modify that sketch to print the same items to the serial console once every 1.0 seconds without using

Starting from your sketch in question (3), modify that sketch to print the same items to the serial console once every 1.0 seconds without using the delay() command. Increment the integer counter as fast as the computer can count, but only output to serial console each second. Choose a counter datatype that avoids wrap-around. Complete the table below for Serial console communication speeds of 9600 baud, 115200 baud, and 1M baud. Any time unit is ok, but units must be specified.

image text in transcribed

// Declare global variables

unsigned long currentTime, previousTime, elapsedTime;

int counter = 0;

void setup() {

// Initialize serial communication at a baud rate of 9600

Serial.begin(9600);

// Store the current time in milliseconds

currentTime = millis();

previousTime = currentTime;

}

void loop() {

// Store the current time in milliseconds

currentTime = millis();

// Calculate the elapsed time since the last loop iteration

elapsedTime = currentTime - previousTime;

// Print the current Arduino time in milliseconds, counter value, and elapsed loop time in microseconds to the serial console

Serial.print("Arduino Time (ms): ");

Serial.print(currentTime);

Serial.print(" | Counter: ");

Serial.print(counter);

Serial.print(" | Elapsed Time (us): ");

Serial.println(elapsedTime*1000);

// Increment the counter

counter++;

// Store the current time as the previous time for the next loop iteration

previousTime = currentTime;

// Wait for a short period before the next loop iteration

delay(1);

}

\begin{tabular}{|l|l|l|l|} \hline & 9600 baud results & 115200 baud results & 1M baud result \\ \hline Approximate loop time (us) & & & \\ \hline \end{tabular}

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

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions