- Find this text in two lines of the Blink code: delay(1000);
- Change the text from "delay(1000);" to "delay(500);" in both lines of code.
STEM Connections
Writing code is essential if computers are to make equipment such as an LED blink and machines function. All the text in computer code must be written correctly into order for the code to work properly. Similarly, some words and some letters must be capitalized, and semicolons and commas must be used in the proper places. These rules for how the text must be written in computer code is known as syntax. Syntax varies from one computer programming language to another. It takes time to learn the syntax of a new programming language.
Delay is another function in the Blink code. Changing the number in the delay function changes the rate that the LED blinks. The number in the delay function is measured in milliseconds. There are 1,000 milliseconds in 1 second. Changing the number in the parentheses from 1000 to 500 will change the delay from 1000 milliseconds (or 1 second) to 500 milliseconds (or half a second). Any positive whole number can be used in the delay function. Since there are two delay functions in the code, different whole numbers can be used in the two delay functions.
At the Thinkabit Lab, we emphasize that students need make sure they upload their code when they change the delay by doing the following:
- Ask the students: “What do you have to change to make the LED blink faster?”
Answer: Change the value in the delay.
- Ask students to think about whether they need to increase the number or decrease the number in the delay to make the LED blink faster.
Answer: Decrease the delay.
- Remind the students to be careful when changing their delay by showing them the two examples below:
- Show them what happens when you try to upload code with a missing ‘;’ or a missing ‘)’.
- Change the value for the delay and before you upload, ask students why the LED didn’t change its blinking rate. Students should answer that you forgot to upload.
If you are using the Thinkabit Lab Notebook:
Have students write their answer on page 14 for the question:
What value can you change in the code to make the LED blink faster? make the delay value smaller
“error compiling”
- Try clicking ‘upload’ again
“problem uploading to board”
- Be sure the port is connected to the right COM#
- Unplug and re-plug the USB cable (possibly using a different USB port if another one is available).
- Disconnect all wires from Arduino board, unplug and re-plug USB cable, close all Arduino windows and open Blink code, and upload again.
“expected ‘ ) ‘ before ‘;’ token”
- Notice that it highlights the area the has a problem.
- Here, it identifies that you’re missing a parenthesis somewhere. Double check all parenthesis and make sure that each has its match.
- Use Ctrl+Z to undo any changes that you made to the code and start over.
“expected ‘;’ before ‘delay’ ”
- Notice it highlights the area the problem is in.
- You’re missing a ‘;’ after a line of code. Check each line! Add the missing ‘;’ at the end of the line.
- Use Ctrl+Z to undo any changes that you made to the code and start over.