The learner will review code and answer questions about the digitalWrite, delay, and PinMode functions.

Setting Output Pin Modes & Writing to Digital Outputs

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

int ledPin = 1;

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

void main()
{
   digitalWrite(ledPin, HIGH);
   delay(1000);
   digitalWrite(ledPin, LOW);
   delay(1000);
}

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 Output Pin Modes & Writing to Digital Outputs

Correct!

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

int ledPin = 1;

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

void main()
{
   digitalWrite(ledPin, HIGH);
   delay(1000);
   digitalWrite(ledPin, LOW);
   delay(1000);
}

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 Output Pin Modes & Writing to Digital Outputs

Incorrect

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

int ledPin = 1;

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

void main()
{
   digitalWrite(ledPin, HIGH);
   delay(1000);
   digitalWrite(ledPin, LOW);
   delay(1000);
}

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 Output Pin Modes & Writing to Digital Outputs

What type of variable is ledPin?

Question Image
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

Correct!

What type of variable is ledPin?

question image

Correct Answer

integer

Explanation:

On the first line of code we have int ledPin = 1; thus ledPin is an int type, which is short for integer.

 Next Question
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

Incorrect

What type of variable is ledPin?

question image

Your Answer

Correct Answer

integer

Explanation:

On the first line of code we have int ledPin = 1; thus ledPin is an int type, which is short for integer.

 Next Question
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

Which output pin will be accessed?

Question Image
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

Correct!

Which output pin will be accessed?

question image

Correct Answer

1

Explanation:

The digitalWrite function accesses the pin with number ledPin (both times it is called).  Since, from line one, ledPin = 1, digitalWrite accesses pin 1.

 Next Question
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

Incorrect

Which output pin will be accessed?

question image

Your Answer

Correct Answer

1

Explanation:

The digitalWrite function accesses the pin with number ledPin (both times it is called).  Since, from line one, ledPin = 1, digitalWrite accesses pin 1.

 Next Question
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

Can the variable ledPin be assigned a negative value?

Question Image
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

Correct!

Can the variable ledPin be assigned a negative value?

question image

Correct Answer

Yes

Explanation:

Since ledPin is an integer, it can have a negative value assigned to it.

 Next Question
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

Incorrect

Can the variable ledPin be assigned a negative value?

question image

Your Answer

Correct Answer

Yes

Explanation:

Since ledPin is an integer, it can have a negative value assigned to it.

 Next Question
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

In the main function, what does the line digitalWrite(ledPin, HIGH); do?

Question Image
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

Correct!

In the main function, what does the line digitalWrite(ledPin, HIGH); do?

question image

Correct Answer

sets output 1 high

Explanation:

The digitalWrite function takes two arguments.  The first argument, which is ledPin here, says what pin to write to.  In this case, since ledPin = 1, it writes to pin 1.  The second argument, which is HIGH here, says what to write, in this case it writes HIGH.

 Next Question
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

Incorrect

In the main function, what does the line digitalWrite(ledPin, HIGH); do?

question image

Your Answer

Correct Answer

sets output 1 high

Explanation:

The digitalWrite function takes two arguments.  The first argument, which is ledPin here, says what pin to write to.  In this case, since ledPin = 1, it writes to pin 1.  The second argument, which is HIGH here, says what to write, in this case it writes HIGH.

 Next Question
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

What would happen if the line digitalWrite(HIGH, ledpin); was executed in the main function of this program?

Question Image
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

Correct!

What would happen if the line digitalWrite(HIGH, ledpin); was executed in the main function of this program?

question image

Correct Answer

It would set output 1 to high.

Explanation:

Here we have to remember that the value HIGH is the same as 1.  Also recall we set ledPin to 1.  Thus the call of digitalWrite(HIGH, ledPin) is the same as digitalWrite(1, 1), which would write to pin 1 (the first argument) the value of 1 or HIGH (the second argument).

 Next Question
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

Incorrect

What would happen if the line digitalWrite(HIGH, ledpin); was executed in the main function of this program?

question image

Your Answer

Correct Answer

It would set output 1 to high.

Explanation:

Here we have to remember that the value HIGH is the same as 1.  Also recall we set ledPin to 1.  Thus the call of digitalWrite(HIGH, ledPin) is the same as digitalWrite(1, 1), which would write to pin 1 (the first argument) the value of 1 or HIGH (the second argument).

 Next Question
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

What would the following code try to do if it was executed in the body of the main function?  digitalWrite(ledpin + 2, LOW);

Question Image
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

Correct!

What would the following code try to do if it was executed in the body of the main function?  digitalWrite(ledpin + 2, LOW);

question image

Correct Answer

set output 3 low

Explanation:

The digitalWrite function will try to set "ledPin + 2" to "LOW".  We set ledPin = 1, so ledPin + 2 = 3.  Thus digitalWrite(ledPin + 2, LOW); is the same as digitalWrite(3, LOW); and it will try to set output 3 to LOW.

 Next Question
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

Incorrect

What would the following code try to do if it was executed in the body of the main function?  digitalWrite(ledpin + 2, LOW);

question image

Your Answer

Correct Answer

set output 3 low

Explanation:

The digitalWrite function will try to set "ledPin + 2" to "LOW".  We set ledPin = 1, so ledPin + 2 = 3.  Thus digitalWrite(ledPin + 2, LOW); is the same as digitalWrite(3, LOW); and it will try to set output 3 to LOW.

 Next Question
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

How long of a time delay would delay(2500); produce?

Question Image
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

Correct!

How long of a time delay would delay(2500); produce?

question image

Correct Answer

2.5 seconds

Explanation:

Recall the delay function has one argument and it pauses the program for that many milliseconds.  Thus a delay(2500); will pause the program for 2.5 seconds.

 Next Question
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

Incorrect

How long of a time delay would delay(2500); produce?

question image

Your Answer

Correct Answer

2.5 seconds

Explanation:

Recall the delay function has one argument and it pauses the program for that many milliseconds.  Thus a delay(2500); will pause the program for 2.5 seconds.

 Next Question
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

How long of a time delay would delay(100); produce?

Question Image
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

Correct!

How long of a time delay would delay(100); produce?

question image

Correct Answer

all of the above

Explanation:

delay(100); will certainly pause the program for 100 milliseconds.  But the other times given are also equal to 100 milliseconds, so all of the above is correct.

 Next Question
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

Incorrect

How long of a time delay would delay(100); produce?

question image

Your Answer

Correct Answer

all of the above

Explanation:

delay(100); will certainly pause the program for 100 milliseconds.  But the other times given are also equal to 100 milliseconds, so all of the above is correct.

 Next Question
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

True or False: Instead of int, we could have set ledPin to be of type float.

Question Image
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

Correct!

True or False: Instead of int, we could have set ledPin to be of type float.

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, like pinMode and digitalWrite.

 Next Question
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

Incorrect

True or False: Instead of int, we could have set ledPin to be of type float.

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, like pinMode and digitalWrite.

 Next Question
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

True or False: This program turns 2 different LEDs on and off.

Question Image
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

Correct!

True or False: This program turns 2 different LEDs on and off.

question image

Correct Answer

False

Explanation:

This program only affects pin 1.

 Finish
Question 1 of 10

Setting Output Pin Modes & Writing to Digital Outputs

Incorrect

True or False: This program turns 2 different LEDs on and off.

question image

Your Answer

Correct Answer

False

Explanation:

This program only affects pin 1.

 Finish
Question 1 of 10
Setting Output Pin Modes & Writing to Digital Outputs

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 Output Pin Modes & Writing to Digital Outputs by Fox Valley Technical College is licensed under a Creative Commons Attribution 3.0 Unported License.