http://www.lulu.com/items/volume_63/1108000/1108699/4/print/ARDUINO_NOTEBOOKv6.pdf
The below program is based on the things that I learned in the PDF document page 1 to 15.
Discovery : "Array", which can store values, is very useful.
This program light the led that connected to the digital pin #13 for 0.01 second 5 times and send a message back to the computer.
Requirement
Arduino + LED (If you use digital pin 13 and have a proper LED)
or
Arduino + LED + resister and wires(same as picture below)
Program
/*
This is a program that to show thigs that I learned from
http://www.lulu.com/items/volume_63/1108000/1108699/4/print/ARDUINO_NOTEBOOKv6.pdf Page 1 to 15
I am going to include commend as much as possible.
*/
/*
This is a block comment. I can write any thing in this section.
*/
// This is also comment. line comment
//list of variables
int variable;//integer that declares variables. most commonly used. 16bit 32,767 to -32,768.
int abc, def, ghi; // variables can take this form
int pin=13; // and also it can take this form
int y = 1;
byte b; //8 bit 0-255
long l; //32 bit 2,147,483,647 to -2,147,483,648
float f; //32 bit 3.4028235E+38 to -3.4028235E+38
double dob; // other form of varable for floating decimal
char ch; // also other form of variable. char has a different function from int
int delayValA[ ]={10, 3000, 5000}; //arrays that can stor the values
void setup()
{ //defines the starting point of function
Serial.begin(9600); // setup connection speed 9600 is good for my arduino
// very important. if you do not get respond from Arduino it must be because of this command
//void setup is the first function of the program
pinMode(pin, OUTPUT); // sets the 0pin as out put
}//defines the ending point of function
void loop()
{
for (int i=1; i<=5;) // this variable works only in the for loop
{
i++; // increment. there is many increment and decrement such as -- ++ *=
Serial.println(i);
digitalWrite(pin,HIGH);//send high signal(1)to the pin
delay(delayValA[1]); // delay the commend
digitalWrite(pin,LOW);//send low signal(0)to the pin
delay(delayValA[2] + 1000); //arithmetic works like this
digitalWrite(pin,HIGH);//send high signal(1)to the pin
delay(delayValA[1]); // delay the commend
digitalWrite(pin,LOW);//send low signal(0)to the pin
delay(delayValA[2] + 1000); //arithmetic works like this
}
Serial. println("out of for loop "); //println is use for send a message from Arduino
delay(delayValA[3] + 2000);
}
Actually, the PDF does not explain "for" commend and it is not easily understandable.
This link is useful to learn about For commend.
http://arduino.cc/en/Reference/For
for ( variable initialize; test; additional information)
for ( int i =0; i<10;>
Hardware setup
Experiment movie
0 件のコメント:
コメントを投稿