首先先到官方網站或至商店、購物網買 Arduino 或入門套件,因為本身非電子相關本科系出身,所以線插的有點亂。
然後開始準備開發環境,Arduino 官方網站下載免費IDE。安裝完畢後就可開始準備玩了。
網路上有許多高手,可參考大家所分享的範例,以這case為例,下列網址提供大家參考:
1.http://coopermaa2nd.blogspot.tw/2010/12/arduino-lab2-led.html
2.http://ming-shian.blogspot.tw/p/arduino.html
| 完成測試圖 |
Code
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
沒有留言:
張貼留言