As a result, we’ll see 100 200 on the serial monitor. To display these values on the serial monitor, we use Serial.print(first) to print the first value, and then Serial.print("\t") to add a tab character for formatting, followed by Serial.print(second) to display the second value. Afterward, we set up serial communication using Serial.begin(9600). In this Arduino code, we define two integer variables, first and second, and assign them values of 100 and 200, respectively. It’s a simple example of using the Serial.print() function for basic output to assist in debugging and monitoring your Arduino program.Ĭonsider another example where we want to print a floating-point number on the serial monitor up to two decimal places. This sketch primarily focuses on demonstrating how to send data (in this case, the integer value) to the serial monitor during the setup phase. The loop() function is empty in this example so that it won’t execute any specific tasks repeatedly. Next, we use Serial.print(myInteger) to send the value of the myInteger variable to the serial monitor, and this means that the number 10 will be displayed in the serial monitor when the program starts. Then, we set up serial communication using Serial.begin(9600), establishing a connection with a baud rate of 9600 bits per second. We declare an integer variable named myInteger and set it to the value 10. In this Arduino code, we have a setup() function where we initialize the program.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |