mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-03 14:24:15 +01:00
Use a consistent number of spaces after punctuation in the comments of the built-in examples
This commit is contained in:
parent
e3044a5f5a
commit
2570383db9
@ -2,7 +2,7 @@
|
|||||||
Blink without Delay
|
Blink without Delay
|
||||||
|
|
||||||
Turns on and off a light emitting diode (LED) connected to a digital
|
Turns on and off a light emitting diode (LED) connected to a digital
|
||||||
pin, without using the delay() function. This means that other code
|
pin, without using the delay() function. This means that other code
|
||||||
can run at the same time without being interrupted by the LED code.
|
can run at the same time without being interrupted by the LED code.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
Debounce
|
Debounce
|
||||||
|
|
||||||
Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
|
Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
|
||||||
press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's
|
press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's
|
||||||
a minimum delay between toggles to debounce the circuit (i.e. to ignore
|
a minimum delay between toggles to debounce the circuit (i.e. to ignore
|
||||||
noise).
|
noise).
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ void loop() {
|
|||||||
// set the LED:
|
// set the LED:
|
||||||
digitalWrite(ledPin, ledState);
|
digitalWrite(ledPin, ledState);
|
||||||
|
|
||||||
// save the reading. Next time through the loop,
|
// save the reading. Next time through the loop,
|
||||||
// it'll be the lastButtonState:
|
// it'll be the lastButtonState:
|
||||||
lastButtonState = reading;
|
lastButtonState = reading;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
Often, you don't need to know the state of a digital input all the time,
|
Often, you don't need to know the state of a digital input all the time,
|
||||||
but you just need to know when the input changes from one state to another.
|
but you just need to know when the input changes from one state to another.
|
||||||
For example, you want to know when a button goes from OFF to ON. This is called
|
For example, you want to know when a button goes from OFF to ON. This is called
|
||||||
state change detection, or edge detection.
|
state change detection, or edge detection.
|
||||||
|
|
||||||
This example shows how to detect when a button or button changes from off to on
|
This example shows how to detect when a button or button changes from off to on
|
||||||
@ -55,7 +55,7 @@ void loop() {
|
|||||||
// went from off to on:
|
// went from off to on:
|
||||||
buttonPushCounter++;
|
buttonPushCounter++;
|
||||||
Serial.println("on");
|
Serial.println("on");
|
||||||
Serial.print("number of button pushes: ");
|
Serial.print("number of button pushes: ");
|
||||||
Serial.println(buttonPushCounter);
|
Serial.println(buttonPushCounter);
|
||||||
} else {
|
} else {
|
||||||
// if the current state is LOW then the button
|
// if the current state is LOW then the button
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
http://www.arduino.cc/en/Tutorial/AnalogInOutSerial
|
http://www.arduino.cc/en/Tutorial/AnalogInOutSerial
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// These constants won't change. They're used to give names
|
// These constants won't change. They're used to give names
|
||||||
// to the pins used:
|
// to the pins used:
|
||||||
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
|
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
|
||||||
const int analogOutPin = 9; // Analog output pin that the LED is attached to
|
const int analogOutPin = 9; // Analog output pin that the LED is attached to
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
http://www.arduino.cc/en/Tutorial/AnalogWriteMega
|
http://www.arduino.cc/en/Tutorial/AnalogWriteMega
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// These constants won't change. They're used to give names
|
// These constants won't change. They're used to give names
|
||||||
// to the pins used:
|
// to the pins used:
|
||||||
const int lowestPin = 2;
|
const int lowestPin = 2;
|
||||||
const int highestPin = 13;
|
const int highestPin = 13;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Calibration
|
Calibration
|
||||||
|
|
||||||
Demonstrates one technique for calibrating sensor input. The
|
Demonstrates one technique for calibrating sensor input. The
|
||||||
sensor readings during the first five seconds of the sketch
|
sensor readings during the first five seconds of the sketch
|
||||||
execution define the minimum and maximum of expected values
|
execution define the minimum and maximum of expected values
|
||||||
attached to the sensor pin.
|
attached to the sensor pin.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
Smoothing
|
Smoothing
|
||||||
|
|
||||||
Reads repeatedly from an analog input, calculating a running average
|
Reads repeatedly from an analog input, calculating a running average
|
||||||
and printing it to the computer. Keeps ten readings in an array and
|
and printing it to the computer. Keeps ten readings in an array and
|
||||||
continually averages them.
|
continually averages them.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
@ -18,9 +18,9 @@
|
|||||||
http://www.arduino.cc/en/Tutorial/Smoothing
|
http://www.arduino.cc/en/Tutorial/Smoothing
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Define the number of samples to keep track of. The higher the number,
|
// Define the number of samples to keep track of. The higher the number,
|
||||||
// the more the readings will be smoothed, but the slower the output will
|
// the more the readings will be smoothed, but the slower the output will
|
||||||
// respond to the input. Using a constant rather than a normal variable lets
|
// respond to the input. Using a constant rather than a normal variable lets
|
||||||
// us use this value to determine the size of the readings array.
|
// us use this value to determine the size of the readings array.
|
||||||
const int numReadings = 10;
|
const int numReadings = 10;
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII
|
For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII
|
||||||
|
|
||||||
The circuit: No external hardware needed.
|
The circuit: No external hardware needed.
|
||||||
|
|
||||||
created 2006
|
created 2006
|
||||||
by Nicholas Zambetti <http://www.zambetti.com>
|
by Nicholas Zambetti <http://www.zambetti.com>
|
||||||
@ -39,7 +39,7 @@ int thisByte = 33;
|
|||||||
void loop() {
|
void loop() {
|
||||||
// prints value unaltered, i.e. the raw binary version of the
|
// prints value unaltered, i.e. the raw binary version of the
|
||||||
// byte. The Serial Monitor interprets all bytes as
|
// byte. The Serial Monitor interprets all bytes as
|
||||||
// ASCII, so 33, the first number, will show up as '!'
|
// ASCII, so 33, the first number, will show up as '!'
|
||||||
Serial.write(thisByte);
|
Serial.write(thisByte);
|
||||||
|
|
||||||
Serial.print(", dec: ");
|
Serial.print(", dec: ");
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
Dimmer
|
Dimmer
|
||||||
|
|
||||||
Demonstrates sending data from the computer to the Arduino board,
|
Demonstrates sending data from the computer to the Arduino board,
|
||||||
in this case to control the brightness of an LED. The data is sent
|
in this case to control the brightness of an LED. The data is sent
|
||||||
in individual bytes, each of which ranges from 0 to 255. Arduino
|
in individual bytes, each of which ranges from 0 to 255. Arduino
|
||||||
reads these bytes and uses them to set the brightness of the LED.
|
reads these bytes and uses them to set the brightness of the LED.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
@ -56,9 +56,9 @@ void loop() {
|
|||||||
// if using Processing 2.1 or later, use Serial.printArray()
|
// if using Processing 2.1 or later, use Serial.printArray()
|
||||||
println(Serial.list());
|
println(Serial.list());
|
||||||
|
|
||||||
// Uses the first port in this list (number 0). Change this to
|
// Uses the first port in this list (number 0). Change this to
|
||||||
// select the port corresponding to your Arduino board. The last
|
// select the port corresponding to your Arduino board. The last
|
||||||
// parameter (e.g. 9600) is the speed of the communication. It
|
// parameter (e.g. 9600) is the speed of the communication. It
|
||||||
// has to correspond to the value passed to Serial.begin() in your
|
// has to correspond to the value passed to Serial.begin() in your
|
||||||
// Arduino sketch.
|
// Arduino sketch.
|
||||||
port = new Serial(this, Serial.list()[0], 9600);
|
port = new Serial(this, Serial.list()[0], 9600);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
Graph
|
Graph
|
||||||
|
|
||||||
A simple example of communication from the Arduino board to the computer:
|
A simple example of communication from the Arduino board to the computer:
|
||||||
the value of analog input 0 is sent out the serial port. We call this "serial"
|
the value of analog input 0 is sent out the serial port. We call this "serial"
|
||||||
communication because the connection appears to both the Arduino and the
|
communication because the connection appears to both the Arduino and the
|
||||||
computer as a serial port, even though it may actually use
|
computer as a serial port, even though it may actually use
|
||||||
a USB cable. Bytes are sent one after another (serially) from the Arduino
|
a USB cable. Bytes are sent one after another (serially) from the Arduino
|
||||||
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
You can use the Arduino Serial Monitor to view the sent data, or it can
|
You can use the Arduino Serial Monitor to view the sent data, or it can
|
||||||
be read by Processing, PD, Max/MSP, or any other program capable of reading
|
be read by Processing, PD, Max/MSP, or any other program capable of reading
|
||||||
data from a serial port. The Processing code below graphs the data received
|
data from a serial port. The Processing code below graphs the data received
|
||||||
so you can see the value of the analog input changing over time.
|
so you can see the value of the analog input changing over time.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
|
@ -37,7 +37,7 @@ void loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// plays a MIDI note. Doesn't check to see that
|
// plays a MIDI note. Doesn't check to see that
|
||||||
// cmd is greater than 127, or that data values are less than 127:
|
// cmd is greater than 127, or that data values are less than 127:
|
||||||
void noteOn(int cmd, int pitch, int velocity) {
|
void noteOn(int cmd, int pitch, int velocity) {
|
||||||
Serial.write(cmd);
|
Serial.write(cmd);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
Physical Pixel
|
Physical Pixel
|
||||||
|
|
||||||
An example of using the Arduino board to receive data from the
|
An example of using the Arduino board to receive data from the
|
||||||
computer. In this case, the Arduino boards turns on an LED when
|
computer. In this case, the Arduino boards turns on an LED when
|
||||||
it receives the character 'H', and turns off the LED when it
|
it receives the character 'H', and turns off the LED when it
|
||||||
receives the character 'L'.
|
receives the character 'L'.
|
||||||
|
|
||||||
|
@ -41,9 +41,9 @@ void loop() {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
SerialEvent occurs whenever a new data comes in the
|
SerialEvent occurs whenever a new data comes in the
|
||||||
hardware serial RX. This routine is run between each
|
hardware serial RX. This routine is run between each
|
||||||
time loop() runs, so using delay inside loop can delay
|
time loop() runs, so using delay inside loop can delay
|
||||||
response. Multiple bytes of data may be available.
|
response. Multiple bytes of data may be available.
|
||||||
*/
|
*/
|
||||||
void serialEvent() {
|
void serialEvent() {
|
||||||
while (Serial.available()) {
|
while (Serial.available()) {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
Switch statement
|
Switch statement
|
||||||
|
|
||||||
Demonstrates the use of a switch statement. The switch
|
Demonstrates the use of a switch statement. The switch
|
||||||
statement allows you to choose from among a set of discrete values
|
statement allows you to choose from among a set of discrete values
|
||||||
of a variable. It's like a series of if statements.
|
of a variable. It's like a series of if statements.
|
||||||
|
|
||||||
To see this sketch in action, put the board and sensor in a well-lit
|
To see this sketch in action, put the board and sensor in a well-lit
|
||||||
room, open the Serial Monitor, and move your hand gradually down
|
room, open the Serial Monitor, and move your hand gradually down
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
Switch statement with serial input
|
Switch statement with serial input
|
||||||
|
|
||||||
Demonstrates the use of a switch statement. The switch
|
Demonstrates the use of a switch statement. The switch
|
||||||
statement allows you to choose from among a set of discrete values
|
statement allows you to choose from among a set of discrete values
|
||||||
of a variable. It's like a series of if statements.
|
of a variable. It's like a series of if statements.
|
||||||
|
|
||||||
To see this sketch in action, open the Serial monitor and send any character.
|
To see this sketch in action, open the Serial monitor and send any character.
|
||||||
The characters a, b, c, d, and e, will turn on LEDs. Any other character will turn
|
The characters a, b, c, d, and e, will turn on LEDs. Any other character will turn
|
||||||
the LEDs off.
|
the LEDs off.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
@ -36,7 +36,7 @@ void loop() {
|
|||||||
// do something different depending on the character received.
|
// do something different depending on the character received.
|
||||||
// The switch statement expects single number values for each case;
|
// The switch statement expects single number values for each case;
|
||||||
// in this example, though, you're using single quotes to tell
|
// in this example, though, you're using single quotes to tell
|
||||||
// the controller to get the ASCII value for the character. For
|
// the controller to get the ASCII value for the character. For
|
||||||
// example 'a' = 97, 'b' = 98, and so forth:
|
// example 'a' = 97, 'b' = 98, and so forth:
|
||||||
|
|
||||||
switch (inByte) {
|
switch (inByte) {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
ADXL3xx
|
ADXL3xx
|
||||||
|
|
||||||
Reads an Analog Devices ADXL3xx accelerometer and communicates the
|
Reads an Analog Devices ADXL3xx accelerometer and communicates the
|
||||||
acceleration to the computer. The pins used are designed to be easily
|
acceleration to the computer. The pins used are designed to be easily
|
||||||
compatible with the breakout boards from SparkFun, available from:
|
compatible with the breakout boards from SparkFun, available from:
|
||||||
http://www.sparkfun.com/commerce/categories.php?c=80
|
http://www.sparkfun.com/commerce/categories.php?c=80
|
||||||
|
|
||||||
@ -36,8 +36,8 @@ void setup() {
|
|||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
// Provide ground and power by using the analog inputs as normal
|
// Provide ground and power by using the analog inputs as normal
|
||||||
// digital pins. This makes it possible to directly connect the
|
// digital pins. This makes it possible to directly connect the
|
||||||
// breakout board to the Arduino. If you use the normal 5V and
|
// breakout board to the Arduino. If you use the normal 5V and
|
||||||
// GND pins on the Arduino, you can remove these lines.
|
// GND pins on the Arduino, you can remove these lines.
|
||||||
pinMode(groundpin, OUTPUT);
|
pinMode(groundpin, OUTPUT);
|
||||||
pinMode(powerpin, OUTPUT);
|
pinMode(powerpin, OUTPUT);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Memsic2125
|
Memsic2125
|
||||||
|
|
||||||
Read the Memsic 2125 two-axis accelerometer. Converts the
|
Read the Memsic 2125 two-axis accelerometer. Converts the
|
||||||
pulses output by the 2125 into milli-g's (1/1000 of Earth's
|
pulses output by the 2125 into milli-g's (1/1000 of Earth's
|
||||||
gravity) and prints them over the serial connection to the
|
gravity) and prints them over the serial connection to the
|
||||||
computer.
|
computer.
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
This sketch reads a PING))) ultrasonic rangefinder and returns the
|
This sketch reads a PING))) ultrasonic rangefinder and returns the
|
||||||
distance to the closest object in range. To do this, it sends a pulse
|
distance to the closest object in range. To do this, it sends a pulse
|
||||||
to the sensor to initiate a reading, then listens for a pulse
|
to the sensor to initiate a reading, then listens for a pulse
|
||||||
to return. The length of the returning pulse is proportional to
|
to return. The length of the returning pulse is proportional to
|
||||||
the distance of the object from the sensor.
|
the distance of the object from the sensor.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
@ -22,7 +22,7 @@
|
|||||||
http://www.arduino.cc/en/Tutorial/Ping
|
http://www.arduino.cc/en/Tutorial/Ping
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// this constant won't change. It's the pin number
|
// this constant won't change. It's the pin number
|
||||||
// of the sensor's output:
|
// of the sensor's output:
|
||||||
const int pingPin = 7;
|
const int pingPin = 7;
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ void loop() {
|
|||||||
long microsecondsToInches(long microseconds) {
|
long microsecondsToInches(long microseconds) {
|
||||||
// According to Parallax's datasheet for the PING))), there are
|
// According to Parallax's datasheet for the PING))), there are
|
||||||
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
|
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
|
||||||
// second). This gives the distance travelled by the ping, outbound
|
// second). This gives the distance travelled by the ping, outbound
|
||||||
// and return, so we divide by 2 to get the distance of the obstacle.
|
// and return, so we divide by 2 to get the distance of the obstacle.
|
||||||
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
|
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
|
||||||
return microseconds / 74 / 2;
|
return microseconds / 74 / 2;
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
The mouse movement is always relative. This sketch reads
|
The mouse movement is always relative. This sketch reads
|
||||||
four pushbuttons, and uses them to set the movement of the mouse.
|
four pushbuttons, and uses them to set the movement of the mouse.
|
||||||
|
|
||||||
WARNING: When you use the Mouse.move() command, the Arduino takes
|
WARNING: When you use the Mouse.move() command, the Arduino takes
|
||||||
over your mouse! Make sure you have control before you use the mouse commands.
|
over your mouse! Make sure you have control before you use the mouse commands.
|
||||||
|
|
||||||
created 15 Mar 2012
|
created 15 Mar 2012
|
||||||
modified 27 Mar 2012
|
modified 27 Mar 2012
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
The mouse movement is always relative. This sketch reads
|
The mouse movement is always relative. This sketch reads
|
||||||
four pushbuttons, and uses them to set the movement of the mouse.
|
four pushbuttons, and uses them to set the movement of the mouse.
|
||||||
|
|
||||||
WARNING: When you use the Mouse.move() command, the Arduino takes
|
WARNING: When you use the Mouse.move() command, the Arduino takes
|
||||||
over your mouse! Make sure you have control before you use the mouse commands.
|
over your mouse! Make sure you have control before you use the mouse commands.
|
||||||
|
|
||||||
created 15 Mar 2012
|
created 15 Mar 2012
|
||||||
modified 27 Mar 2012
|
modified 27 Mar 2012
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
The sketch assumes that the joystick resting values are around the
|
The sketch assumes that the joystick resting values are around the
|
||||||
middle of the range, but that they vary within a threshold.
|
middle of the range, but that they vary within a threshold.
|
||||||
|
|
||||||
WARNING: When you use the Mouse.move() command, the Arduino takes
|
WARNING: When you use the Mouse.move() command, the Arduino takes
|
||||||
over your mouse! Make sure you have control before you use the command.
|
over your mouse! Make sure you have control before you use the command.
|
||||||
This sketch includes a pushbutton to toggle the mouse control state, so
|
This sketch includes a pushbutton to toggle the mouse control state, so
|
||||||
you can turn on and off mouse control.
|
you can turn on and off mouse control.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user