The learner will review code and answer questions about the pinMode, digitalWrite, and digitalRead functions.
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.
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.
Got it!
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.
Got it!
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.
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.
True
That is a valid way to declare variables.
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.
True
That is a valid way to declare variables.
True or False: A digital pin can be assigned as both an input and an output at the same time.
True or False: A digital pin can be assigned as both an input and an output at the same time.
False
A digital pin can only be one or the other at any specific time.
True or False: A digital pin can be assigned as both an input and an output at the same time.
False
A digital pin can only be one or the other at any specific time.
True or False: It would be syntactically correct to have a third function call like pinMode(ledPin, INPUT); in the setup function.
True or False: It would be syntactically correct to have a third function call like pinMode(ledPin, INPUT); in the setup function.
True
Although this would probably lead to confusion for anyone reviewing the code, the syntax of the statement is correct and the program should compile.
True or False: It would be syntactically correct to have a third function call like pinMode(ledPin, INPUT); in the setup function.
True
Although this would probably lead to confusion for anyone reviewing the code, the syntax of the statement is correct and the program should compile.
The digitalRead function in the main function reads from which pin?
10
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.
The digitalRead function in the main function reads from which pin?
10
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.
What is the result of the first two lines of code in the main function (restated below)?
value = digitalRead(inPin);
digitalWrite(ledPin, value);
What is the result of the first two lines of code in the main function (restated below)?
value = digitalRead(inPin);
digitalWrite(ledPin, value);
Pins 1 and 10 will have the same value.
Those lines of code read the value of pin 10 (since inPin = 10) and write that value to pin 1 (since ledPin = 1).
What is the result of the first two lines of code in the main function (restated below)?
value = digitalRead(inPin);
digitalWrite(ledPin, value);
Pins 1 and 10 will have the same value.
Those lines of code read the value of pin 10 (since inPin = 10) and write that value to pin 1 (since ledPin = 1).
After the program runs through one time, is the LED on or off?
Off
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.
After the program runs through one time, is the LED on or off?
Off
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.
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?
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?
No
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.
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?
No
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.
What does the code value = digitalRead(inPin); do?
What does the code value = digitalRead(inPin); do?
It assigns the variable value inPin's value
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.
What does the code value = digitalRead(inPin); do?
It assigns the variable value inPin's value
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.
True or False: The variable inPin can have a value of 1.5.
False
The variable inPin is of type int, so it can only have integer values assigned to it.
True or False: The variable inPin can have a value of 1.5.
False
The variable inPin is of type int, so it can only have integer values assigned to it.
The code value = digitalRead(inPin + 2); will attempt to read which input?
12
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).
The code value = digitalRead(inPin + 2); will attempt to read which input?
12
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).
You have answered 5 of 10 questions correctly.
50%