Experiment 4.A Pre-Lab Assignment ECEN2270 1) The serial interface on the Arduin
ID: 3349372 • Letter: E
Question
Experiment 4.A Pre-Lab Assignment ECEN2270 1) The serial interface on the Arduino is a powerful tool for debugging. It allows you to view the current value of program variables as your program runs. This can be used to check if a variable is changing as you think it should, or to determine if a program reached a certain point in execution or not. The example program below uses this future to debug by printing the value of the variable “Variable” to the serial monitor. Describe what lines 2, 6, and 10-19 do (line 2 has been done for you as an example). Liberal use of google and the Arduino website will help. 2 int Variable = 0; initialize 'Variable' to zero 4 // the setup routine runs once when you press reset: 5 void setup() { 6 Serial.begin(9600); 13 9 // the loop routine runs over and over again forever: 10 void loop() { 11 Serial.println(Variable, HEX); 12 if (VariableExplanation / Answer
Line 6 Serial.begin (9600) ; // open serial port and set data rate to 9600 bits per second
Line 10 void loop () // repeats the body of loop again and again without returning any value
Line 11 Serial.Println (variable, HEX); //Prints data (i.e. variable) on the serial port in HEX format
Line 12 if (variable < 5) { // conditional statement will be followed . if variable is less than 5 then execute statements in { }
Line 13 variable = variable + 2 // increment variable value in steps of 2 , i.e. 0, 2, 4.....
Line 14 else // close statement block in true condition and open statement block for false condition. when variable > 5
Line 15 Serial.Println ("RESET"); // Print RESET on serial monitor
Line 16 variable = 0 // initialize variable = 0
Line 17 Close the statement block to be executed in false case
Line 18 delay (1000) // introduce delay of 1000ms or 1s
Line 19 Closes loop
Q 2.
0
2
4
RESET
0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.