ตัวอย่างงานที่ใช้โปรแกรม Arduino
การเขียนโปรแกรมเบื้องต้นกับ Arduino C++ (การรับค่าจากสวิตซ์)
Code( ถ้ากดปุ่ม LED จะดับ)
int buttonPin = 2; // the number of the pushbutton pin
int ledPin = 9; // 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:
Serial.begin(9600);
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:
Serial.println("turn LED on");
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
Serial.println("turn LED off");
digitalWrite(ledPin, LOW);
}
}
อ้างอิง http://www.myarduino.net/article/8/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%80%E0%B8%82%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%81%E0%B8%81%E0%B8%A3%E0%B8%A1%E0%B9%80%E0%B8%9A%E0%B8%B7%E0%B9%89%E0%B8%AD%E0%B8%87%E0%B8%95%E0%B9%89%E0%B8%99%E0%B8%81%E0%B8%B1%E0%B8%9A-arduino-c-%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%A3%E0%B8%B1%E0%B8%9A%E0%B8%84%E0%B9%88%E0%B8%B2%E0%B8%88%E0%B8%B2%E0%B8%81%E0%B8%AA%E0%B8%A7%E0%B8%B4%E0%B8%95%E0%B8%8B%E0%B9%8C
ไม่มีความคิดเห็น:
แสดงความคิดเห็น