The learner will review code and answer questions about the analogRead and analogWrite functions.

Analog Output Writing

All the flashcards in this set deal with the following code:

/*Assume an 8-bit analog output. Assume a 10-bit analog input. Assume maximum analog output is 5 VDC, therefore a 5 volt  output would be generated by writing 255 to the analog output. A 2.5 volt output would be generated by writing 128, and a 0 volt output would be generated by writing 0.*/

int OutputPin = 3;
int analogPin = 1;
int value = 0;

void setup()
{
   pinMode(OutputPin, OUTPUT);
}

void main()
{
   value = analogRead(analogPin);
   value = value / 4;
   analogWrite(OutputPin, value);
}


This code is displayed in the image below, which will be on each card, but you may want to make note of it before going on.

Question Image
Question 1 of 10

Analog Output Writing

Correct!

All the flashcards in this set deal with the following code:

/*Assume an 8-bit analog output. Assume a 10-bit analog input. Assume maximum analog output is 5 VDC, therefore a 5 volt  output would be generated by writing 255 to the analog output. A 2.5 volt output would be generated by writing 128, and a 0 volt output would be generated by writing 0.*/

int OutputPin = 3;
int analogPin = 1;
int value = 0;

void setup()
{
   pinMode(OutputPin, OUTPUT);
}

void main()
{
   value = analogRead(analogPin);
   value = value / 4;
   analogWrite(OutputPin, value);
}


This code is displayed in the image below, which will be on each card, but you may want to make note of it before going on.

question image

Correct Answer

Got it!

 Next Question
Question 1 of 10

Analog Output Writing

Incorrect

All the flashcards in this set deal with the following code:

/*Assume an 8-bit analog output. Assume a 10-bit analog input. Assume maximum analog output is 5 VDC, therefore a 5 volt  output would be generated by writing 255 to the analog output. A 2.5 volt output would be generated by writing 128, and a 0 volt output would be generated by writing 0.*/

int OutputPin = 3;
int analogPin = 1;
int value = 0;

void setup()
{
   pinMode(OutputPin, OUTPUT);
}

void main()
{
   value = analogRead(analogPin);
   value = value / 4;
   analogWrite(OutputPin, value);
}


This code is displayed in the image below, which will be on each card, but you may want to make note of it before going on.

question image

Your Answer

Correct Answer

Got it!

 Next Question
Question 1 of 10

Analog Output Writing

Which analog output is being used?

Question Image
Question 1 of 10

Analog Output Writing

Correct!

Which analog output is being used?

question image

Correct Answer

3

Explanation:

The code analogWrite(OutputPin, value) is where we actually send our output to the pin OutputPin.  Since OutputPin has value 3, 3 is the analog output being used.

 Next Question
Question 1 of 10

Analog Output Writing

Incorrect

Which analog output is being used?

question image

Your Answer

Correct Answer

3

Explanation:

The code analogWrite(OutputPin, value) is where we actually send our output to the pin OutputPin.  Since OutputPin has value 3, 3 is the analog output being used.

 Next Question
Question 1 of 10

Analog Output Writing

True or False: OutputPin could have been declared as a Float type variable.

Question Image
Question 1 of 10

Analog Output Writing

Correct!

True or False: OutputPin could have been declared as a Float type variable.

question image

Correct Answer

False

Explanation:

We should never use float variables for values we are going to test for equality or as arguments in functions that take integer arguments.  Both the pinMode and the analogWrite functions take integer arguments.  

 Next Question
Question 1 of 10

Analog Output Writing

Incorrect

True or False: OutputPin could have been declared as a Float type variable.

question image

Your Answer

Correct Answer

False

Explanation:

We should never use float variables for values we are going to test for equality or as arguments in functions that take integer arguments.  Both the pinMode and the analogWrite functions take integer arguments.  

 Next Question
Question 1 of 10

Analog Output Writing

True or False: Essentially, this program reads the analog input 1, scales it by a factor of 4, and then writes the scaled value to analog output 3.

Question Image
Question 1 of 10

Analog Output Writing

Correct!

True or False: Essentially, this program reads the analog input 1, scales it by a factor of 4, and then writes the scaled value to analog output 3.

question image

Correct Answer

True

Explanation:

That is a valid explanation of what this program does.

 Next Question
Question 1 of 10

Analog Output Writing

Incorrect

True or False: Essentially, this program reads the analog input 1, scales it by a factor of 4, and then writes the scaled value to analog output 3.

question image

Your Answer

Correct Answer

True

Explanation:

That is a valid explanation of what this program does.

 Next Question
Question 1 of 10

Analog Output Writing

True or False: We could rewrite the lines value = analogRead(analogPin); and value = value / 4; by replacing them with value = analogRead(analogPin) / 4; and the program would work produce the same results.

Question Image
Question 1 of 10

Analog Output Writing

Correct!

True or False: We could rewrite the lines value = analogRead(analogPin); and value = value / 4; by replacing them with value = analogRead(analogPin) / 4; and the program would work produce the same results.

question image

Correct Answer

True

Explanation:

value = analogRead(analogPin) / 4; would read from the pin analogPin, divide the value by 4, and store that as value, just like the separate lines of code value = analogRead(analogPin); and value = value / 4;.

 Next Question
Question 1 of 10

Analog Output Writing

Incorrect

True or False: We could rewrite the lines value = analogRead(analogPin); and value = value / 4; by replacing them with value = analogRead(analogPin) / 4; and the program would work produce the same results.

question image

Your Answer

Correct Answer

True

Explanation:

value = analogRead(analogPin) / 4; would read from the pin analogPin, divide the value by 4, and store that as value, just like the separate lines of code value = analogRead(analogPin); and value = value / 4;.

 Next Question
Question 1 of 10

Analog Output Writing

If we replaced all three lines of code in the main function with analogWrite(OutputPin, analogRead(analogPin)/4); would this program function the same?

Question Image
Question 1 of 10

Analog Output Writing

Correct!

If we replaced all three lines of code in the main function with analogWrite(OutputPin, analogRead(analogPin)/4); would this program function the same?

question image

Correct Answer

Yes

Explanation:

The program would function the same (with the exception that value would not store anything other than 0); analogWrite(OutputPin, analogRead(analogPin)/4); will read the value on pin analogPin, scale it by a factor of 4, and then analog write that scaled value to pin OutputPin.  

 Next Question
Question 1 of 10

Analog Output Writing

Incorrect

If we replaced all three lines of code in the main function with analogWrite(OutputPin, analogRead(analogPin)/4); would this program function the same?

question image

Your Answer

Correct Answer

Yes

Explanation:

The program would function the same (with the exception that value would not store anything other than 0); analogWrite(OutputPin, analogRead(analogPin)/4); will read the value on pin analogPin, scale it by a factor of 4, and then analog write that scaled value to pin OutputPin.  

 Next Question
Question 1 of 10

Analog Output Writing

True or False: In the line analogWrite(OutputPin, value); the value parameter is an optional parameter.

Question Image
Question 1 of 10

Analog Output Writing

Correct!

True or False: In the line analogWrite(OutputPin, value); the value parameter is an optional parameter.

question image

Correct Answer

False

Explanation:

The analogWrite function requires two inputs, where to write (here OutputPin) and what to write (here value).

 Next Question
Question 1 of 10

Analog Output Writing

Incorrect

True or False: In the line analogWrite(OutputPin, value); the value parameter is an optional parameter.

question image

Your Answer

Correct Answer

False

Explanation:

The analogWrite function requires two inputs, where to write (here OutputPin) and what to write (here value).

 Next Question
Question 1 of 10

Analog Output Writing

If value had not been scaled by a factor of 4 in this program, what would the analog output be if the analog input was 180 hex?

Question Image
Question 1 of 10

Analog Output Writing

Correct!

If value had not been scaled by a factor of 4 in this program, what would the analog output be if the analog input was 180 hex?

question image

Correct Answer

80 hex

Explanation:

Since we only have an 8-bit analog output, we can only write two hex digits of output; thus 80 hex will be output when 180 hex is input.

 Next Question
Question 1 of 10

Analog Output Writing

Incorrect

If value had not been scaled by a factor of 4 in this program, what would the analog output be if the analog input was 180 hex?

question image

Your Answer

Correct Answer

80 hex

Explanation:

Since we only have an 8-bit analog output, we can only write two hex digits of output; thus 80 hex will be output when 180 hex is input.

 Next Question
Question 1 of 10

Analog Output Writing

What is the numerical content of value in the analogWrite function if 2.5 VDC is being output?

Question Image
Question 1 of 10

Analog Output Writing

Correct!

What is the numerical content of value in the analogWrite function if 2.5 VDC is being output?

question image

Correct Answer

128

Explanation:

Since there is an 8-bit output and the maximum output is 5 VDC, then an output of 2.5 VDC must be generated by half of the maximum output, or 128.  Note that the value being referenced here has already been scaled by a factor of 4.

 Next Question
Question 1 of 10

Analog Output Writing

Incorrect

What is the numerical content of value in the analogWrite function if 2.5 VDC is being output?

question image

Your Answer

Correct Answer

128

Explanation:

Since there is an 8-bit output and the maximum output is 5 VDC, then an output of 2.5 VDC must be generated by half of the maximum output, or 128.  Note that the value being referenced here has already been scaled by a factor of 4.

 Next Question
Question 1 of 10

Analog Output Writing

If the analog read results in a value of 3 being read into value, what would be sent to the analog output?

Question Image
Question 1 of 10

Analog Output Writing

Correct!

If the analog read results in a value of 3 being read into value, what would be sent to the analog output?

question image

Correct Answer

0

Explanation:

Since value is an int type, when value = value / 4; is executed, the division 3 / 4 will result in 0, so 0 will be assigned to value.  

 Next Question
Question 1 of 10

Analog Output Writing

Incorrect

If the analog read results in a value of 3 being read into value, what would be sent to the analog output?

question image

Your Answer

Correct Answer

0

Explanation:

Since value is an int type, when value = value / 4; is executed, the division 3 / 4 will result in 0, so 0 will be assigned to value.  

 Next Question
Question 1 of 10

Analog Output Writing

True or False: value could have effectively been divided by 4 by arithmetically shifting it right twice.

Question Image
Question 1 of 10

Analog Output Writing

Correct!

True or False: value could have effectively been divided by 4 by arithmetically shifting it right twice.

question image

Correct Answer

True

Explanation:

Division by 4 and an arithmetic shift right by two places has the same result.

 Finish
Question 1 of 10

Analog Output Writing

Incorrect

True or False: value could have effectively been divided by 4 by arithmetically shifting it right twice.

question image

Your Answer

Correct Answer

True

Explanation:

Division by 4 and an arithmetic shift right by two places has the same result.

 Finish
Question 1 of 10
Analog Output Writing

Score

You have answered 5 of 10 questions correctly.

50%

Start Over

See other flashcards and apps related to:

Question 1 of 10
Author
Published
6/2/2015
Last Updated
6/2/2015
Tags

No Comments Yet