Mar 31, 2020

[Arduino code] the output of Serial.write() and Serial.print() (아두이노에서의 시리얼 모니터 출력 예시)

- Check the output result of Serial.write(val) and Serial.print(val) functions according to data types.
(자료형에 따른 Serial.write(val)와 Serial.print(val) 함수의 출력결과 확인)
 : In the case of Serial.write(val), the character corresponding to the ASCII code of val is output regardless of the data type of val.
(Serial.write(val)의 경우 val의 자료형에 상관없이 val의 아스키코드에 해당하는 문자를 출력)
 : Use Serial.write(val) function for characters, and Serial.print(val) function for numbers.

unsigned int bd_rate = 9600;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(bd_rate);
  Serial.println("Serial START");
}

void loop() {
  // put your main code here, to run repeatedly:
  char X = 97;
  int Y = 97;
  Serial.print("X: "); Serial.print(X);Serial.print("\t"); Serial.write(X); Serial.println();
  Serial.print("Y: "); Serial.print(Y); Serial.print("\t"); Serial.write(Y); Serial.println();
  delay(1000);
}
<Snap shot of Arduino serial moniter>

No comments:

Post a Comment