2019年1月10日 星期四

Week13_05160664

Week13

1.
從Processing的範例程Libraries>Serial>SimpleRead的程式碼,複製裡面的48行到62行到Arduino裡。
2.

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

void setup() {
  pinMode(switchPin, INPUT);             // Set pin 0 as an input
  pinMode(2,INPUT_PULLUP);//MakerUNO有一個按鈕,在pin2,會自動拉高
  Serial.begin(9600);                    // Start serial communication at 9600 bps
}

void loop() {
  if (digitalRead(2) == 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
}

沒有留言:

張貼留言