The learner will review code and answer questions about arrays and for loops.
All the flashcards in this set deal with the following code:
int timer = 200;
int digoutPins[] = {0, 1, 2, 3, 4, 5, 6, 7};
int adifferentArray[] = {2, 5, 3, 8, 9};
char thirdArray[30];
int digoutCount = 8;
void setup()
{
for (int PinNum = 0; PinNum < digoutCount; PinNum++)
pinMode(digoutPins[PinNum], OUTPUT);
}
void main()
{
for (int PinNum = 0; PinNum < digoutCount; PinNum++)
{
digitalWrite(digoutPins[PinNum], HIGH);
delay(timer);
digitalWrite(digoutPins[PinNum], LOW);
delay(timer);
}
for (int PinNum = digoutCount - 1; PinNum >- 0; PinNum--)
{
digitalWrite(digoutPins[PinNum], HIGH);
delay(timer);
digitalWrite(digoutPins[PinNum], LOW);
delay(timer);
}
}
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 timer = 200;
int digoutPins[] = {0, 1, 2, 3, 4, 5, 6, 7};
int adifferentArray[] = {2, 5, 3, 8, 9};
char thirdArray[30];
int digoutCount = 8;
void setup()
{
for (int PinNum = 0; PinNum < digoutCount; PinNum++)
pinMode(digoutPins[PinNum], OUTPUT);
}
void main()
{
for (int PinNum = 0; PinNum < digoutCount; PinNum++)
{
digitalWrite(digoutPins[PinNum], HIGH);
delay(timer);
digitalWrite(digoutPins[PinNum], LOW);
delay(timer);
}
for (int PinNum = digoutCount - 1; PinNum >- 0; PinNum--)
{
digitalWrite(digoutPins[PinNum], HIGH);
delay(timer);
digitalWrite(digoutPins[PinNum], LOW);
delay(timer);
}
}
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 timer = 200;
int digoutPins[] = {0, 1, 2, 3, 4, 5, 6, 7};
int adifferentArray[] = {2, 5, 3, 8, 9};
char thirdArray[30];
int digoutCount = 8;
void setup()
{
for (int PinNum = 0; PinNum < digoutCount; PinNum++)
pinMode(digoutPins[PinNum], OUTPUT);
}
void main()
{
for (int PinNum = 0; PinNum < digoutCount; PinNum++)
{
digitalWrite(digoutPins[PinNum], HIGH);
delay(timer);
digitalWrite(digoutPins[PinNum], LOW);
delay(timer);
}
for (int PinNum = digoutCount - 1; PinNum >- 0; PinNum--)
{
digitalWrite(digoutPins[PinNum], HIGH);
delay(timer);
digitalWrite(digoutPins[PinNum], LOW);
delay(timer);
}
}
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!
In the for loop within the setup function, PinNum has what value at the end of the third loop iteration?
In the for loop within the setup function, PinNum has what value at the end of the third loop iteration?
2
PinNum starts that loop with a value of 0 and it is increased by one each time the loop ends. So for the first loop it is 0, for the second loop it is 1, and for the third loop it is 2. (At the beginning of the fourth loop it is incremented to three.)
In the for loop within the setup function, PinNum has what value at the end of the third loop iteration?
2
PinNum starts that loop with a value of 0 and it is increased by one each time the loop ends. So for the first loop it is 0, for the second loop it is 1, and for the third loop it is 2. (At the beginning of the fourth loop it is incremented to three.)
True or False: Digital pins 0 through 8 are set up as outputs.
False
Only pins 0 through 7 are set as outputs, the for loop in setup iterates PinNum from 0 to 7 (when it reaches 8 it stops as 8 < 8 is false). So only the pins in the 0 through 7 places in the digoutPins array are set to OUTPUT. Those pin values are 0 through 7.
True or False: Digital pins 0 through 8 are set up as outputs.
False
Only pins 0 through 7 are set as outputs, the for loop in setup iterates PinNum from 0 to 7 (when it reaches 8 it stops as 8 < 8 is false). So only the pins in the 0 through 7 places in the digoutPins array are set to OUTPUT. Those pin values are 0 through 7.
What is the value of the fourth element of the digoutPins array?
3
The digoutPins array is {0, 1, 2, 3, 4, 5, 6, 7}. Therefore, the fourth element is 3.
What is the value of the fourth element of the digoutPins array?
3
The digoutPins array is {0, 1, 2, 3, 4, 5, 6, 7}. Therefore, the fourth element is 3.
True or False: In the first for loop in the main section, PinNum varies from 0 to 8 inclusive and the digital pins 0 through 7 are written to.
True or False: In the first for loop in the main section, PinNum varies from 0 to 8 inclusive and the digital pins 0 through 7 are written to.
True
Initially PinNum is 0, and it is incremented until PinNum < digoutCount is false, which happens when PinNum is 8 (since 8 < 8 is false). For each value of PinNum in 0, 1, 2, ..., 7, we perform the digitalWrite command on digoutPins[PinNum]. As digoutPins[0] = 0, digoutPins[1] = 1, ..., digoutPins[7] = 7, we do write to each of the pins 0 through 7 in this for loop.
True or False: In the first for loop in the main section, PinNum varies from 0 to 8 inclusive and the digital pins 0 through 7 are written to.
True
Initially PinNum is 0, and it is incremented until PinNum < digoutCount is false, which happens when PinNum is 8 (since 8 < 8 is false). For each value of PinNum in 0, 1, 2, ..., 7, we perform the digitalWrite command on digoutPins[PinNum]. As digoutPins[0] = 0, digoutPins[1] = 1, ..., digoutPins[7] = 7, we do write to each of the pins 0 through 7 in this for loop.
The array values must start with the number 0.
False
The index of the first item in an array is always 0, but the values of the array can be any value (that matches the array's variable type).
The array values must start with the number 0.
False
The index of the first item in an array is always 0, but the values of the array can be any value (that matches the array's variable type).
What is the value of the fourth element of the adifferentArray array?
8
adifferentArray has values {2, 5, 3, 8, 9} so the value of the fourth element is 8.
What is the value of the fourth element of the adifferentArray array?
8
adifferentArray has values {2, 5, 3, 8, 9} so the value of the fourth element is 8.
True or False: The second element of the digoutPins array can be accessed as digoutPins[2].
True or False: The second element of the digoutPins array can be accessed as digoutPins[2].
False
digoutPins[2] will give the value of the third element of the digoutPins array since the index for an array starts at 0.
True or False: The second element of the digoutPins array can be accessed as digoutPins[2].
False
digoutPins[2] will give the value of the third element of the digoutPins array since the index for an array starts at 0.
True or False: The thirdArray array has 30 elements.
True
When it is initialized in the row char thirdArray[30]; it is set to have 30 elements.
True or False: The thirdArray array has 30 elements.
True
When it is initialized in the row char thirdArray[30]; it is set to have 30 elements.
What are the indexes of the elements in thirdArray?
0 - 29
Since thirdArray has 30 elements and the index of an array starts at 0, the indexes of the elements in thirdArray are 0, 1, 2, ..., 28, 29.
What are the indexes of the elements in thirdArray?
0 - 29
Since thirdArray has 30 elements and the index of an array starts at 0, the indexes of the elements in thirdArray are 0, 1, 2, ..., 28, 29.
What is the correct way to assign a value to an element of thirdArray?
What is the correct way to assign a value to an element of thirdArray?
thirdArray[5] = 'I';
We can assign values to elements of an array that has been initialized by using the assign operation, namely =, by referencing the index of the element we want to change like arrayname[index]. Of the given choices, only one of them has a valid index, namely thirdArray[5] = 'I';
What is the correct way to assign a value to an element of thirdArray?
thirdArray[5] = 'I';
We can assign values to elements of an array that has been initialized by using the assign operation, namely =, by referencing the index of the element we want to change like arrayname[index]. Of the given choices, only one of them has a valid index, namely thirdArray[5] = 'I';