PowenKo > Hardware > Arduino > analogRead

February 7, 2012   ·   0 Comments

Screen Shot 2012-02-07 at 3.21.45 PM


int potPin = 0;                // 宣告類比腳位輸入的PIN腳
int val = 0;                   // 宣告變數Val = 0

void setup() {
  Serial.begin(9600);          //設定SerialPort的速度9600 = 9600bit/s
}

void loop() {
 val = analogRead(potPin);     // 用analogRead()這個函式讀取特定腳位的數值到變數val
  Serial.print(val);           //印出數值在Serial.Monitor
  delay(150);                  //延遲讀入的時間為150ms
}

將程式上傳到Arduino之後,打開Serial Monitor ,就會看到從可變電阻上面所收到的數值,而這些數值就可以用來控制LED的閃滅,或是控制Flash的動畫影格之類的應用。

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