EasyManua.ls Logo

Elegoo Mega2560 - Page 174

Elegoo Mega2560
224 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
174
/
223
The next two lines write back a confirmation message to the Serial Monitor.
Serial.print("Turned on LED ");
Serial.println(led);
The first line uses Serial.print rather than Serial.println. The different between the
two is that Serial.print does not start a new line after printing whatever is in its
parameter. We use this in the first line, because we are printing the message in two
parts. Firstly the general bit: 'Turned on LED ' and then the number of the LED.
The number of the LED is held in an 'int' variable rather than being a text string.
Serial.print can take either a text string enclosed in double-quotes, or an 'int' or for
that matter pretty much any type of variable.
After the 'if' statement that handles the case, when a single digit has been handled,
there is a second 'if' statement that checks to see if 'ch' is the letter 'x'.
if (ch == 'x')
{
leds = 0;
updateShiftRegister();
Serial.println("Cleared");
}
If it is, then it clears all the LEDs and sends a confirmation message.

Table of Contents