From bde00b9be931cf9f90d31928aec8b9dc7f40e1f0 Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Mon, 9 Apr 2012 10:48:11 -0400 Subject: [PATCH] Added delays to some serial examples to avoid crashing the serial monitor. --- .../examples/02.Digital/toneKeyboard/toneKeyboard.ino | 3 +-- .../02.Digital/tonePitchFollower/tonePitchFollower.ino | 4 ++-- .../03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino | 6 +++--- build/shared/examples/03.Analog/Smoothing/Smoothing.ino | 7 ++++--- build/shared/examples/04.Communication/Graph/Graph.ino | 4 ++-- .../SerialCallResponse/SerialCallResponse.ino | 6 +++++- .../IfStatementConditional/IfStatementConditional.ino | 4 ++-- build/shared/examples/05.Control/switchCase/switchCase.ino | 7 ++++--- .../08.Strings/CharacterAnalysis/CharacterAnalysis.ino | 2 +- 9 files changed, 24 insertions(+), 19 deletions(-) diff --git a/build/shared/examples/02.Digital/toneKeyboard/toneKeyboard.ino b/build/shared/examples/02.Digital/toneKeyboard/toneKeyboard.ino index 9decdd752..8521f8ab6 100644 --- a/build/shared/examples/02.Digital/toneKeyboard/toneKeyboard.ino +++ b/build/shared/examples/02.Digital/toneKeyboard/toneKeyboard.ino @@ -9,7 +9,7 @@ * 8-ohm speaker on digital pin 8 created 21 Jan 2010 - modified 30 Aug 2011 + modified 9 Apr 2012 by Tom Igoe This example code is in the public domain. @@ -41,5 +41,4 @@ void loop() { tone(8, notes[thisSensor], 20); } } - Serial.println(); } diff --git a/build/shared/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino b/build/shared/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino index beb28b2bd..2bdf0df26 100644 --- a/build/shared/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino +++ b/build/shared/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino @@ -9,7 +9,7 @@ * 4.7K resistor on analog 0 to ground created 21 Jan 2010 - modified 30 Aug 2011 + modified 9 Apr 2012 by Tom Igoe This example code is in the public domain. @@ -36,7 +36,7 @@ void loop() { // play the pitch: tone(9, thisPitch, 10); - + delay(1); // delay in between reads for stability } diff --git a/build/shared/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino b/build/shared/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino index e142f690e..a16f7eb2a 100644 --- a/build/shared/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino +++ b/build/shared/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino @@ -12,7 +12,7 @@ * LED connected from digital pin 9 to ground created 29 Dec. 2008 - modified 30 Aug 2011 + modified 9 Apr 2012 by Tom Igoe This example code is in the public domain. @@ -46,8 +46,8 @@ void loop() { Serial.print("\t output = "); Serial.println(outputValue); - // wait 10 milliseconds before the next loop + // wait 2 milliseconds before the next loop // for the analog-to-digital converter to settle // after the last reading: - delay(10); + delay(2); } diff --git a/build/shared/examples/03.Analog/Smoothing/Smoothing.ino b/build/shared/examples/03.Analog/Smoothing/Smoothing.ino index e33a0dd16..cf6935de3 100644 --- a/build/shared/examples/03.Analog/Smoothing/Smoothing.ino +++ b/build/shared/examples/03.Analog/Smoothing/Smoothing.ino @@ -10,9 +10,9 @@ * Analog sensor (potentiometer will do) attached to analog input 0 Created 22 April 2007 - modified 30 Aug 2011 By David A. Mellis - + modified 9 Apr 2012 + by Tom Igoe http://www.arduino.cc/en/Tutorial/Smoothing This example code is in the public domain. @@ -61,7 +61,8 @@ void loop() { // calculate the average: average = total / numReadings; // send it to the computer as ASCII digits - Serial.println(average); + Serial.println(average); + delay(1); // delay in between reads for stability } diff --git a/build/shared/examples/04.Communication/Graph/Graph.ino b/build/shared/examples/04.Communication/Graph/Graph.ino index 92256ab00..c2e4637b6 100644 --- a/build/shared/examples/04.Communication/Graph/Graph.ino +++ b/build/shared/examples/04.Communication/Graph/Graph.ino @@ -18,7 +18,7 @@ created 2006 by David A. Mellis - modified 30 Aug 2011 + modified 9 Apr 2012 by Tom Igoe and Scott Fitzgerald This example code is in the public domain. @@ -36,7 +36,7 @@ void loop() { Serial.println(analogRead(A0)); // wait a bit for the analog-to-digital converter // to stabilize after the last reading: - delay(10); + delay(2); } /* Processing code for this example diff --git a/build/shared/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino b/build/shared/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino index e15031e8b..03e34317b 100644 --- a/build/shared/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino +++ b/build/shared/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino @@ -15,7 +15,7 @@ Created 26 Sept. 2005 by Tom Igoe - modified 30 Aug 2011 + modified 9 Apr 2012 by Tom Igoe and Scott Fitzgerald This example code is in the public domain. @@ -33,6 +33,10 @@ void setup() { // start serial port at 9600 bps: Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + pinMode(2, INPUT); // digital sensor is on digital pin 2 establishContact(); // send a byte to establish contact until receiver responds } diff --git a/build/shared/examples/05.Control/IfStatementConditional/IfStatementConditional.ino b/build/shared/examples/05.Control/IfStatementConditional/IfStatementConditional.ino index 8346f2cbb..e6c18017a 100644 --- a/build/shared/examples/05.Control/IfStatementConditional/IfStatementConditional.ino +++ b/build/shared/examples/05.Control/IfStatementConditional/IfStatementConditional.ino @@ -16,7 +16,7 @@ connected to pin 13, so you don't need any extra components for this example. created 17 Jan 2009 - modified 30 Aug 2011 + modified 9 Apr 2012 by Tom Igoe This example code is in the public domain. @@ -51,6 +51,6 @@ void loop() { // print the analog value: Serial.println(analogValue); - + delay(1); // delay in between reads for stability } diff --git a/build/shared/examples/05.Control/switchCase/switchCase.ino b/build/shared/examples/05.Control/switchCase/switchCase.ino index 87eb3f340..93004b3de 100644 --- a/build/shared/examples/05.Control/switchCase/switchCase.ino +++ b/build/shared/examples/05.Control/switchCase/switchCase.ino @@ -14,7 +14,7 @@ * 10K resistor from analog in 0 to ground created 1 Jul 2009 - modified 30 Aug 2011 + modified 9 Apr 2012 by Tom Igoe This example code is in the public domain. @@ -22,7 +22,8 @@ http://www.arduino.cc/en/Tutorial/SwitchCase */ -// these constants won't change: +// these constants won't change. They are the +// lowest and highest readings you get from your sensor: const int sensorMin = 0; // sensor minimum, discovered through experiment const int sensorMax = 600; // sensor maximum, discovered through experiment @@ -53,7 +54,7 @@ void loop() { Serial.println("bright"); break; } - + delay(1); // delay in between reads for stability } diff --git a/build/shared/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino b/build/shared/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino index 085c8344f..b640403b0 100644 --- a/build/shared/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino +++ b/build/shared/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino @@ -15,7 +15,7 @@ void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { - ; // wait for serial port to connect. Needed fo Leonardo only + ; // wait for serial port to connect. Needed for Leonardo only } // send an intro: