The learner will review code and answer questions about the digitalWrite, delay, and PinMode functions.
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.
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.
Got it!
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.
Got it!
What type of variable is ledPin?
integer
On the first line of code we have int ledPin = 1; thus ledPin is an int type, which is short for integer.
What type of variable is ledPin?
integer
On the first line of code we have int ledPin = 1; thus ledPin is an int type, which is short for integer.
Which output pin will be accessed?
1
The digitalWrite function accesses the pin with number ledPin (both times it is called). Since, from line one, ledPin = 1, digitalWrite accesses pin 1.
Which output pin will be accessed?
1
The digitalWrite function accesses the pin with number ledPin (both times it is called). Since, from line one, ledPin = 1, digitalWrite accesses pin 1.
Can the variable ledPin be assigned a negative value?
Yes
Since ledPin is an integer, it can have a negative value assigned to it.
Can the variable ledPin be assigned a negative value?
Yes
Since ledPin is an integer, it can have a negative value assigned to it.
In the main function, what does the line digitalWrite(ledPin, HIGH); do?
In the main function, what does the line digitalWrite(ledPin, HIGH); do?
sets output 1 high
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.
In the main function, what does the line digitalWrite(ledPin, HIGH); do?
sets output 1 high
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.
What would happen if the line digitalWrite(HIGH, ledpin); was executed in the main function of this program?
What would happen if the line digitalWrite(HIGH, ledpin); was executed in the main function of this program?
It would set output 1 to high.
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).
What would happen if the line digitalWrite(HIGH, ledpin); was executed in the main function of this program?
It would set output 1 to high.
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).
What would the following code try to do if it was executed in the body of the main function? digitalWrite(ledpin + 2, LOW);
What would the following code try to do if it was executed in the body of the main function? digitalWrite(ledpin + 2, LOW);
set output 3 low
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.
What would the following code try to do if it was executed in the body of the main function? digitalWrite(ledpin + 2, LOW);
set output 3 low
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.
How long of a time delay would delay(2500); produce?
2.5 seconds
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.
How long of a time delay would delay(2500); produce?
2.5 seconds
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.
How long of a time delay would delay(100); produce?
How long of a time delay would delay(100); produce?
all of the above
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.
How long of a time delay would delay(100); produce?
all of the above
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.
True or False: Instead of int, we could have set ledPin to be of type float.
False
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.
True or False: Instead of int, we could have set ledPin to be of type float.
False
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.
True or False: This program turns 2 different LEDs on and off.
False
This program only affects pin 1.
True or False: This program turns 2 different LEDs on and off.
False
This program only affects pin 1.
You have answered 5 of 10 questions correctly.
50%