What is the output of the code given below if there is a constant 5V supply to pin 10? [code] void setup() { Serial.begin(9600); } void

Đức Linh

New member
What is the output of the code given below if there is a constant 5V supply to pin 10?
Code:
void setup() {
    Serial.begin(9600);
}
void loop() {
    int x=0;
    do {
        x=analogRead(10);
        Serial.println(x);
    }while(x!=1023);  
}
A. 1023
B. 1024
C. null
D. 1029
 
Answer: A
Explanation: The above code takes an input and the prints the value of the voltage that is mapped to an integer set of 0 to 1023. The loop runs continuously until the value of ‘x’ is equal to 1023 or 5V as input. The control structure that is used here is the do-while loop and is an exit-controlled loop.
 

Tìm kiếm

Back
Top