Académique Documents
Professionnel Documents
Culture Documents
Code Lesson #2
Be careful to nish with the closing curly bracket and the usual semi-colon!
Translation!
for (int x = 0; x <100; x++) What this does is: 1. Create a variable named x with an initial value of 0 (zero) 2. Sets up a condition for an action that will keep repeating so long as x is less than 100; in other words, it will stop when x = 99. 3. Each time it loops through this statement, it will add 1 (one) to the value of x. Remember that x++ is just a shortcut for x = x +1. println (x); What this does is print the value of x to the serial monitor. The result would look like this: 0 1 2 3 4... all the way up to 99
Practice #1
Write the code that will create an array named ledPins that will access, in the following order, these pins: 0, 1, 2, 3, 2, 4, 2, 1, 3, 0, and 4. Answer on next screen!
Answer #1
int ledPins [ ] = {
0, 1, 2, 3, 2, 4, 2, 1, 3, 0, 4} ;
Practice #2
Write a line of code that turns on LED pin #3 the rst time it appears in this sequence. Answer on next screen!
Answer #2