2015年12月7日 星期一

02160473賴緯漢_2015互動技術概論 week13

今日作業
1.按鈕操作
先下載範例Digital->DigitalInputPullup
把版子接好











































範例檔DigitalInputPullup
























程式碼:
void setup() {
  //start serial connection
  Serial.begin(9600);
  //configure pin2 as an input and enable the internal pull-up resistor
  pinMode(2, INPUT_PULLUP);//訊號輸入2號洞
  pinMode(13, OUTPUT);

}

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);
  }
}

開啟監控視窗
工具->序列埠監控視窗
如果沒按下按鈕為1
        有按下按鈕為0
























2.processing範例檔
先開啟processing
下載範例檔Examples->Libraries->serial->SimpleRead
























把processing的loop程式碼複製到arduino取代其中的loop
把switchPin改成2














把portname改成COM4
























把arduino的程式上傳到電路板
並執行processing程式
當沒按下為灰色
    有按下為黑色

沒有留言:

張貼留言