LED

PowenKo > Hardware > Arduino > LED on/off onboard

February 7, 2012   ·   0 Comments

LED閃爍語法:(轉載原官方網站上的程式碼,網址如下:www.arduino.cc/en/Tutorial/BlinkingLED)

/* Blinking LED
* ————
*
* turns on and off a light emitting diode(LED) connected to a digital 
* pin, in intervals of 2 seconds. Ideally we use pin 13 on the Arduino 
* board because it has a resistor attached to it, needing only an LED

*
* Created 1 June 2005
* copyleft 2005 DojoDave <http://www.0j0.org>
* http://arduino.berlios.de
*
* based on an orginal by H. Barragan for the Wiring i/o board
*/

int ledPin = 13;             // 這裡設定所要閃爍的LED燈腳位

void setup()
{
pinMode(ledPin, OUTPUT);     // 這裡設定所要輸出的PIN腳模式,OUTPUT = 輸出4V電壓
}

void loop()
{
digitalWrite(ledPin, HIGH);  // 設定PIN13腳位為高電位 = 4V
delay(1000);                 // 設定延遲時間,1000 = 1秒
digitalWrite(ledPin, LOW);   // 設定PIN13腳位為低電位 = 0V
delay(1000);                 // 設定延遲時間
}

由以上的範例可以製作出讓PIN13的腳位輸出一個每隔1秒鐘就產生高電位的閃爍效果。

shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Hardware22

Hardware

Amazon

adsbygoogle

Recent Posts

Categories

Amazon