Question

What will the following 2 Arduino code print on the serial monitor?   int x =1 ;...

What will the following 2 Arduino code print on the serial monitor?  
int x =1 ;
void setup() {       
Serial.begin(9600);  
}   
void loop() {       
Serial.println(x);  
x = x+1;
}       

And

int x =1 ;
void setup() {       
Serial.begin(9600);  
}   
void loop() {   
if (x < 10) {   
Serial.println(x);  
x = x+1;
}
else {  
Serial.println(x);  
}
}

Homework Answers

Answer #1

the first program will print

number from 1 than add 1 to it and than print 2

and keep on adding 1 to prevoius number and printing .

i have taken two snapshots of serial monitor.

actually its a infinte loop.

your second program will keep on printing 10 on serial monitor again and again

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
What will the following Arduino code do? Please explain in a few words.    In this...
What will the following Arduino code do? Please explain in a few words.    In this setup, a motor is connected to an H-bridge, which is controlled by pin11 and pin 10. A distance sensor is connected to pin 2. Here is the code: int  motorPin1 = 11; // Variables defined before setup and loop functions can be used anywhere in any function.      int  motorPin2 = 10;    int distance_sensor_pin = 2;   long int pulse_duration, distance_in_inches;   void setup() {     // The...
What will the following Arduino code do? Please explain in a few words. In this setup,...
What will the following Arduino code do? Please explain in a few words. In this setup, a motor is connected to an H-bridge, which is controlled by pin11 and pin 10. A distance sensor is connected to pin 2. Here is the code: int  motorPin1 = 11; // Variables defined before setup and loop functions can be used anywhere in any function.      int  motorPin2 = 10;    int distance_sensor_pin = 2;   long int pulse_duration, distance_in_inches;   void setup() {     // The setup...
I have wrote this code for arduino to turn the LED light off when an object...
I have wrote this code for arduino to turn the LED light off when an object is not detected and the LED light on when an object is detected, although the code is not working. How can I improve this? #define trigPin 12 #define echoPin 11 int ledPin= 1; //Connect LEd pin to 6 int duration, distance; //to measure the distance and time taken void setup() { Serial.begin (9600); //Define the output and input objects(devices) pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(ledPin,...
A.6 ... static int x = 1; int y = x * 2; void t1() {...
A.6 ... static int x = 1; int y = x * 2; void t1() {                 y++;                 cout << "x: " << x << " | y: " << y << endl;                 y += 1;                 x -= -1; } void t2() {                 int* x = &y;                 cout << "x: " << x << " | y: " << y << endl; } void t3() {                 int y = x;                 static int x...
Complete the Java code. The code should print “x is in numbers” if the integer x...
Complete the Java code. The code should print “x is in numbers” if the integer x is one of the values stored in numbers. If x is not in numbers, your code should print “x is not in numbers” public static void main(String[] args){                         int[] numbers = <some array values>;                         int x = <some value>;             }
The following code should print X is greater than 0. However, the code has errors. Fix...
The following code should print X is greater than 0. However, the code has errors. Fix the code so that it compiles and runs correctly. (Rewrite the program with all the fixes) public class Test1 { public static void main(String[] args) { int x = 3; if (x > 0 System.out.println("x is greater than 0") else System.out.println(x is less than or equal 0"); } } Must be in java and easy to understand grade 11 course
In Java programming language 11.Create the code for a for loop to print the numbers 1  through...
In Java programming language 11.Create the code for a for loop to print the numbers 1  through 5 inclusive vertically so the output is 1 2 3 4 5 11b What is the output of the following               OUTPUT int i=3; while(int i >0) { System.out.println(i); i--; } 11c What is the output of the following               OUTPUT for(int i=3;i<10;i++) System.out.println(3*i); 11d Create the line of code to print the numbers 10 through 1 decreasing by 1 each time 11e Create the line of code...
convert the while loop into for loop x = int(input('Enter initial value: ')) count = 0...
convert the while loop into for loop x = int(input('Enter initial value: ')) count = 0 if(x<1): print('Error') exit() print('Initial value is: ',x,' ',end='') while(x!=1): if(x%2==0): x=x/2 else: x=3*x+1 count+=1 if(x!=1): rint('Next value is: ',int(x),' ',end='') else: print('Final value ',int(x),', ',end='') print('number of operations performed ',int(count),' ',end='') break
Complete the Java ocode. The code should print how many times integer x appears in numbers....
Complete the Java ocode. The code should print how many times integer x appears in numbers. For example, if numbers = {2,2,1,3,2,2} and x = 2, your code should print the number 4, because x appears 4 times in the array public static void main(String[] args){                         int[] numbers = <some array values>;                         int x = <some value>;             }
In Java 1. What will be the value of x after the following section of code...
In Java 1. What will be the value of x after the following section of code executes: int x = 3; if (x > 3)     x = x – 2; else     x = x + 2; A. 1 B.3    C.5              D.7 2. What will be the value of y after the following section of code executes: int y = 5, z = 3; if (y > 4){      z = 2;      y = y – 1;...