Last active
December 22, 2021 17:25
-
-
Save Park-Developer/16e41b05ce7a9c7aa148f97f0d405c68 to your computer and use it in GitHub Desktop.
Arduino : serial example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setup() { | |
// initialize digital pin 13 as an output. | |
pinMode(13, OUTPUT); | |
Serial.begin(9600); | |
} | |
// the loop function runs over and over again forever | |
void loop() { | |
String msg = ""; | |
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) | |
delay(1000); // wait for a second | |
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW | |
delay(1000); // wait for a second | |
if(Serial.available()) // Serial.available() : Get the number of bytes (characters) available for reading from the serial port. This is data that’s already arrived and stored in the serial receive buffer (which holds 64 bytes). | |
{ | |
msg = Serial.readString(); // Serial.readString() : Serial.readString() reads characters from the serial buffer into a String. The function terminates if it times out (see setTimeout()). | |
Serial.println("aryud"+msg); // Serial.println() : Prints data to the serial port as human-readable ASCII text followed by a carriage return character (ASCII 13, or '\r') and a newline character (ASCII 10, or '\n'). This command takes the same forms as Serial.print(). | |
} | |
} | |
//출처: https://micropilot.tistory.com/2869 [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment