LED

PowenKo > Hardware > Arduino > LED

February 7, 2012   ·   0 Comments

P1060693-s


程式碼:

/*此為利用當類比腳沒有插上線路時,預設值為1024(這蠻特別的,我以為會是0)
當有任何動作,哪怕只是一根單心線擦一下類比腳位,其值便不再為1024
以此特性簡單的做出利用水銀開關來閃爍 LED的範例*/

int ledPin = 13;   
int analogPin = 2;  
int val = 0;   
int threshold = 1; 

void setup()
{
  pinMode(ledPin, OUTPUT);   
}

void loop()
{
  val = analogRead(analogPin);   
  if (val >= threshold) {
      digitalWrite(ledPin, HIGH);   // 當水銀開關low時,led持續發亮
  } else {
     digitalWrite(ledPin, HIGH);  // 當水銀開關high時,led閃爍
     delay(300);                
     digitalWrite(ledPin, LOW);   
     delay(300);                
  }
}

裝好之後的圖:

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