Which Arduino function returns the amount of time since the board started running?
millis()
What are the 3 sections in a for loop called?
Initialization, Condition, Update
Which type of loop is best to use when you know exactly how many times something should repeat?
For loop
If the button is NOT being pressed, what will happen after this section of code:
do{
digitalWrite(led, HIGH);
} while (digitalRead(button) == HIGH);
LED will turn on. (do while loops will always run once)
Find the error in the code below:
if(digitalRead(button) == HIGH){
motor.write(90)
delay(1000)
motor.write(180)
}
No semicolons were used
What variable type is used to hold a millis() value?
unsigned long
What operator checks if two values are equal?
==
Which type of loop is best when a program should continue running until a button is pressed?
While loop
What will the serial monitor say when this loop is finished running:
for(int i = 0; i < 5; i+=2){
Serial.println(i);
}
6
(First loop i = 0, second loop i = 2, third loop i = 4, fourth loop i = 6 which makes the condition false ending the loop)
Find the error in the code below:
for(int i = 0, i < 10, i++){
Used commas instead of semicolons to separate the sections of the for loop.
What unit of measurement represents the resistance in a circuit?
ohms
What is the correct format of a while loop?
while(condition){
//code to repeat
}
Which loop type is guaranteed to run at least once every time, regardless of whether a condition is met?
Do while loop
What will the LED look like if this is the void loop section of the code:
void loop(){
digitalWrite(led, LOW);
delay(1000);
digitalWrite(led, HIGH);
}
LED will be off
(No delay after digitalWrite(HIGH);)
Find the error in the code below:
while(brightness > 50){
tone(buzzer, HIGH);
delay(250);
noTone(buzzer);
}
Buzzers need to be set to a frequency rather than written high.
tone(buzzer, 200);
What does the != operator mean?
Not equal to
How would you create an infinite loop?
Write a loop without updates/condition being re-checked
When would you check the millis() if you wanted to turn an LED on 5 seconds after a button is pressed?
Once when the button is pressed, and another time in the loop (constant).
How many times will the LED blink:
while(x<10){
digitalWrite(LED, HIGH);
delay(100);
digitalWrite(LED, LOW);
delay(100);
x = x + 2;
}
5 times
(x = x + 2 add 2 to the x variable each loop)
Find the error in the code below:
do (temp < 50){
digitalWrite(LED, HIGH);
} while;
do {
digitalWrite(LED, HIGH);
} while (temp < 50);
What is the main difference between long and unsigned long?
Unsigned long only holds positive large numbers. (Long holds both + and -)
What is the correct formatting of a do-while loop?
do{
//code to repeat
} while (condition);
What error would someone make to create an infinite loop?
Make a condition that is always true.
What will be printed to the serial monitor after this code runs?
if(digitalRead(button) == HIGH){
number = 31;
Serial.println("number");
}
The word "number"
Find the error in the code below:
while(x < 10){
x = 0;
motor.write(45);
delay(200);
motor.write(100);
delay(200);
x ++;
}
The condition is always true, making an infinite loop.