2010年6月7日月曜日

Exercise and tutorial

http://www.lulu.com/items/volume_63/1108000/1108699/4/print/ARDUINO_NOTEBOOKv6.pdf

This exercise is based on PDF page 29 (digital output)

The exercise in PDF was lighting up LED. I changed a program little bit so that Arduino sends back to the computer additional information.

Requirements

Arduino Kit (Arduino board, LED, resistor, wires)



Program

/*

This program is a basic test of digital output and "Serial.print".

The Arduino board will send back information of the loop counter.

*/
int pin=13; //variables. I use this variable to specify a digital pin
int counter=0; //I use this variable to count a number of loop
int delayTime = 500; //value for delay


void setup()
{
  Serial.begin(9600);  //setup serial connection speed
  pinMode(pin, OUTPUT); //setup digital pin
  Serial.println("start program"); //This message will appear one at the beginning 
}


void loop()
{

// the followings loop forever
  counter++; // Whenever loop, increment will add 1 to the "counter" variable 
  Serial.print("this is"); //It is better not to use Serial.println in hear
  Serial.print(counter); // get a value from variable
  Serial.println("time"); 
  digitalWrite(pin, HIGH); //light LED
  delay(delayTime);           //duration
  digitalWrite(pin,LOW);  //turn of LED
  delay(delayTime*2);    //duration
}



Hardware setup

The LED is connected to the resistor and digital pin 13

The program will control power supply to the LED and resistor control the amount of electrical flow.


Work picture


0 件のコメント:

コメントを投稿