13
13
*/
14
14
15
15
void setup () {
16
+ // Open serial communications and wait for port to open:
16
17
Serial.begin (9600 );
18
+ // this check is only needed on the Leonardo:
19
+ while (!Serial) ;
20
+ ;
21
+
22
+ Serial.println (" \n\n String Constructors:" );
17
23
}
18
24
19
25
void loop () {
20
- // using a constant String:
21
- String stringOne = " Hello String" ;
22
- Serial.println (stringOne); // prints "Hello String"
26
+ // using a constant String:
27
+ String stringOne = " Hello String" ;
28
+ Serial.println (stringOne); // prints "Hello String"
29
+
30
+ // converting a constant char into a String:
31
+ stringOne = String (' a' );
32
+ Serial.println (stringOne); // prints "a"
23
33
24
- // converting a constant char into a String:
25
- stringOne = String (' a ' );
26
- Serial.println (stringOne ); // prints "a "
34
+ // converting a constant string into a String object :
35
+ String stringTwo = String (" This is a string " );
36
+ Serial.println (stringTwo ); // prints "This is a string "
27
37
28
- // converting a constant string into a String object:
29
- String stringTwo = String (" This is a string" );
30
- Serial.println (stringTwo); // prints "This is a string"
38
+ // concatenating two strings:
39
+ stringOne = String (stringTwo + " with more" );
40
+ // prints "This is a string with more":
41
+ Serial.println (stringOne);
31
42
32
- // concatenating two strings:
33
- stringOne = String (stringTwo + " with more" );
34
- // prints "This is a string with more":
35
- Serial.println (stringOne);
43
+ // using a constant integer:
44
+ stringOne = String (13 );
45
+ Serial.println (stringOne); // prints "13"
36
46
37
- // using a constant integer:
38
- stringOne = String (13 );
39
- Serial.println (stringOne); // prints "13"
40
-
41
- // using an int and a base:
42
- stringOne = String (analogRead (A0), DEC);
43
- // prints "453" or whatever the value of analogRead(A0) is
44
- Serial.println (stringOne);
47
+ // using an int and a base:
48
+ stringOne = String (analogRead (A0), DEC);
49
+ // prints "453" or whatever the value of analogRead(A0) is
50
+ Serial.println (stringOne);
45
51
46
- // using an int and a base (hexadecimal):
47
- stringOne = String (45 , HEX);
48
- // prints "2d", which is the hexadecimal version of decimal 45:
49
- Serial.println (stringOne);
52
+ // using an int and a base (hexadecimal):
53
+ stringOne = String (45 , HEX);
54
+ // prints "2d", which is the hexadecimal version of decimal 45:
55
+ Serial.println (stringOne);
50
56
51
- // using an int and a base (binary)
52
- stringOne = String (255 , BIN);
53
- // prints "11111111" which is the binary value of 255
54
- Serial.println (stringOne);
55
-
56
- // using a long and a base:
57
- stringOne = String (millis (), DEC);
58
- // prints "123456" or whatever the value of millis() is:
59
- Serial.println (stringOne);
57
+ // using an int and a base (binary)
58
+ stringOne = String (255 , BIN);
59
+ // prints "11111111" which is the binary value of 255
60
+ Serial.println (stringOne);
61
+
62
+ // using a long and a base:
63
+ stringOne = String (millis (), DEC);
64
+ // prints "123456" or whatever the value of millis() is:
65
+ Serial.println (stringOne);
60
66
61
67
// do nothing while true:
62
68
while (true );
63
69
64
- }
70
+ }
0 commit comments