@arduino workshop

Page 124

This sends the text between the quotation marks to the Serial Monitor’s output window. You can also use Serial.println to display text and then force any following text to start on the next line: Serial.println("Arduino for Everyone!");

Displaying the Contents of Variables You can also display the contents of variables on the Serial Monitor. For example, this would display the contents of the variable results: Serial.println(results);

If the variable is a float, the display will default to two decimal places. You can specify the number of decimal places used as a number between 0 and 6 by entering a second parameter after the variable name. For example, to display the float variable results to four decimal places, you would enter the following: Serial.print(results,4);

Project #12: Displaying the Temperature in the Serial Monitor Using the hardware from Project 8, we’ll display temperature data in Celsius and Fahrenheit in the Serial Monitor window. To do this, we’ll create one function to determine the temperature values and another to display them in the Serial Monitor. Enter this code into the IDE: // Project 12 - Displaying the Temperature in the Serial Monitor float celsius = 0; float fahrenheit = 0; void setup() { Serial.begin(9600); } u void findTemps() { float voltage = 0; float sensor = 0;

Working with Functions 103


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.