Printing Numbers
Part of the First Circuits section of Coddy's Arduino journey. Lesson 9 of 22.
Serial.println() prints numbers too. Without quotes, the board works the sum out first and prints the answer:
Serial.println(2 + 3); // prints 5
Serial.println("2 + 3"); // prints 2 + 3In quotes, 2 + 3 is five characters of text. Without quotes, it is a calculation.
To multiply, use *, not x. Put text and a result on one line with print() first:
Serial.print("Hours in a week: ");
Serial.println(7 * 24); // Hours in a week: 168Challenge
EasyIn setup(), print two lines, letting the board do the maths:
12 * 12 = 144, where the board works out the 144 from12 * 12- the number of minutes in a day, worked out with
24 * 60
Press Run, then Check.
Try it yourself
void setup() {
Serial.begin(9600);
// print 12 * 12 = 144, then the minutes in a day
}
void loop() {
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in First Circuits
2Talking to Your Computer
Hello, Serial MonitorPrint Versus PrintlnPrinting NumbersYour First VariableCounting UpWhen an Int Runs OutPractice on your own: Arduino playground