The learner will review code and answer questions about the pinMode, digitalWrite, and digitalRead functions.

Setting Input Pin Modes & Reading Digital Inputs

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

int ledPin = 1;
int inPin = 10;
int value = 0;

void setup()
{
   pinMode(ledPin, OUTPUT);
   pinMode(inPin, INPUT);
}

void main()
{
   value = digitalRead(inPin);
   digitalWrite(ledPin, value);
   delay(5000);
   value = 0;
   digitalWrite(ledPin, 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

Setting Input Pin Modes & Reading Digital Inputs

Correct!

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

int ledPin = 1;
int inPin = 10;
int value = 0;

void setup()
{
   pinMode(ledPin, OUTPUT);
   pinMode(inPin, INPUT);
}

void main()
{
   value = digitalRead(inPin);
   digitalWrite(ledPin, value);
   delay(5000);
   value = 0;
   digitalWrite(ledPin, 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

Setting Input Pin Modes & Reading Digital Inputs

Incorrect

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

int ledPin = 1;
int inPin = 10;
int value = 0;

void setup()
{
   pinMode(ledPin, OUTPUT);
   pinMode(inPin, INPUT);
}

void main()
{
   value = digitalRead(inPin);
   digitalWrite(ledPin, value);
   delay(5000);
   value = 0;
   digitalWrite(ledPin, 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

Setting Input Pin Modes & Reading Digital Inputs

True or False: The variables could have been declared as int ledPin, inPin, value; and then had values assigned to them in the main program.

Question Image
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

Correct!

True or False: The variables could have been declared as int ledPin, inPin, value; and then had values assigned to them in the main program.

question image

Correct Answer

True

Explanation:

That is a valid way to declare variables.

 Next Question
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

Incorrect

True or False: The variables could have been declared as int ledPin, inPin, value; and then had values assigned to them in the main program.

question image

Your Answer

Correct Answer

True

Explanation:

That is a valid way to declare variables.

 Next Question
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

True or False: A digital pin can be assigned as both an input and an output at the same time.

Question Image
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

Correct!

True or False: A digital pin can be assigned as both an input and an output at the same time.

question image

Correct Answer

False

Explanation:

A digital pin can only be one or the other at any specific time.

 Next Question
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

Incorrect

True or False: A digital pin can be assigned as both an input and an output at the same time.

question image

Your Answer

Correct Answer

False

Explanation:

A digital pin can only be one or the other at any specific time.

 Next Question
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

True or False: It would be syntactically correct to have a third function call like pinMode(ledPin, INPUT); in the setup function.

Question Image
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

Correct!

True or False: It would be syntactically correct to have a third function call like pinMode(ledPin, INPUT); in the setup function.

question image

Correct Answer

True

Explanation:

Although this would probably lead to confusion for anyone reviewing the code, the syntax of the statement is correct and the program should compile.

 Next Question
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

Incorrect

True or False: It would be syntactically correct to have a third function call like pinMode(ledPin, INPUT); in the setup function.

question image

Your Answer

Correct Answer

True

Explanation:

Although this would probably lead to confusion for anyone reviewing the code, the syntax of the statement is correct and the program should compile.

 Next Question
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

The digitalRead function in the main function reads from which pin?

Question Image
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

Correct!

The digitalRead function in the main function reads from which pin?

question image

Correct Answer

10

Explanation:

The line value = digitalRead(inPin); is going to read the value of whichever pin inPin is.  Since we have int inPin = 10; and we have not changed its value since then, digitalRead(inPin) is the same as digitalRead(10) and it will read the digital input on pin 10.

 Next Question
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

Incorrect

The digitalRead function in the main function reads from which pin?

question image

Your Answer

Correct Answer

10

Explanation:

The line value = digitalRead(inPin); is going to read the value of whichever pin inPin is.  Since we have int inPin = 10; and we have not changed its value since then, digitalRead(inPin) is the same as digitalRead(10) and it will read the digital input on pin 10.

 Next Question
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

What is the result of the first two lines of code in the main function (restated below)?

value = digitalRead(inPin);
digitalWrite(ledPin, value);

Question Image
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

Correct!

What is the result of the first two lines of code in the main function (restated below)?

value = digitalRead(inPin);
digitalWrite(ledPin, value);

question image

Correct Answer

Pins 1 and 10 will have the same value.

Explanation:

Those lines of code read the value of pin 10 (since inPin = 10) and write that value to pin 1 (since ledPin = 1).

 Next Question
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

Incorrect

What is the result of the first two lines of code in the main function (restated below)?

value = digitalRead(inPin);
digitalWrite(ledPin, value);

question image

Your Answer

Correct Answer

Pins 1 and 10 will have the same value.

Explanation:

Those lines of code read the value of pin 10 (since inPin = 10) and write that value to pin 1 (since ledPin = 1).

 Next Question
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

After the program runs through one time, is the LED on or off?

Question Image
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

Correct!

After the program runs through one time, is the LED on or off?

question image

Correct Answer

Off

Explanation:

The last two lines of code first set value to 0, value = 0;, and then write that to ledPin, digitalWrite(ledPin, value).  Since a value of 0 is off, the LED will be off.

 Next Question
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

Incorrect

After the program runs through one time, is the LED on or off?

question image

Your Answer

Correct Answer

Off

Explanation:

The last two lines of code first set value to 0, value = 0;, and then write that to ledPin, digitalWrite(ledPin, value).  Since a value of 0 is off, the LED will be off.

 Next Question
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

Assume the clock speed is 10 MHz.  If the delay call were not in the program, would you be able to see the LED turn on?

Question Image
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

Correct!

Assume the clock speed is 10 MHz.  If the delay call were not in the program, would you be able to see the LED turn on?

question image

Correct Answer

No

Explanation:

With a clock speed of 10 MHz (10 million cycles per second), the LED would not be left on for long enough to be seen.

 Next Question
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

Incorrect

Assume the clock speed is 10 MHz.  If the delay call were not in the program, would you be able to see the LED turn on?

question image

Your Answer

Correct Answer

No

Explanation:

With a clock speed of 10 MHz (10 million cycles per second), the LED would not be left on for long enough to be seen.

 Next Question
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

Correct!

What does the code value = digitalRead(inPin); do?

question image

Correct Answer

It assigns the variable value inPin's value

Explanation:

The assign operation, namely =, takes the value on the right and attempts to assign it to the variable on the left.  Here, digitalRead(inPin) is found and then that value is assigned to the variable value.

 Next Question
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

Incorrect

What does the code value = digitalRead(inPin); do?

question image

Your Answer

Correct Answer

It assigns the variable value inPin's value

Explanation:

The assign operation, namely =, takes the value on the right and attempts to assign it to the variable on the left.  Here, digitalRead(inPin) is found and then that value is assigned to the variable value.

 Next Question
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

True or False: The variable inPin can have a value of 1.5.

Question Image
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

Correct!

True or False: The variable inPin can have a value of 1.5.

question image

Correct Answer

False

Explanation:

The variable inPin is of type int, so it can only have integer values assigned to it.

 Next Question
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

Incorrect

True or False: The variable inPin can have a value of 1.5.

question image

Your Answer

Correct Answer

False

Explanation:

The variable inPin is of type int, so it can only have integer values assigned to it.

 Next Question
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

The code value = digitalRead(inPin + 2); will attempt to read which input?

Question Image
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

Correct!

The code value = digitalRead(inPin + 2); will attempt to read which input?

question image

Correct Answer

12

Explanation:

Since inPin = 10, the function digitalRead(inPin + 2) is the same as the function digitalRead(10 + 2) which, again, is the same as digitalRead(12).

 Finish
Question 1 of 10

Setting Input Pin Modes & Reading Digital Inputs

Incorrect

The code value = digitalRead(inPin + 2); will attempt to read which input?

question image

Your Answer

Correct Answer

12

Explanation:

Since inPin = 10, the function digitalRead(inPin + 2) is the same as the function digitalRead(10 + 2) which, again, is the same as digitalRead(12).

 Finish
Question 1 of 10
Setting Input Pin Modes & Reading Digital Inputs

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

Creative Commons License
Setting Input Pin Modes & Reading Digital Inputs by Fox Valley Technical College is licensed under a Creative Commons Attribution 3.0 Unported License.