User Tools

Site Tools


tutorials:learn:arduino:lesson2.html

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tutorials:learn:arduino:lesson2.html [2010/10/20 21:45]
daigo
tutorials:learn:arduino:lesson2.html [2016/01/28 18:05] (current)
Line 80: Line 80:
 <code C>int ledPin = 13;                // LED connected to digital pin 13</​code>​ <code C>int ledPin = 13;                // LED connected to digital pin 13</​code>​
  
-This is the first line of actual instruction code. It is also extremely unlike English (or any other human language). The first part we can easily understand is the part to the right, which is also a comment. Turns out if you want to make a small comment, you can use **%%//%%** as well as /* */. // is often used for short, one line comments.+This is the first line of actual instruction code. It is also extremely unlike English (or any other human language). The first part we can easily understand is the part to the right, which is also a comment. Turns out if you want to make a small comment, you can use **%%//%%** as well as /* */. %%//%% is often used for short, one line comments.
  
  
  
-The rest of the line, the stuff before the //, is what is called a **statement**,​ which is basically like a computerized sentence. Much like human sentances end with a . (period), all computer sentences end with a ; (semicolon)+The rest of the line, the stuff before the %%//%%, is what is called a **statement**,​ which is basically like a computerized sentence. Much like human sentances end with a . (period), all computer sentences end with a ; (semicolon)
  
  
Line 94: Line 94:
 |int|ledPin|=|13 | |int|ledPin|=|13 |
  \\ The first part of this sentence is **int**, which is short for **integer** which is a fancy way of saying whole number ​ \\ The second part of this sentence is **ledPin** which is the name of the box \\ The third part is an =, which basically says that the variable (box) named ledPin should start out equaling whatever is after the = \\ The fourth part is 13, a whole number (integer) which is assigned to **ledPin** \\   \\ The first part of this sentence is **int**, which is short for **integer** which is a fancy way of saying whole number ​ \\ The second part of this sentence is **ledPin** which is the name of the box \\ The third part is an =, which basically says that the variable (box) named ledPin should start out equaling whatever is after the = \\ The fourth part is 13, a whole number (integer) which is assigned to **ledPin** \\ 
 +
 ==== Procedures ​ ==== ==== Procedures ​ ====
  
Line 105: Line 106:
 }</​code>​ }</​code>​
  
-OK we've got two comments, each starting with //. We understand comments already so lets skip that. \\ We also see in the middle there is a statement, we know its a statement because it ends with a **;** (semicolon) however there'​s a whole bunch more stuff before and after it. \\ This bunch of code is an example of a **procedure**,​ a procedure is a collection of statements, its used to group statements together so that we can refer to them all with one name. Its just like a procedure that we use to perform a task step by step.+OK we've got two comments, each starting with %%//%%. We understand comments already so lets skip that. \\ We also see in the middle there is a statement, we know its a statement because it ends with a **;** (semicolon) however there'​s a whole bunch more stuff before and after it. \\ This bunch of code is an example of a **procedure**,​ a procedure is a collection of statements, its used to group statements together so that we can refer to them all with one name. Its just like a procedure that we use to perform a task step by step. 
  
-   +^**returned value**^**procedure name**^(input values)^**{ statements }**|
-^**returned value **^**procedure name**^(input values) ^**{ statements } **^|+
 |void|setup|()|{ pinMode(ledPin,​ OUTPUT); }| |void|setup|()|{ pinMode(ledPin,​ OUTPUT); }|
  
Line 233: Line 234:
  
  
-**Exercise 2.  \\ Modify the code so that the light is on for 50 msec and off for 50 msec. What happens? ** \\ //Highlight the text below to see the answer // \\ Intense strobe action!+**Exercise 2.  \\ Modify the code so that the light is on for 50 msec and off for 50 msec. What happens? ** \\ //Highlight the text below to see the answer // \\ <class white>Intense strobe action!</​class>​
  
  
  
-**Exercise 3.** ** \\ Modify the code so that the light is on for 10 ms and off for 10 ms. What happens?** \\ //Highlight the text below to see the answer ​       // \\ The light is no longer blinking+**Exercise 3.** ** \\ Modify the code so that the light is on for 10 ms and off for 10 ms. What happens?** \\ //Highlight the text below to see the answer ​       // \\ <class white>The light is no longer blinking</​class>​
  
  
  
-**Now pick up the Arduino and gently wave it back and forth, in a dark room. What happens?** \\ //Highlight the text below to see the answer //         \\ The LED creates a dashed trail of light in the air. z+**Now pick up the Arduino and gently wave it back and forth, in a dark room. What happens?** \\ //Highlight the text below to see the answer //         ​\\ ​<class white>The LED creates a dashed trail of light in the air.</​class>​
  
  
  
-**What do you think is happening here? \\ **//​Highlight the text below to see the answer //**         ​\\ ​**The LED is blinking, but its blinking so fast that our eyes can't pick it up, so it looks like a blur. When the Arduino is waved in the air, we see streaks of light from the blinks.+**What do you think is happening here? \\ **//​Highlight the text below to see the answer //**         ​\\ ​ 
 +<class white>The LED is blinking, but its blinking so fast that our eyes can't pick it up, so it looks like a blur. When the Arduino is waved in the air, we see streaks of light from the blinks.</​class>​
  
  
/home/ladyada/public_html/wiki/data/attic/tutorials/learn/arduino/lesson2.html.1287611140.txt.gz · Last modified: 2016/01/28 18:05 (external edit)