2018年12月6日 星期四

week13


Step1:  安裝驅動


安裝成功顯示COM7


Step2:
打開processing ---> 文件 ------> 範例程序 -------> Serial ------> SimpleRead
複製到Arduino
將腳位改成pin2

**程式碼:
int switchPin = 4;                       // Switch connected to pin 4

void setup() {
  pinMode(switchPin, INPUT);             // Set pin 0 as an input
  Serial.begin(9600);                    // Start serial communication at 9600 bps
}

void loop() {
  if (digitalRead(switchPin) == HIGH) {  // If switch is ON,
    Serial.write(1);               // send 1 to Processing
  } else {                               // If the switch is not ON,
    Serial.write(0);               // send 0 to Processing
  }
  delay(100);                            // Wait 100 milliseconds
}




成功如下圖



Step3: 回到processing 改成COM7






Step4: Arduino 跟 Processing 互動




















沒有留言:

張貼留言