week13
開啟範例檔:
測試: 開啟序列阜監控室窗測試
會發現,按住按鈕開關視窗會顯示"0",放開會顯示"1"
void loop() {
//read the pushbutton value into a variable
int sensorVal = digitalRead(2);
//print out the value of the pushbutton
Serial.println(sensorVal);
// Keep in mind the pullup means the pushbutton's
// logic is inverted. It goes HIGH when it's open,
// and LOW when it's pressed. Turn on pin 13 when the
// button's pressed, and off when it's not:
if (sensorVal == HIGH) {
digitalWrite(13, LOW);
} else {
digitalWrite(13, HIGH);
}
}
Processing與Arduino做結合
開啟Processing的Arduino控制範例檔案
int sensorVal = digitalRead(2);
//print out the value of the pushbutton
Serial.println(sensorVal);
// Keep in mind the pullup means the pushbutton's
// logic is inverted. It goes HIGH when it's open,
// and LOW when it's pressed. Turn on pin 13 when the
// button's pressed, and off when it's not:
if (sensorVal == HIGH) {
digitalWrite(13, LOW);
} else {
digitalWrite(13, HIGH);
}
}
Processing與Arduino做結合
開啟Processing的Arduino控制範例檔案
改Processing的 portName 跟 ARDUINO的序列阜一樣
再把Processing的Arduino Code for loop() copy 到 Arduino 裡面 ,並且把 switchPin
改成"2" (因為pinMode(2, INPUT_PULLUP);是2)
沒有留言:
張貼留言