下記のページで、RS232通信(シリアル通信)を紹介させて頂きました。
その相手側となる装置をArduinoを使用して作成しようと思います。使用したArduinoはArduino LEONARDOです。
PC側に文字を送信したい場合のコードは下記のようになります。
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
Serial.setTimeout(3000);
}
// the loop routine runs over and over again forever:
void loop() {
Serial.println("OK");
}
PC側から文字を受信したい場合のコードは下記のようになります。
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
Serial.setTimeout(3000);
}
// the loop routine runs over and over again forever:
void loop() {
String strRev = "";
if(Serial.available() > 0){
strRev = Serial.readStringUntil('¥r');
if(strRev == "Send"){
digitalWrite(13, HIGH);
}
}
}