From 412f261e41e2ff26a63876a3dd56a02917c575ef Mon Sep 17 00:00:00 2001 From: Federico Vanzati Date: Fri, 6 Apr 2012 20:00:31 +0200 Subject: [PATCH] Corretions and refinements to the String examples --- .../CharacterAnalysis/CharacterAnalysis.ino | 6 +++--- .../StringAdditionOperator.ino | 6 ++++-- .../08.Strings/StringLength/StringLength.ino | 9 +++++++-- .../StringLengthTrim/StringLengthTrim.ino | 4 ++-- build/linux/work/lib/pde.jar | Bin 401211 -> 401211 bytes .../CharacterAnalysis/CharacterAnalysis.ino | 7 +++---- .../StringAdditionOperator.ino | 8 +++++--- .../StringAppendOperator.ino | 8 +++++--- .../StringCaseChanges/StringCaseChanges.ino | 8 +++++--- .../StringCharacters/StringCharacters.ino | 6 +++--- .../StringComparisonOperators.ino | 9 ++++++--- .../StringConstructors/StringConstructors.ino | 10 ++++++---- .../StringIndexOf/StringIndexOf.ino | 9 +++++---- .../08.Strings/StringLength/StringLength.ino | 8 +++++--- .../StringLengthTrim/StringLengthTrim.ino | 8 +++++--- .../StringReplace/StringReplace.ino | 8 +++++--- .../StringStartsWithEndsWith.ino | 9 +++++---- .../StringSubstring/StringSubstring.ino | 8 +++++--- .../08.Strings/StringToInt/StringToInt.ino | 8 +++++--- .../StringToIntRGB/StringToIntRGB.ino | 12 ++++++------ 20 files changed, 90 insertions(+), 61 deletions(-) diff --git a/build/linux/work/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino b/build/linux/work/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino index ca93a1063..414d4628f 100644 --- a/build/linux/work/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino +++ b/build/linux/work/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino @@ -15,8 +15,9 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); // this check is only needed on the Leonardo: - while (!Serial) ; - ; + while (!Serial) { + ; // wait for serial port to connect. Needed fo Leonardo only + } // send an intro: Serial.println("send any byte and I'll tell you everything I can about it"); @@ -81,4 +82,3 @@ void loop() { Serial.println(); } } - diff --git a/build/linux/work/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino b/build/linux/work/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino index 9acef0e7c..a1a79e6aa 100644 --- a/build/linux/work/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino +++ b/build/linux/work/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino @@ -20,13 +20,15 @@ void setup() { // initialize serial and wait for port to open: Serial.begin(9600); // this check is only needed on the Leonardo: - while (!Serial) ; - ; + while (!Serial) { + ; // wait for serial port to connect. Needed fo Leonardo only + } stringOne = String("stringThree = "); stringTwo = String("this string"); stringThree = String (); Serial.println("\n\nAdding strings together (concatenation):"); + Serial.println(); } void loop() { diff --git a/build/linux/work/examples/08.Strings/StringLength/StringLength.ino b/build/linux/work/examples/08.Strings/StringLength/StringLength.ino index a83b6b562..260175357 100644 --- a/build/linux/work/examples/08.Strings/StringLength/StringLength.ino +++ b/build/linux/work/examples/08.Strings/StringLength/StringLength.ino @@ -15,8 +15,13 @@ String txtMsg = ""; // a string for incoming text int lastStringLength = txtMsg.length(); // previous length of the String void setup() { - // open the serial port: + // Open serial communications and wait for port to open: Serial.begin(9600); + // this check is only needed on the Leonardo: + while (!Serial) ; + ; + + Serial.println("\n\nString length():"); } void loop() { @@ -40,4 +45,4 @@ void loop() { // note the length for next time through the loop: lastStringLength = txtMsg.length(); } -} \ No newline at end of file +} diff --git a/build/linux/work/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino b/build/linux/work/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino index aa49ed0b9..42ffb5a0d 100644 --- a/build/linux/work/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino +++ b/build/linux/work/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino @@ -13,11 +13,11 @@ */ void setup() { - // Open serial communications and wait for port to open: + // Open serial communications and wait for port to open: Serial.begin(9600); // this check is only needed on the Leonardo: while (!Serial) ; - ; + ; Serial.println("\n\nString length() and trim():"); } diff --git a/build/linux/work/lib/pde.jar b/build/linux/work/lib/pde.jar index 951ae43c15002f14c48d20213e643e877a44e1e2..36c8c093eb176aa7d969d8d85ae6ef781958703c 100644 GIT binary patch delta 82 zcmdnJPh$5z37!CNW)?061`Y-Wwx)?ZnoO)sjpnW9j9bl_G_--7_C#$aAZ7+)mhFk! ftjW`v*qWvvJH%=Ul-$mEnDw+eh;i-}Ypw|Zh^QC+ delta 82 zcmdnJPh$5z37!CNW)?061`Y;>XQ>l;G?|{JHk!AZGj26!($EHS+7q>zfS4JGS+*x? fvnEexdX_r<*dbO+pyYPO!>p&(L5y>+SaVGPF!>yh diff --git a/build/shared/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino b/build/shared/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino index ca93a1063..085c8344f 100644 --- a/build/shared/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino +++ b/build/shared/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino @@ -14,9 +14,9 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - // this check is only needed on the Leonardo: - while (!Serial) ; - ; + while (!Serial) { + ; // wait for serial port to connect. Needed fo Leonardo only + } // send an intro: Serial.println("send any byte and I'll tell you everything I can about it"); @@ -81,4 +81,3 @@ void loop() { Serial.println(); } } - diff --git a/build/shared/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino b/build/shared/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino index 9acef0e7c..d7c2c4493 100644 --- a/build/shared/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino +++ b/build/shared/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino @@ -19,14 +19,16 @@ String stringOne, stringTwo, stringThree; void setup() { // initialize serial and wait for port to open: Serial.begin(9600); - // this check is only needed on the Leonardo: - while (!Serial) ; - ; + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } stringOne = String("stringThree = "); stringTwo = String("this string"); stringThree = String (); + // send an intro: Serial.println("\n\nAdding strings together (concatenation):"); + Serial.println(); } void loop() { diff --git a/build/shared/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino b/build/shared/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino index 1776c06f2..b7eb12230 100644 --- a/build/shared/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino +++ b/build/shared/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino @@ -16,13 +16,15 @@ String stringOne, stringTwo; void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - // this check is only needed on the Leonardo: - while (!Serial) ; - ; + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } stringOne = String("Sensor "); stringTwo = String("value"); + // send an intro: Serial.println("\n\nAppending to a string:"); + Serial.println(); } void loop() { diff --git a/build/shared/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino b/build/shared/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino index cdccb53c4..675ab8e19 100644 --- a/build/shared/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino +++ b/build/shared/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino @@ -15,11 +15,13 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - // this check is only needed on the Leonardo: - while (!Serial) ; - ; + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + // send an intro: Serial.println("\n\nString case changes:"); + Serial.println(); } void loop() { diff --git a/build/shared/examples/08.Strings/StringCharacters/StringCharacters.ino b/build/shared/examples/08.Strings/StringCharacters/StringCharacters.ino index d7d27e7bc..06e9e3e53 100644 --- a/build/shared/examples/08.Strings/StringCharacters/StringCharacters.ino +++ b/build/shared/examples/08.Strings/StringCharacters/StringCharacters.ino @@ -15,9 +15,9 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - // this check is only needed on the Leonardo: - while (!Serial) ; - ; + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } Serial.println("\n\nString charAt() and setCharAt():"); } diff --git a/build/shared/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino b/build/shared/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino index 742a6ad94..dc468ee4e 100644 --- a/build/shared/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino +++ b/build/shared/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino @@ -17,13 +17,16 @@ String stringOne, stringTwo; void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - // this check is only needed on the Leonardo: - while (!Serial) ; - ; + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + stringOne = String("this"); stringTwo = String("that"); + // send an intro: Serial.println("\n\nComparing Strings:"); + Serial.println(); } diff --git a/build/shared/examples/08.Strings/StringConstructors/StringConstructors.ino b/build/shared/examples/08.Strings/StringConstructors/StringConstructors.ino index aa67c5aa2..d823cda10 100644 --- a/build/shared/examples/08.Strings/StringConstructors/StringConstructors.ino +++ b/build/shared/examples/08.Strings/StringConstructors/StringConstructors.ino @@ -15,11 +15,13 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - // this check is only needed on the Leonardo: - while (!Serial) ; - ; - + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + + // send an intro: Serial.println("\n\nString Constructors:"); + Serial.println(); } void loop() { diff --git a/build/shared/examples/08.Strings/StringIndexOf/StringIndexOf.ino b/build/shared/examples/08.Strings/StringIndexOf/StringIndexOf.ino index 76d0d1bf6..b943c1639 100644 --- a/build/shared/examples/08.Strings/StringIndexOf/StringIndexOf.ino +++ b/build/shared/examples/08.Strings/StringIndexOf/StringIndexOf.ino @@ -15,12 +15,13 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - // this check is only needed on the Leonardo: - while (!Serial) ; - ; + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + // send an intro: Serial.println("\n\nString indexOf() and lastIndexOf() functions:"); - + Serial.println(); } void loop() { diff --git a/build/shared/examples/08.Strings/StringLength/StringLength.ino b/build/shared/examples/08.Strings/StringLength/StringLength.ino index 260175357..ea9793b43 100644 --- a/build/shared/examples/08.Strings/StringLength/StringLength.ino +++ b/build/shared/examples/08.Strings/StringLength/StringLength.ino @@ -17,11 +17,13 @@ int lastStringLength = txtMsg.length(); // previous length of the String void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - // this check is only needed on the Leonardo: - while (!Serial) ; - ; + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + // send an intro: Serial.println("\n\nString length():"); + Serial.ptintln(); } void loop() { diff --git a/build/shared/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino b/build/shared/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino index 42ffb5a0d..8f7009248 100644 --- a/build/shared/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino +++ b/build/shared/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino @@ -15,11 +15,13 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - // this check is only needed on the Leonardo: - while (!Serial) ; - ; + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + // send an intro: Serial.println("\n\nString length() and trim():"); + Serial.println(); } void loop() { diff --git a/build/shared/examples/08.Strings/StringReplace/StringReplace.ino b/build/shared/examples/08.Strings/StringReplace/StringReplace.ino index cf41527c7..b5e39dc38 100644 --- a/build/shared/examples/08.Strings/StringReplace/StringReplace.ino +++ b/build/shared/examples/08.Strings/StringReplace/StringReplace.ino @@ -15,11 +15,13 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - // this check is only needed on the Leonardo: - while (!Serial) ; - ; + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + // send an intro: Serial.println("\n\nString replace:\n"); + Serial.println(); } void loop() { diff --git a/build/shared/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino b/build/shared/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino index 9ec6e6eb7..b2509e56d 100644 --- a/build/shared/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino +++ b/build/shared/examples/08.Strings/StringStartsWithEndsWith/StringStartsWithEndsWith.ino @@ -15,12 +15,13 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - // this check is only needed on the Leonardo: - while (!Serial) ; - ; + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + // send an intro: Serial.println("\n\nString startsWith() and endsWith():"); - + Serial.println(); } void loop() { diff --git a/build/shared/examples/08.Strings/StringSubstring/StringSubstring.ino b/build/shared/examples/08.Strings/StringSubstring/StringSubstring.ino index e6353a5ba..4d6cff0fd 100644 --- a/build/shared/examples/08.Strings/StringSubstring/StringSubstring.ino +++ b/build/shared/examples/08.Strings/StringSubstring/StringSubstring.ino @@ -15,11 +15,13 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - // this check is only needed on the Leonardo: - while (!Serial) ; - ; + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + // send an intro: Serial.println("\n\nString substring():"); + Serial.println(); } void loop() { diff --git a/build/shared/examples/08.Strings/StringToInt/StringToInt.ino b/build/shared/examples/08.Strings/StringToInt/StringToInt.ino index 5864829dd..68b96cec5 100644 --- a/build/shared/examples/08.Strings/StringToInt/StringToInt.ino +++ b/build/shared/examples/08.Strings/StringToInt/StringToInt.ino @@ -18,11 +18,13 @@ String inString = ""; // string to hold input void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - // this check is only needed on the Leonardo: - while (!Serial) ; - ; + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + // send an intro: Serial.println("\n\nString toInt():"); + Serial.println(); } void loop() { diff --git a/build/shared/examples/08.Strings/StringToIntRGB/StringToIntRGB.ino b/build/shared/examples/08.Strings/StringToIntRGB/StringToIntRGB.ino index 289209877..9f1658fd5 100644 --- a/build/shared/examples/08.Strings/StringToIntRGB/StringToIntRGB.ino +++ b/build/shared/examples/08.Strings/StringToIntRGB/StringToIntRGB.ino @@ -27,11 +27,13 @@ int red, green, blue = 0; void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); - // this check is only needed on the Leonardo: - while (!Serial) ; - ; + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + // send an intro: Serial.println("\n\nString toInt() RGB:"); + Serial.println(); // set LED cathode pins as outputs: pinMode(9, OUTPUT); pinMode(10, OUTPUT); @@ -99,7 +101,6 @@ void loop() { inString = ""; // reset the color counter: currentColor = 0; - } } @@ -221,8 +222,7 @@ Here's a Processing sketch that will draw a color wheel and send a serial myPort.write(colorString ); } - - */ +*/