Indent all multi-line C style comments in built-in examples by at least two spaces

This is required for Auto Format compatibility because it has the undesirable effect of indenting only unindented contents of multi-lline comments, thus altering the relative indentation of the text.

The exception is the Max/MSP patches as I did not know whether indentation would break them.
This commit is contained in:
per1234 2017-07-14 15:30:34 -07:00 committed by Cristian Maglie
parent 499c424d59
commit 8f48433f33
73 changed files with 1240 additions and 1240 deletions

View File

@ -1,8 +1,8 @@
/*
DigitalReadSerial
Reads a digital input on pin 2, prints the result to the Serial Monitor
Reads a digital input on pin 2, prints the result to the Serial Monitor
This example code is in the public domain.
This example code is in the public domain.
*/
// digital pin 2 has a pushbutton attached to it. Give it a name:

View File

@ -1,16 +1,16 @@
/*
Fade
Fade
This example shows how to fade an LED on pin 9
using the analogWrite() function.
This example shows how to fade an LED on pin 9
using the analogWrite() function.
The analogWrite() function uses PWM, so if
you want to change the pin you're using, be
sure to use another PWM capable pin. On most
Arduino, the PWM pins are identified with
a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11.
The analogWrite() function uses PWM, so if
you want to change the pin you're using, be
sure to use another PWM capable pin. On most
Arduino, the PWM pins are identified with
a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11.
This example code is in the public domain.
This example code is in the public domain.
*/
int led = 9; // the PWM pin the LED is attached to

View File

@ -1,30 +1,30 @@
/* Blink without Delay
Turns on and off a light emitting diode (LED) connected to a digital
pin, without using the delay() function. This means that other code
can run at the same time without being interrupted by the LED code.
Turns on and off a light emitting diode (LED) connected to a digital
pin, without using the delay() function. This means that other code
can run at the same time without being interrupted by the LED code.
The circuit:
- Use the onboard LED.
- Note: Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
the correct LED pin independent of which board is used.
If you want to know what pin the on-board LED is connected to on your Arduino model, check
the Technical Specs of your board at https://www.arduino.cc/en/Main/Products
The circuit:
- Use the onboard LED.
- Note: Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
the correct LED pin independent of which board is used.
If you want to know what pin the on-board LED is connected to on your Arduino model, check
the Technical Specs of your board at https://www.arduino.cc/en/Main/Products
created 2005
by David A. Mellis
modified 8 Feb 2010
by Paul Stoffregen
modified 11 Nov 2013
by Scott Fitzgerald
modified 9 Jan 2017
by Arturo Guadalupi
created 2005
by David A. Mellis
modified 8 Feb 2010
by Paul Stoffregen
modified 11 Nov 2013
by Scott Fitzgerald
modified 9 Jan 2017
by Arturo Guadalupi
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
*/
// constants won't change. Used here to set a pin number:

View File

@ -1,27 +1,27 @@
/*
Button
Turns on and off a light emitting diode(LED) connected to digital
pin 13, when pressing a pushbutton attached to pin 2.
Turns on and off a light emitting diode(LED) connected to digital
pin 13, when pressing a pushbutton attached to pin 2.
The circuit:
- LED attached from pin 13 to ground
- pushbutton attached to pin 2 from +5V
- 10K resistor attached to pin 2 from ground
The circuit:
- LED attached from pin 13 to ground
- pushbutton attached to pin 2 from +5V
- 10K resistor attached to pin 2 from ground
- Note: on most Arduinos there is already an LED on the board
attached to pin 13.
- Note: on most Arduinos there is already an LED on the board
attached to pin 13.
created 2005
by DojoDave <http://www.0j0.org>
modified 30 Aug 2011
by Tom Igoe
created 2005
by DojoDave <http://www.0j0.org>
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Button
http://www.arduino.cc/en/Tutorial/Button
*/
// constants won't change. They're used here to

View File

@ -1,33 +1,33 @@
/*
Debounce
Debounce
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
a minimum delay between toggles to debounce the circuit (i.e. to ignore
noise).
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
a minimum delay between toggles to debounce the circuit (i.e. to ignore
noise).
The circuit:
- LED attached from pin 13 to ground
- pushbutton attached from pin 2 to +5V
- 10K resistor attached from pin 2 to ground
The circuit:
- LED attached from pin 13 to ground
- pushbutton attached from pin 2 to +5V
- 10K resistor attached from pin 2 to ground
- Note: On most Arduino boards, there is already an LED on the board
connected to pin 13, so you don't need any extra components for this example.
- Note: On most Arduino boards, there is already an LED on the board
connected to pin 13, so you don't need any extra components for this example.
created 21 November 2006
by David A. Mellis
modified 30 Aug 2011
by Limor Fried
modified 28 Dec 2012
by Mike Walters
modified 30 Aug 2016
by Arturo Guadalupi
created 21 November 2006
by David A. Mellis
modified 30 Aug 2011
by Limor Fried
modified 28 Dec 2012
by Mike Walters
modified 30 Aug 2016
by Arturo Guadalupi
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Debounce
http://www.arduino.cc/en/Tutorial/Debounce
*/
// constants won't change. They're used here to

View File

@ -1,23 +1,23 @@
/*
Input Pull-up Serial
Input Pull-up Serial
This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a
digital input on pin 2 and prints the results to the Serial Monitor.
This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a
digital input on pin 2 and prints the results to the Serial Monitor.
The circuit:
- Momentary switch attached from pin 2 to ground
- Built-in LED on pin 13
The circuit:
- Momentary switch attached from pin 2 to ground
- Built-in LED on pin 13
Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal
20K-ohm resistor is pulled to 5V. This configuration causes the input to
read HIGH when the switch is open, and LOW when it is closed.
Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal
20K-ohm resistor is pulled to 5V. This configuration causes the input to
read HIGH when the switch is open, and LOW when it is closed.
created 14 March 2012
by Scott Fitzgerald
created 14 March 2012
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/InputPullupSerial
http://www.arduino.cc/en/Tutorial/InputPullupSerial
This example code is in the public domain
This example code is in the public domain
*/

View File

@ -1,27 +1,27 @@
/*
State change detection (edge detection)
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.
For example, you want to know when a button goes from OFF to ON. This is called
state change detection, or edge detection.
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.
For example, you want to know when a button goes from OFF to ON. This is called
state change detection, or edge detection.
This example shows how to detect when a button or button changes from off to on
and on to off.
This example shows how to detect when a button or button changes from off to on
and on to off.
The circuit:
- pushbutton attached to pin 2 from +5V
- 10K resistor attached to pin 2 from ground
- LED attached from pin 13 to ground (or use the built-in LED on
most Arduino boards)
The circuit:
- pushbutton attached to pin 2 from +5V
- 10K resistor attached to pin 2 from ground
- LED attached from pin 13 to ground (or use the built-in LED on
most Arduino boards)
created 27 Sep 2005
modified 30 Aug 2011
by Tom Igoe
created 27 Sep 2005
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/ButtonStateChange
http://www.arduino.cc/en/Tutorial/ButtonStateChange
*/

View File

@ -1,20 +1,20 @@
/*
keyboard
Plays a pitch that changes based on a changing analog input
Plays a pitch that changes based on a changing analog input
circuit:
- 3 force-sensing resistors from +5V to analog in 0 through 5
- 3 10K resistors from analog in 0 through 5 to ground
- 8-ohm speaker on digital pin 8
circuit:
- 3 force-sensing resistors from +5V to analog in 0 through 5
- 3 10K resistors from analog in 0 through 5 to ground
- 8-ohm speaker on digital pin 8
created 21 Jan 2010
modified 9 Apr 2012
by Tom Igoe
created 21 Jan 2010
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Tone3
http://www.arduino.cc/en/Tutorial/Tone3
*/

View File

@ -1,18 +1,18 @@
/*
Melody
Plays a melody
Plays a melody
circuit:
- 8-ohm speaker on digital pin 8
circuit:
- 8-ohm speaker on digital pin 8
created 21 Jan 2010
modified 30 Aug 2011
by Tom Igoe
created 21 Jan 2010
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Tone
http://www.arduino.cc/en/Tutorial/Tone
*/
#include "pitches.h"

View File

@ -1,18 +1,18 @@
/*
Multiple tone player
Plays multiple tones on multiple pins in sequence
Plays multiple tones on multiple pins in sequence
circuit:
- 3 8-ohm speaker on digital pins 6, 7, and 8
circuit:
- 3 8-ohm speaker on digital pins 6, 7, and 8
created 8 March 2010
by Tom Igoe
based on a snippet from Greg Borenstein
created 8 March 2010
by Tom Igoe
based on a snippet from Greg Borenstein
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Tone4
http://www.arduino.cc/en/Tutorial/Tone4
*/

View File

@ -1,20 +1,20 @@
/*
Pitch follower
Plays a pitch that changes based on a changing analog input
Plays a pitch that changes based on a changing analog input
circuit:
- 8-ohm speaker on digital pin 9
- photoresistor on analog 0 to 5V
- 4.7K resistor on analog 0 to ground
circuit:
- 8-ohm speaker on digital pin 9
- photoresistor on analog 0 to 5V
- 4.7K resistor on analog 0 to ground
created 21 Jan 2010
modified 31 May 2012
by Tom Igoe, with suggestion from Michael Flynn
created 21 Jan 2010
modified 31 May 2012
by Tom Igoe, with suggestion from Michael Flynn
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Tone2
http://www.arduino.cc/en/Tutorial/Tone2
*/

View File

@ -1,21 +1,21 @@
/*
Analog input, analog output, serial output
Reads an analog input pin, maps the result to a range from 0 to 255
and uses the result to set the pulse width modulation (PWM) of an output pin.
Also prints the results to the Serial Monitor.
Reads an analog input pin, maps the result to a range from 0 to 255
and uses the result to set the pulse width modulation (PWM) of an output pin.
Also prints the results to the Serial Monitor.
The circuit:
- potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
- LED connected from digital pin 9 to ground
The circuit:
- potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
- LED connected from digital pin 9 to ground
created 29 Dec. 2008
modified 9 Apr 2012
by Tom Igoe
created 29 Dec. 2008
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
This example code is in the public domain.
*/

View File

@ -1,29 +1,29 @@
/*
Analog Input
Demonstrates analog input by reading an analog sensor on analog pin 0 and
turning on and off a light emitting diode(LED) connected to digital pin 13.
The amount of time the LED will be on and off depends on
the value obtained by analogRead().
Demonstrates analog input by reading an analog sensor on analog pin 0 and
turning on and off a light emitting diode(LED) connected to digital pin 13.
The amount of time the LED will be on and off depends on
the value obtained by analogRead().
The circuit:
- Potentiometer attached to analog input 0
- center pin of the potentiometer to the analog pin
- one side pin (either one) to ground
- the other side pin to +5V
- LED anode (long leg) attached to digital output 13
- LED cathode (short leg) attached to ground
The circuit:
- Potentiometer attached to analog input 0
- center pin of the potentiometer to the analog pin
- one side pin (either one) to ground
- the other side pin to +5V
- LED anode (long leg) attached to digital output 13
- LED cathode (short leg) attached to ground
- Note: because most Arduinos have a built-in LED attached
to pin 13 on the board, the LED is optional.
- Note: because most Arduinos have a built-in LED attached
to pin 13 on the board, the LED is optional.
Created by David Cuartielles
modified 30 Aug 2011
By Tom Igoe
Created by David Cuartielles
modified 30 Aug 2011
By Tom Igoe
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/AnalogInput
http://www.arduino.cc/en/Tutorial/AnalogInput
*/

View File

@ -1,28 +1,28 @@
/*
Calibration
Demonstrates one technique for calibrating sensor input. The
sensor readings during the first five seconds of the sketch
execution define the minimum and maximum of expected values
attached to the sensor pin.
Demonstrates one technique for calibrating sensor input. The
sensor readings during the first five seconds of the sketch
execution define the minimum and maximum of expected values
attached to the sensor pin.
The sensor minimum and maximum initial values may seem backwards.
Initially, you set the minimum high and listen for anything
lower, saving it as the new minimum. Likewise, you set the
maximum low and listen for anything higher as the new maximum.
The sensor minimum and maximum initial values may seem backwards.
Initially, you set the minimum high and listen for anything
lower, saving it as the new minimum. Likewise, you set the
maximum low and listen for anything higher as the new maximum.
The circuit:
- Analog sensor (potentiometer will do) attached to analog input 0
- LED attached from digital pin 9 to ground
The circuit:
- Analog sensor (potentiometer will do) attached to analog input 0
- LED attached from digital pin 9 to ground
created 29 Oct 2008
By David A Mellis
modified 30 Aug 2011
By Tom Igoe
created 29 Oct 2008
By David A Mellis
modified 30 Aug 2011
By Tom Igoe
http://www.arduino.cc/en/Tutorial/Calibration
http://www.arduino.cc/en/Tutorial/Calibration
This example code is in the public domain.
This example code is in the public domain.
*/

View File

@ -1,19 +1,19 @@
/*
Fading
Fading
This example shows how to fade an LED using the analogWrite() function.
This example shows how to fade an LED using the analogWrite() function.
The circuit:
- LED attached from digital pin 9 to ground.
The circuit:
- LED attached from digital pin 9 to ground.
Created 1 Nov 2008
By David A. Mellis
modified 30 Aug 2011
By Tom Igoe
Created 1 Nov 2008
By David A. Mellis
modified 30 Aug 2011
By Tom Igoe
http://www.arduino.cc/en/Tutorial/Fading
http://www.arduino.cc/en/Tutorial/Fading
This example code is in the public domain.
This example code is in the public domain.
*/

View File

@ -1,22 +1,22 @@
/*
ASCII table
Prints out byte values in all possible formats:
- as raw binary values
- as ASCII-encoded decimal, hex, octal, and binary values
Prints out byte values in all possible formats:
- as raw binary values
- as ASCII-encoded decimal, hex, octal, and binary values
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
by Nicholas Zambetti
modified 9 Apr 2012
by Tom Igoe
created 2006
by Nicholas Zambetti
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
This example code is in the public domain.
<http://www.zambetti.com>
<http://www.zambetti.com>
*/
void setup() {

View File

@ -1,23 +1,23 @@
/*
Dimmer
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 individual bytes, each of which ranges from 0 to 255. Arduino
reads these bytes and uses them to set the brightness of the LED.
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 individual bytes, each of which ranges from 0 to 255. Arduino
reads these bytes and uses them to set the brightness of the LED.
The circuit:
LED attached from digital pin 9 to ground.
Serial connection to Processing, Max/MSP, or another serial application
The circuit:
LED attached from digital pin 9 to ground.
Serial connection to Processing, Max/MSP, or another serial application
created 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe and Scott Fitzgerald
created 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe and Scott Fitzgerald
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Dimmer
http://www.arduino.cc/en/Tutorial/Dimmer
*/
@ -43,43 +43,43 @@ void loop() {
}
/* Processing code for this example
// Dimmer - sends bytes over a serial port
// by David A. Mellis
// This example code is in the public domain.
// Dimmer - sends bytes over a serial port
// by David A. Mellis
// This example code is in the public domain.
import processing.serial.*;
Serial port;
import processing.serial.*;
Serial port;
void setup() {
size(256, 150);
void setup() {
size(256, 150);
println("Available serial ports:");
// if using Processing 2.1 or later, use Serial.printArray()
println(Serial.list());
println("Available serial ports:");
// if using Processing 2.1 or later, use Serial.printArray()
println(Serial.list());
// Uses the first port in this list (number 0). Change this to
// select the port corresponding to your Arduino board. The last
// parameter (e.g. 9600) is the speed of the communication. It
// has to correspond to the value passed to Serial.begin() in your
// Arduino sketch.
port = new Serial(this, Serial.list()[0], 9600);
// Uses the first port in this list (number 0). Change this to
// select the port corresponding to your Arduino board. The last
// parameter (e.g. 9600) is the speed of the communication. It
// has to correspond to the value passed to Serial.begin() in your
// Arduino sketch.
port = new Serial(this, Serial.list()[0], 9600);
// If you know the name of the port used by the Arduino board, you
// can specify it directly like this.
//port = new Serial(this, "COM1", 9600);
}
// If you know the name of the port used by the Arduino board, you
// can specify it directly like this.
//port = new Serial(this, "COM1", 9600);
}
void draw() {
// draw a gradient from black to white
for (int i = 0; i < 256; i++) {
stroke(i);
line(i, 0, i, 150);
}
void draw() {
// draw a gradient from black to white
for (int i = 0; i < 256; i++) {
stroke(i);
line(i, 0, i, 150);
}
// write the current X-position of the mouse to the serial port as
// a single byte
port.write(mouseX);
}
// write the current X-position of the mouse to the serial port as
// a single byte
port.write(mouseX);
}
*/
/* Max/MSP v5 patch for this example

View File

@ -1,29 +1,29 @@
/*
Graph
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"
communication because the connection appears to both the Arduino and the
computer as a serial port, even though it may actually use
a USB cable. Bytes are sent one after another (serially) from the Arduino
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"
communication because the connection appears to both the Arduino and the
computer as a serial port, even though it may actually use
a USB cable. Bytes are sent one after another (serially) from the Arduino
to the computer.
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
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.
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
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.
The circuit:
Any analog input sensor is attached to analog in pin 0.
The circuit:
Any analog input sensor is attached to analog in pin 0.
created 2006
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe and Scott Fitzgerald
created 2006
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe and Scott Fitzgerald
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Graph
http://www.arduino.cc/en/Tutorial/Graph
*/
void setup() {
@ -41,72 +41,72 @@ void loop() {
/* Processing code for this example
// Graphing sketch
// Graphing sketch
// This program takes ASCII-encoded strings
// from the serial port at 9600 baud and graphs them. It expects values in the
// range 0 to 1023, followed by a newline, or newline and carriage return
// This program takes ASCII-encoded strings
// from the serial port at 9600 baud and graphs them. It expects values in the
// range 0 to 1023, followed by a newline, or newline and carriage return
// Created 20 Apr 2005
// Updated 24 Nov 2015
// by Tom Igoe
// This example code is in the public domain.
// Created 20 Apr 2005
// Updated 24 Nov 2015
// by Tom Igoe
// This example code is in the public domain.
import processing.serial.*;
import processing.serial.*;
Serial myPort; // The serial port
int xPos = 1; // horizontal position of the graph
float inByte = 0;
Serial myPort; // The serial port
int xPos = 1; // horizontal position of the graph
float inByte = 0;
void setup () {
// set the window size:
size(400, 300);
void setup () {
// set the window size:
size(400, 300);
// List all the available serial ports
// if using Processing 2.1 or later, use Serial.printArray()
println(Serial.list());
// List all the available serial ports
// if using Processing 2.1 or later, use Serial.printArray()
println(Serial.list());
// I know that the first port in the serial list on my Mac
// is always my Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[0], 9600);
// I know that the first port in the serial list on my Mac
// is always my Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[0], 9600);
// don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');
// don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');
// set initial background:
background(0);
}
void draw () {
// draw the line:
stroke(127, 34, 255);
line(xPos, height, xPos, height - inByte);
// at the edge of the screen, go back to the beginning:
if (xPos >= width) {
xPos = 0;
// set initial background:
background(0);
} else {
// increment the horizontal position:
xPos++;
}
}
void draw () {
// draw the line:
stroke(127, 34, 255);
line(xPos, height, xPos, height - inByte);
void serialEvent (Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// convert to an int and map to the screen height:
inByte = float(inString);
println(inByte);
inByte = map(inByte, 0, 1023, 0, height);
// at the edge of the screen, go back to the beginning:
if (xPos >= width) {
xPos = 0;
background(0);
} else {
// increment the horizontal position:
xPos++;
}
}
void serialEvent (Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// convert to an int and map to the screen height:
inByte = float(inString);
println(inByte);
inByte = map(inByte, 0, 1023, 0, height);
}
}
}
*/

View File

@ -1,24 +1,24 @@
/*
MIDI note player
MIDI note player
This sketch shows how to use the serial transmit pin (pin 1) to send MIDI note data.
If this circuit is connected to a MIDI synth, it will play
the notes F#-0 (0x1E) to F#-5 (0x5A) in sequence.
This sketch shows how to use the serial transmit pin (pin 1) to send MIDI note data.
If this circuit is connected to a MIDI synth, it will play
the notes F#-0 (0x1E) to F#-5 (0x5A) in sequence.
The circuit:
- digital in 1 connected to MIDI jack pin 5
- MIDI jack pin 2 connected to ground
- MIDI jack pin 4 connected to +5V through 220-ohm resistor
Attach a MIDI cable to the jack, then to a MIDI synth, and play music.
The circuit:
- digital in 1 connected to MIDI jack pin 5
- MIDI jack pin 2 connected to ground
- MIDI jack pin 4 connected to +5V through 220-ohm resistor
Attach a MIDI cable to the jack, then to a MIDI synth, and play music.
created 13 Jun 2006
modified 13 Aug 2012
by Tom Igoe
created 13 Jun 2006
modified 13 Aug 2012
by Tom Igoe
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Midi
http://www.arduino.cc/en/Tutorial/Midi
*/

View File

@ -1,22 +1,22 @@
/*
Multiple Serial test
Receives from the main serial port, sends to the others.
Receives from serial port 1, sends to the main serial (Serial 0).
Receives from the main serial port, sends to the others.
Receives from serial port 1, sends to the main serial (Serial 0).
This example works only with boards with more than one serial like Arduino Mega, Due, Zero etc
This example works only with boards with more than one serial like Arduino Mega, Due, Zero etc
The circuit:
- Any serial device attached to Serial port 1
- Serial monitor open on Serial port 0:
The circuit:
- Any serial device attached to Serial port 1
- Serial monitor open on Serial port 0:
created 30 Dec. 2008
modified 20 May 2012
by Tom Igoe & Jed Roach
modified 27 Nov 2015
by Arturo Guadalupi
created 30 Dec. 2008
modified 20 May 2012
by Tom Igoe & Jed Roach
modified 27 Nov 2015
by Arturo Guadalupi
This example code is in the public domain.
This example code is in the public domain.
*/

View File

@ -1,26 +1,26 @@
/*
Physical Pixel
An example of using the Arduino board to receive data from the
computer. In this case, the Arduino boards turns on an LED when
it receives the character 'H', and turns off the LED when it
receives the character 'L'.
An example of using the Arduino board to receive data from the
computer. In this case, the Arduino boards turns on an LED when
it receives the character 'H', and turns off the LED when it
receives the character 'L'.
The data can be sent from the Arduino Serial Monitor, or another
program like Processing (see code below), Flash (via a serial-net
proxy), PD, or Max/MSP.
The data can be sent from the Arduino Serial Monitor, or another
program like Processing (see code below), Flash (via a serial-net
proxy), PD, or Max/MSP.
The circuit:
- LED connected from digital pin 13 to ground
The circuit:
- LED connected from digital pin 13 to ground
created 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe and Scott Fitzgerald
created 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe and Scott Fitzgerald
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/PhysicalPixel
http://www.arduino.cc/en/Tutorial/PhysicalPixel
*/
const int ledPin = 13; // the pin that the LED is attached to
@ -51,74 +51,74 @@ void loop() {
/* Processing code for this example
// mouse over serial
// mouse over serial
// Demonstrates how to send data to the Arduino I/O board, in order to
// turn ON a light if the mouse is over a square and turn it off
// if the mouse is not.
// Demonstrates how to send data to the Arduino I/O board, in order to
// turn ON a light if the mouse is over a square and turn it off
// if the mouse is not.
// created 2003-4
// based on examples by Casey Reas and Hernando Barragan
// modified 30 Aug 2011
// by Tom Igoe
// This example code is in the public domain.
// created 2003-4
// based on examples by Casey Reas and Hernando Barragan
// modified 30 Aug 2011
// by Tom Igoe
// This example code is in the public domain.
import processing.serial.*;
import processing.serial.*;
float boxX;
float boxY;
int boxSize = 20;
boolean mouseOverBox = false;
float boxX;
float boxY;
int boxSize = 20;
boolean mouseOverBox = false;
Serial port;
Serial port;
void setup() {
size(200, 200);
boxX = width/2.0;
boxY = height/2.0;
rectMode(RADIUS);
void setup() {
size(200, 200);
boxX = width/2.0;
boxY = height/2.0;
rectMode(RADIUS);
// List all the available serial ports in the output pane.
// You will need to choose the port that the Arduino board is
// connected to from this list. The first port in the list is
// port #0 and the third port in the list is port #2.
// if using Processing 2.1 or later, use Serial.printArray()
println(Serial.list());
// List all the available serial ports in the output pane.
// You will need to choose the port that the Arduino board is
// connected to from this list. The first port in the list is
// port #0 and the third port in the list is port #2.
// if using Processing 2.1 or later, use Serial.printArray()
println(Serial.list());
// Open the port that the Arduino board is connected to (in this case #0)
// Make sure to open the port at the same speed Arduino is using (9600bps)
port = new Serial(this, Serial.list()[0], 9600);
// Open the port that the Arduino board is connected to (in this case #0)
// Make sure to open the port at the same speed Arduino is using (9600bps)
port = new Serial(this, Serial.list()[0], 9600);
}
}
void draw()
{
background(0);
void draw()
{
background(0);
// Test if the cursor is over the box
if (mouseX > boxX-boxSize && mouseX < boxX+boxSize &&
mouseY > boxY-boxSize && mouseY < boxY+boxSize) {
mouseOverBox = true;
// draw a line around the box and change its color:
stroke(255);
fill(153);
// send an 'H' to indicate mouse is over square:
port.write('H');
}
else {
// return the box to its inactive state:
stroke(153);
fill(153);
// send an 'L' to turn the LED off:
port.write('L');
mouseOverBox = false;
}
// Test if the cursor is over the box
if (mouseX > boxX-boxSize && mouseX < boxX+boxSize &&
mouseY > boxY-boxSize && mouseY < boxY+boxSize) {
mouseOverBox = true;
// draw a line around the box and change its color:
stroke(255);
fill(153);
// send an 'H' to indicate mouse is over square:
port.write('H');
}
else {
// return the box to its inactive state:
stroke(153);
fill(153);
// send an 'L' to turn the LED off:
port.write('L');
mouseOverBox = false;
}
// Draw the box
rect(boxX, boxY, boxSize, boxSize);
}
// Draw the box
rect(boxX, boxY, boxSize, boxSize);
}
*/

View File

@ -1,23 +1,23 @@
/*
Reading a serial ASCII-encoded string.
This sketch demonstrates the Serial parseInt() function.
It looks for an ASCII string of comma-separated values.
It parses them into ints, and uses those to fade an RGB LED.
This sketch demonstrates the Serial parseInt() function.
It looks for an ASCII string of comma-separated values.
It parses them into ints, and uses those to fade an RGB LED.
Circuit: Common-Cathode RGB LED wired like so:
- Red anode: digital pin 3
- Green anode: digital pin 5
- Blue anode: digital pin 6
- Cathode : GND
Circuit: Common-Cathode RGB LED wired like so:
- Red anode: digital pin 3
- Green anode: digital pin 5
- Blue anode: digital pin 6
- Cathode : GND
created 13 Apr 2012
by Tom Igoe
modified 14 Mar 2016
by Arturo Guadalupi
created 13 Apr 2012
by Tom Igoe
modified 14 Mar 2016
by Arturo Guadalupi
This example code is in the public domain.
This example code is in the public domain.
*/
// pins for the LEDs:

View File

@ -1,26 +1,26 @@
/*
Serial Call and Response
Language: Wiring/Arduino
Language: Wiring/Arduino
This program sends an ASCII A (byte of value 65) on startup
and repeats that until it gets some data in.
Then it waits for a byte in the serial port, and
sends three sensor values whenever it gets a byte in.
This program sends an ASCII A (byte of value 65) on startup
and repeats that until it gets some data in.
Then it waits for a byte in the serial port, and
sends three sensor values whenever it gets a byte in.
Thanks to Greg Shakar and Scott Fitzgerald for the improvements
Thanks to Greg Shakar and Scott Fitzgerald for the improvements
The circuit:
- potentiometers attached to analog inputs 0 and 1
- pushbutton attached to digital I/O 2
The circuit:
- potentiometers attached to analog inputs 0 and 1
- pushbutton attached to digital I/O 2
Created 26 Sept. 2005
by Tom Igoe
modified 24 April 2012
by Tom Igoe and Scott Fitzgerald
Created 26 Sept. 2005
by Tom Igoe
modified 24 April 2012
by Tom Igoe and Scott Fitzgerald
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/SerialCallResponse
http://www.arduino.cc/en/Tutorial/SerialCallResponse
*/
@ -68,82 +68,82 @@ void establishContact() {
}
/*
Processing sketch to run with this example:
Processing sketch to run with this example:
// This example code is in the public domain.
// This example code is in the public domain.
import processing.serial.*;
import processing.serial.*;
int bgcolor; // Background color
int fgcolor; // Fill color
Serial myPort; // The serial port
int[] serialInArray = new int[3]; // Where we'll put what we receive
int serialCount = 0; // A count of how many bytes we receive
int xpos, ypos; // Starting position of the ball
boolean firstContact = false; // Whether we've heard from the microcontroller
int bgcolor; // Background color
int fgcolor; // Fill color
Serial myPort; // The serial port
int[] serialInArray = new int[3]; // Where we'll put what we receive
int serialCount = 0; // A count of how many bytes we receive
int xpos, ypos; // Starting position of the ball
boolean firstContact = false; // Whether we've heard from the microcontroller
void setup() {
size(256, 256); // Stage size
noStroke(); // No border on the next thing drawn
void setup() {
size(256, 256); // Stage size
noStroke(); // No border on the next thing drawn
// Set the starting position of the ball (middle of the stage)
xpos = width/2;
ypos = height/2;
// Set the starting position of the ball (middle of the stage)
xpos = width/2;
ypos = height/2;
// Print a list of the serial ports for debugging purposes
// if using Processing 2.1 or later, use Serial.printArray()
println(Serial.list());
// Print a list of the serial ports for debugging purposes
// if using Processing 2.1 or later, use Serial.printArray()
println(Serial.list());
// I know that the first port in the serial list on my Mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}
// I know that the first port in the serial list on my Mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}
void draw() {
background(bgcolor);
fill(fgcolor);
// Draw the shape
ellipse(xpos, ypos, 20, 20);
}
void draw() {
background(bgcolor);
fill(fgcolor);
// Draw the shape
ellipse(xpos, ypos, 20, 20);
}
void serialEvent(Serial myPort) {
// read a byte from the serial port:
int inByte = myPort.read();
// if this is the first byte received, and it's an A,
// clear the serial buffer and note that you've
// had first contact from the microcontroller.
// Otherwise, add the incoming byte to the array:
if (firstContact == false) {
if (inByte == 'A') {
myPort.clear(); // clear the serial port buffer
firstContact = true; // you've had first contact from the microcontroller
myPort.write('A'); // ask for more
void serialEvent(Serial myPort) {
// read a byte from the serial port:
int inByte = myPort.read();
// if this is the first byte received, and it's an A,
// clear the serial buffer and note that you've
// had first contact from the microcontroller.
// Otherwise, add the incoming byte to the array:
if (firstContact == false) {
if (inByte == 'A') {
myPort.clear(); // clear the serial port buffer
firstContact = true; // you've had first contact from the microcontroller
myPort.write('A'); // ask for more
}
}
else {
// Add the latest byte from the serial port to array:
serialInArray[serialCount] = inByte;
serialCount++;
// If we have 3 bytes:
if (serialCount > 2 ) {
xpos = serialInArray[0];
ypos = serialInArray[1];
fgcolor = serialInArray[2];
// print the values (for debugging purposes only):
println(xpos + "\t" + ypos + "\t" + fgcolor);
// Send a capital A to request new sensor readings:
myPort.write('A');
// Reset serialCount:
serialCount = 0;
}
}
}
else {
// Add the latest byte from the serial port to array:
serialInArray[serialCount] = inByte;
serialCount++;
// If we have 3 bytes:
if (serialCount > 2 ) {
xpos = serialInArray[0];
ypos = serialInArray[1];
fgcolor = serialInArray[2];
// print the values (for debugging purposes only):
println(xpos + "\t" + ypos + "\t" + fgcolor);
// Send a capital A to request new sensor readings:
myPort.write('A');
// Reset serialCount:
serialCount = 0;
}
}
}
*/
/*

View File

@ -1,30 +1,30 @@
/*
Serial Call and Response in ASCII
Language: Wiring/Arduino
Language: Wiring/Arduino
This program sends an ASCII A (byte of value 65) on startup
and repeats that until it gets some data in.
Then it waits for a byte in the serial port, and
sends three ASCII-encoded, comma-separated sensor values,
truncated by a linefeed and carriage return,
whenever it gets a byte in.
This program sends an ASCII A (byte of value 65) on startup
and repeats that until it gets some data in.
Then it waits for a byte in the serial port, and
sends three ASCII-encoded, comma-separated sensor values,
truncated by a linefeed and carriage return,
whenever it gets a byte in.
Thanks to Greg Shakar and Scott Fitzgerald for the improvements
Thanks to Greg Shakar and Scott Fitzgerald for the improvements
The circuit:
- potentiometers attached to analog inputs 0 and 1
- pushbutton attached to digital I/O 2
The circuit:
- potentiometers attached to analog inputs 0 and 1
- pushbutton attached to digital I/O 2
Created 26 Sept. 2005
by Tom Igoe
modified 24 Apr 2012
by Tom Igoe and Scott Fitzgerald
Created 26 Sept. 2005
by Tom Igoe
modified 24 Apr 2012
by Tom Igoe and Scott Fitzgerald
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/SerialCallResponseASCII
http://www.arduino.cc/en/Tutorial/SerialCallResponseASCII
*/
@ -74,73 +74,73 @@ void establishContact() {
/*
Processing code to run with this example:
Processing code to run with this example:
// This example code is in the public domain.
// This example code is in the public domain.
import processing.serial.*; // import the Processing serial library
Serial myPort; // The serial port
import processing.serial.*; // import the Processing serial library
Serial myPort; // The serial port
float bgcolor; // Background color
float fgcolor; // Fill color
float xpos, ypos; // Starting position of the ball
float bgcolor; // Background color
float fgcolor; // Fill color
float xpos, ypos; // Starting position of the ball
void setup() {
size(640,480);
void setup() {
size(640,480);
// List all the available serial ports
// if using Processing 2.1 or later, use Serial.printArray()
println(Serial.list());
// List all the available serial ports
// if using Processing 2.1 or later, use Serial.printArray()
println(Serial.list());
// I know that the first port in the serial list on my Mac
// is always my Arduino board, so I open Serial.list()[0].
// Change the 0 to the appropriate number of the serial port
// that your microcontroller is attached to.
myPort = new Serial(this, Serial.list()[0], 9600);
// I know that the first port in the serial list on my Mac
// is always my Arduino board, so I open Serial.list()[0].
// Change the 0 to the appropriate number of the serial port
// that your microcontroller is attached to.
myPort = new Serial(this, Serial.list()[0], 9600);
// read bytes into a buffer until you get a linefeed (ASCII 10):
myPort.bufferUntil('\n');
// read bytes into a buffer until you get a linefeed (ASCII 10):
myPort.bufferUntil('\n');
// draw with smooth edges:
smooth();
}
void draw() {
background(bgcolor);
fill(fgcolor);
// Draw the shape
ellipse(xpos, ypos, 20, 20);
}
// serialEvent method is run automatically by the Processing applet
// whenever the buffer reaches the byte value set in the bufferUntil()
// method in the setup():
void serialEvent(Serial myPort) {
// read the serial buffer:
String myString = myPort.readStringUntil('\n');
// if you got any bytes other than the linefeed:
myString = trim(myString);
// split the string at the commas
// and convert the sections into integers:
int sensors[] = int(split(myString, ','));
// print out the values you got:
for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
}
// add a linefeed after all the sensor values are printed:
println();
if (sensors.length > 1) {
xpos = map(sensors[0], 0,1023,0,width);
ypos = map(sensors[1], 0,1023,0,height);
fgcolor = sensors[2];
}
// send a byte to ask for more data:
myPort.write("A");
// draw with smooth edges:
smooth();
}
void draw() {
background(bgcolor);
fill(fgcolor);
// Draw the shape
ellipse(xpos, ypos, 20, 20);
}
// serialEvent method is run automatically by the Processing applet
// whenever the buffer reaches the byte value set in the bufferUntil()
// method in the setup():
void serialEvent(Serial myPort) {
// read the serial buffer:
String myString = myPort.readStringUntil('\n');
// if you got any bytes other than the linefeed:
myString = trim(myString);
// split the string at the commas
// and convert the sections into integers:
int sensors[] = int(split(myString, ','));
// print out the values you got:
for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
}
// add a linefeed after all the sensor values are printed:
println();
if (sensors.length > 1) {
xpos = map(sensors[0], 0,1023,0,width);
ypos = map(sensors[1], 0,1023,0,height);
fgcolor = sensors[2];
}
// send a byte to ask for more data:
myPort.write("A");
}
*/
/*

View File

@ -1,22 +1,22 @@
/*
Serial Event example
When new serial data arrives, this sketch adds it to a String.
When a newline is received, the loop prints the string and
clears it.
When new serial data arrives, this sketch adds it to a String.
When a newline is received, the loop prints the string and
clears it.
A good test for this is to try it with a GPS receiver
that sends out NMEA 0183 sentences.
A good test for this is to try it with a GPS receiver
that sends out NMEA 0183 sentences.
NOTE: The serialEvent() feature is not available on the
Leonardo, Micro, or other ATmega32U4 based boards.
Created 9 May 2011
by Tom Igoe
NOTE: The serialEvent() feature is not available on the
Leonardo, Micro, or other ATmega32U4 based boards.
Created 9 May 2011
by Tom Igoe
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/SerialEvent
http://www.arduino.cc/en/Tutorial/SerialEvent
*/
@ -42,9 +42,9 @@ void loop() {
/*
SerialEvent occurs whenever a new data comes in the
hardware serial RX. This routine is run between each
time loop() runs, so using delay inside loop can delay
response. Multiple bytes of data may be available.
hardware serial RX. This routine is run between each
time loop() runs, so using delay inside loop can delay
response. Multiple bytes of data may be available.
*/
void serialEvent() {
while (Serial.available()) {

View File

@ -1,17 +1,17 @@
/*
This example reads three analog sensors (potentiometers are easiest)
and sends their values serially. The Processing and Max/MSP programs at the bottom
take those three values and use them to change the background color of the screen.
and sends their values serially. The Processing and Max/MSP programs at the bottom
take those three values and use them to change the background color of the screen.
The circuit:
- potentiometers attached to analog inputs 0, 1, and 2
The circuit:
- potentiometers attached to analog inputs 0, 1, and 2
http://www.arduino.cc/en/Tutorial/VirtualColorMixer
http://www.arduino.cc/en/Tutorial/VirtualColorMixer
created 2 Dec 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe and Scott Fitzgerald
created 2 Dec 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe and Scott Fitzgerald
This example code is in the public domain.
*/
@ -34,57 +34,57 @@ void loop() {
/* Processing code for this example
// This example code is in the public domain.
// This example code is in the public domain.
import processing.serial.*;
import processing.serial.*;
float redValue = 0; // red value
float greenValue = 0; // green value
float blueValue = 0; // blue value
float redValue = 0; // red value
float greenValue = 0; // green value
float blueValue = 0; // blue value
Serial myPort;
Serial myPort;
void setup() {
size(200, 200);
void setup() {
size(200, 200);
// List all the available serial ports
// if using Processing 2.1 or later, use Serial.printArray()
println(Serial.list());
// List all the available serial ports
// if using Processing 2.1 or later, use Serial.printArray()
println(Serial.list());
// I know that the first port in the serial list on my Mac
// is always my Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[0], 9600);
// don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');
}
// I know that the first port in the serial list on my Mac
// is always my Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[0], 9600);
// don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');
}
void draw() {
// set the background color with the color values:
background(redValue, greenValue, blueValue);
}
void draw() {
// set the background color with the color values:
background(redValue, greenValue, blueValue);
}
void serialEvent(Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');
void serialEvent(Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// split the string on the commas and convert the
// resulting substrings into an integer array:
float[] colors = float(split(inString, ","));
// if the array has at least three elements, you know
// you got the whole thing. Put the numbers in the
// color variables:
if (colors.length >=3) {
// map them to the range 0-255:
redValue = map(colors[0], 0, 1023, 0, 255);
greenValue = map(colors[1], 0, 1023, 0, 255);
blueValue = map(colors[2], 0, 1023, 0, 255);
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// split the string on the commas and convert the
// resulting substrings into an integer array:
float[] colors = float(split(inString, ","));
// if the array has at least three elements, you know
// you got the whole thing. Put the numbers in the
// color variables:
if (colors.length >=3) {
// map them to the range 0-255:
redValue = map(colors[0], 0, 1023, 0, 255);
greenValue = map(colors[1], 0, 1023, 0, 255);
blueValue = map(colors[2], 0, 1023, 0, 255);
}
}
}
}
*/

View File

@ -1,24 +1,24 @@
/*
Arrays
Demonstrates the use of an array to hold pin numbers
in order to iterate over the pins in a sequence.
Lights multiple LEDs in sequence, then in reverse.
Demonstrates the use of an array to hold pin numbers
in order to iterate over the pins in a sequence.
Lights multiple LEDs in sequence, then in reverse.
Unlike the For Loop tutorial, where the pins have to be
contiguous, here the pins can be in any random order.
Unlike the For Loop tutorial, where the pins have to be
contiguous, here the pins can be in any random order.
The circuit:
- LEDs from pins 2 through 7 to ground
The circuit:
- LEDs from pins 2 through 7 to ground
created 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe
created 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Array
http://www.arduino.cc/en/Tutorial/Array
*/
int timer = 100; // The higher the number, the slower the timing.

View File

@ -1,20 +1,20 @@
/*
For Loop Iteration
Demonstrates the use of a for() loop.
Lights multiple LEDs in sequence, then in reverse.
Demonstrates the use of a for() loop.
Lights multiple LEDs in sequence, then in reverse.
The circuit:
- LEDs from pins 2 through 7 to ground
The circuit:
- LEDs from pins 2 through 7 to ground
created 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe
created 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/ForLoop
http://www.arduino.cc/en/Tutorial/ForLoop
*/
int timer = 100; // The higher the number, the slower the timing.

View File

@ -1,27 +1,27 @@
/*
Conditionals - If statement
This example demonstrates the use of if() statements.
It reads the state of a potentiometer (an analog input) and turns on an LED
only if the potentiometer goes above a certain threshold level. It prints the analog value
regardless of the level.
This example demonstrates the use of if() statements.
It reads the state of a potentiometer (an analog input) and turns on an LED
only if the potentiometer goes above a certain threshold level. It prints the analog value
regardless of the level.
The circuit:
- potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
- LED connected from digital pin 13 to ground
The circuit:
- potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
- LED connected from digital pin 13 to ground
- Note: On most Arduino boards, there is already an LED on the board
connected to pin 13, so you don't need any extra components for this example.
- Note: On most Arduino boards, there is already an LED on the board
connected to pin 13, so you don't need any extra components for this example.
created 17 Jan 2009
modified 9 Apr 2012
by Tom Igoe
created 17 Jan 2009
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/IfStatement
http://www.arduino.cc/en/Tutorial/IfStatement
*/

View File

@ -1,30 +1,30 @@
/*
Conditionals - while statement
This example demonstrates the use of while() statements.
This example demonstrates the use of while() statements.
While the pushbutton is pressed, the sketch runs the calibration routine.
The sensor readings during the while loop define the minimum and maximum
of expected values from the photoresistor.
While the pushbutton is pressed, the sketch runs the calibration routine.
The sensor readings during the while loop define the minimum and maximum
of expected values from the photoresistor.
This is a variation on the calibrate example.
This is a variation on the calibrate example.
The circuit:
- photoresistor connected from +5V to analog in pin 0
- 10K resistor connected from ground to analog in pin 0
- LED connected from digital pin 9 to ground through 220 ohm resistor
- pushbutton attached from pin 2 to +5V
- 10K resistor attached from pin 2 to ground
The circuit:
- photoresistor connected from +5V to analog in pin 0
- 10K resistor connected from ground to analog in pin 0
- LED connected from digital pin 9 to ground through 220 ohm resistor
- pushbutton attached from pin 2 to +5V
- 10K resistor attached from pin 2 to ground
created 17 Jan 2009
modified 30 Aug 2011
by Tom Igoe
modified 20 Jan 2017
by Arturo Guadalupi
created 17 Jan 2009
modified 30 Aug 2011
by Tom Igoe
modified 20 Jan 2017
by Arturo Guadalupi
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/WhileLoop
http://www.arduino.cc/en/Tutorial/WhileLoop
*/

View File

@ -1,25 +1,25 @@
/*
Switch statement
Demonstrates the use of a switch statement. The switch
statement allows you to choose from among a set of discrete values
of a variable. It's like a series of if statements.
Demonstrates the use of a switch statement. The switch
statement allows you to choose from among a set of discrete values
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
room, open the Serial Monitor, and move your hand gradually down
over the sensor.
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
over the sensor.
The circuit:
- photoresistor from analog in 0 to +5V
- 10K resistor from analog in 0 to ground
The circuit:
- photoresistor from analog in 0 to +5V
- 10K resistor from analog in 0 to ground
created 1 Jul 2009
modified 9 Apr 2012
by Tom Igoe
created 1 Jul 2009
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/SwitchCase
http://www.arduino.cc/en/Tutorial/SwitchCase
*/
// these constants won't change. They are the

View File

@ -1,23 +1,23 @@
/*
Switch statement with serial input
Demonstrates the use of a switch statement. The switch
statement allows you to choose from among a set of discrete values
of a variable. It's like a series of if statements.
Demonstrates the use of a switch statement. The switch
statement allows you to choose from among a set of discrete values
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.
The characters a, b, c, d, and e, will turn on LEDs. Any other character will turn
the LEDs off.
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 LEDs off.
The circuit:
- 5 LEDs attached to digital pins 2 through 6 through 220-ohm resistors
The circuit:
- 5 LEDs attached to digital pins 2 through 6 through 220-ohm resistors
created 1 Jul 2009
by Tom Igoe
created 1 Jul 2009
by Tom Igoe
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/SwitchCase2
http://www.arduino.cc/en/Tutorial/SwitchCase2
*/
void setup() {

View File

@ -1,28 +1,28 @@
/*
ADXL3xx
ADXL3xx
Reads an Analog Devices ADXL3xx accelerometer and communicates the
acceleration to the computer. The pins used are designed to be easily
compatible with the breakout boards from SparkFun, available from:
http://www.sparkfun.com/commerce/categories.php?c=80
Reads an Analog Devices ADXL3xx accelerometer and communicates the
acceleration to the computer. The pins used are designed to be easily
compatible with the breakout boards from SparkFun, available from:
http://www.sparkfun.com/commerce/categories.php?c=80
http://www.arduino.cc/en/Tutorial/ADXL3xx
http://www.arduino.cc/en/Tutorial/ADXL3xx
The circuit:
analog 0: accelerometer self test
analog 1: z-axis
analog 2: y-axis
analog 3: x-axis
analog 4: ground
analog 5: vcc
The circuit:
analog 0: accelerometer self test
analog 1: z-axis
analog 2: y-axis
analog 3: x-axis
analog 4: ground
analog 5: vcc
created 2 Jul 2008
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe
created 2 Jul 2008
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
This example code is in the public domain.
*/

View File

@ -1,23 +1,23 @@
/* Knock Sensor
This sketch reads a piezo element to detect a knocking sound.
It reads an analog pin and compares the result to a set threshold.
If the result is greater than the threshold, it writes
"knock" to the serial port, and toggles the LED on pin 13.
This sketch reads a piezo element to detect a knocking sound.
It reads an analog pin and compares the result to a set threshold.
If the result is greater than the threshold, it writes
"knock" to the serial port, and toggles the LED on pin 13.
The circuit:
- + connection of the piezo attached to analog in 0
- - connection of the piezo attached to ground
- 1-megohm resistor attached from analog in 0 to ground
The circuit:
- + connection of the piezo attached to analog in 0
- - connection of the piezo attached to ground
- 1-megohm resistor attached from analog in 0 to ground
http://www.arduino.cc/en/Tutorial/Knock
http://www.arduino.cc/en/Tutorial/Knock
created 25 Mar 2007
by David Cuartielles <http://www.0j0.org>
modified 30 Aug 2011
by Tom Igoe
created 25 Mar 2007
by David Cuartielles <http://www.0j0.org>
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
This example code is in the public domain.
*/

View File

@ -1,25 +1,25 @@
/*
Memsic2125
Memsic2125
Read the Memsic 2125 two-axis accelerometer. Converts the
pulses output by the 2125 into milli-g's (1/1000 of Earth's
gravity) and prints them over the serial connection to the
computer.
Read the Memsic 2125 two-axis accelerometer. Converts the
pulses output by the 2125 into milli-g's (1/1000 of Earth's
gravity) and prints them over the serial connection to the
computer.
The circuit:
- X output of accelerometer to digital pin 2
- Y output of accelerometer to digital pin 3
- +V of accelerometer to +5V
- GND of accelerometer to ground
The circuit:
- X output of accelerometer to digital pin 2
- Y output of accelerometer to digital pin 3
- +V of accelerometer to +5V
- GND of accelerometer to ground
http://www.arduino.cc/en/Tutorial/Memsic2125
http://www.arduino.cc/en/Tutorial/Memsic2125
created 6 Nov 2008
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe
created 6 Nov 2008
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
This example code is in the public domain.
*/

View File

@ -1,24 +1,24 @@
/* Ping))) Sensor
This sketch reads a PING))) ultrasonic rangefinder and returns the
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 return. The length of the returning pulse is proportional to
the distance of the object from the sensor.
This sketch reads a PING))) ultrasonic rangefinder and returns the
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 return. The length of the returning pulse is proportional to
the distance of the object from the sensor.
The circuit:
- +V connection of the PING))) attached to +5V
- GND connection of the PING))) attached to ground
- SIG connection of the PING))) attached to digital pin 7
The circuit:
- +V connection of the PING))) attached to +5V
- GND connection of the PING))) attached to ground
- SIG connection of the PING))) attached to digital pin 7
http://www.arduino.cc/en/Tutorial/Ping
http://www.arduino.cc/en/Tutorial/Ping
created 3 Nov 2008
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe
created 3 Nov 2008
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
This example code is in the public domain.
*/

View File

@ -1,36 +1,36 @@
/*
Row-Column Scanning an 8x8 LED matrix with X-Y input
This example controls an 8x8 LED matrix using two analog inputs
This example controls an 8x8 LED matrix using two analog inputs
created 27 May 2009
modified 30 Aug 2011
by Tom Igoe
created 27 May 2009
modified 30 Aug 2011
by Tom Igoe
This example works for the Lumex LDM-24488NI Matrix. See
http://sigma.octopart.com/140413/datasheet/Lumex-LDM-24488NI.pdf
for the pin connections
This example works for the Lumex LDM-24488NI Matrix. See
http://sigma.octopart.com/140413/datasheet/Lumex-LDM-24488NI.pdf
for the pin connections
For other LED cathode column matrixes, you should only need to change
the pin numbers in the row[] and column[] arrays
For other LED cathode column matrixes, you should only need to change
the pin numbers in the row[] and column[] arrays
rows are the anodes
cols are the cathodes
---------
rows are the anodes
cols are the cathodes
---------
Pin numbers:
Matrix:
- Digital pins 2 through 13,
- analog pins 2 through 5 used as digital 16 through 19
Potentiometers:
- center pins are attached to analog pins 0 and 1, respectively
- side pins attached to +5V and ground, respectively.
Pin numbers:
Matrix:
- Digital pins 2 through 13,
- analog pins 2 through 5 used as digital 16 through 19
Potentiometers:
- center pins are attached to analog pins 0 and 1, respectively
- side pins attached to +5V and ground, respectively.
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/RowColumnScanning
http://www.arduino.cc/en/Tutorial/RowColumnScanning
see also http://www.tigoe.net/pcomp/code/category/arduinowiring/514 for more
see also http://www.tigoe.net/pcomp/code/category/arduinowiring/514 for more
*/

View File

@ -12,12 +12,12 @@
The circuit:
- LEDs from pins 2 through 11 to ground
created 4 Sep 2010
by Tom Igoe
created 4 Sep 2010
by Tom Igoe
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/BarGraph
http://www.arduino.cc/en/Tutorial/BarGraph
*/

View File

@ -1,14 +1,14 @@
/*
Character analysis operators
Examples using the character analysis operators.
Send any byte and the sketch will tell you about it.
Examples using the character analysis operators.
Send any byte and the sketch will tell you about it.
created 29 Nov 2010
modified 2 Apr 2012
by Tom Igoe
created 29 Nov 2010
modified 2 Apr 2012
by Tom Igoe
This example code is in the public domain.
This example code is in the public domain.
*/
void setup() {

View File

@ -1,16 +1,16 @@
/*
Adding Strings together
Examples of how to add Strings together
You can also add several different data types to String, as shown here:
Examples of how to add Strings together
You can also add several different data types to String, as shown here:
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
http://www.arduino.cc/en/Tutorial/StringAdditionOperator
http://www.arduino.cc/en/Tutorial/StringAdditionOperator
This example code is in the public domain.
This example code is in the public domain.
*/
// declare three Strings:

View File

@ -1,15 +1,15 @@
/*
Appending to Strings using the += operator and concat()
Examples of how to append different data types to Strings
Examples of how to append different data types to Strings
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
http://www.arduino.cc/en/Tutorial/StringAppendOperator
http://www.arduino.cc/en/Tutorial/StringAppendOperator
This example code is in the public domain.
This example code is in the public domain.
*/
String stringOne, stringTwo;

View File

@ -1,15 +1,15 @@
/*
String Case changes
Examples of how to change the case of a String
Examples of how to change the case of a String
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
http://www.arduino.cc/en/Tutorial/StringCaseChanges
http://www.arduino.cc/en/Tutorial/StringCaseChanges
This example code is in the public domain.
This example code is in the public domain.
*/
void setup() {

View File

@ -1,15 +1,15 @@
/*
String charAt() and setCharAt()
Examples of how to get and set characters of a String
Examples of how to get and set characters of a String
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
http://www.arduino.cc/en/Tutorial/StringCharacters
http://www.arduino.cc/en/Tutorial/StringCharacters
This example code is in the public domain.
This example code is in the public domain.
*/
void setup() {

View File

@ -1,15 +1,15 @@
/*
Comparing Strings
Examples of how to compare Strings using the comparison operators
Examples of how to compare Strings using the comparison operators
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
http://www.arduino.cc/en/Tutorial/StringComparisonOperators
http://www.arduino.cc/en/Tutorial/StringComparisonOperators
This example code is in the public domain.
This example code is in the public domain.
*/
String stringOne, stringTwo;

View File

@ -1,15 +1,15 @@
/*
String constructors
String constructors
Examples of how to create Strings from other data types
Examples of how to create Strings from other data types
created 27 July 2010
modified 30 Aug 2011
by Tom Igoe
created 27 July 2010
modified 30 Aug 2011
by Tom Igoe
http://www.arduino.cc/en/Tutorial/StringConstructors
http://www.arduino.cc/en/Tutorial/StringConstructors
This example code is in the public domain.
This example code is in the public domain.
*/
void setup() {

View File

@ -1,15 +1,15 @@
/*
String indexOf() and lastIndexOf() functions
Examples of how to evaluate, look for, and replace characters in a String
Examples of how to evaluate, look for, and replace characters in a String
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
http://www.arduino.cc/en/Tutorial/StringIndexOf
http://www.arduino.cc/en/Tutorial/StringIndexOf
This example code is in the public domain.
This example code is in the public domain.
*/
void setup() {

View File

@ -1,15 +1,15 @@
/*
String length()
Examples of how to use length() in a String.
Open the Serial Monitor and start sending characters to see the results.
Examples of how to use length() in a String.
Open the Serial Monitor and start sending characters to see the results.
created 1 Aug 2010
by Tom Igoe
created 1 Aug 2010
by Tom Igoe
http://www.arduino.cc/en/Tutorial/StringLengthTrim
http://www.arduino.cc/en/Tutorial/StringLengthTrim
This example code is in the public domain.
This example code is in the public domain.
*/
String txtMsg = ""; // a string for incoming text

View File

@ -1,15 +1,15 @@
/*
String length() and trim()
Examples of how to use length() and trim() in a String
Examples of how to use length() and trim() in a String
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
http://www.arduino.cc/en/Tutorial/StringLengthTrim
http://www.arduino.cc/en/Tutorial/StringLengthTrim
This example code is in the public domain.
This example code is in the public domain.
*/
void setup() {

View File

@ -1,15 +1,15 @@
/*
String replace()
Examples of how to replace characters or substrings of a String
Examples of how to replace characters or substrings of a String
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
http://www.arduino.cc/en/Tutorial/StringReplace
http://www.arduino.cc/en/Tutorial/StringReplace
This example code is in the public domain.
This example code is in the public domain.
*/
void setup() {

View File

@ -1,15 +1,15 @@
/*
String startWith() and endsWith()
Examples of how to use startsWith() and endsWith() in a String
Examples of how to use startsWith() and endsWith() in a String
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
http://www.arduino.cc/en/Tutorial/StringStartsWithEndsWith
http://www.arduino.cc/en/Tutorial/StringStartsWithEndsWith
This example code is in the public domain.
This example code is in the public domain.
*/
void setup() {

View File

@ -1,15 +1,15 @@
/*
String substring()
Examples of how to use substring in a String
Examples of how to use substring in a String
created 27 July 2010,
modified 2 Apr 2012
by Zach Eveland
created 27 July 2010,
modified 2 Apr 2012
by Zach Eveland
http://www.arduino.cc/en/Tutorial/StringSubstring
http://www.arduino.cc/en/Tutorial/StringSubstring
This example code is in the public domain.
This example code is in the public domain.
*/
void setup() {

View File

@ -1,16 +1,16 @@
/*
String to Integer conversion
Reads a serial input string until it sees a newline, then converts
the string to a number if the characters are digits.
Reads a serial input string until it sees a newline, then converts
the string to a number if the characters are digits.
The circuit:
No external components needed.
The circuit:
No external components needed.
created 29 Nov 2010
by Tom Igoe
created 29 Nov 2010
by Tom Igoe
This example code is in the public domain.
This example code is in the public domain.
*/
String inString = ""; // string to hold input

View File

@ -1,28 +1,28 @@
/*
Keyboard logout
This sketch demonstrates the Keyboard library.
This sketch demonstrates the Keyboard library.
When you connect pin 2 to ground, it performs a logout.
It uses keyboard combinations to do this, as follows:
When you connect pin 2 to ground, it performs a logout.
It uses keyboard combinations to do this, as follows:
On Windows, CTRL-ALT-DEL followed by ALT-l
On Ubuntu, CTRL-ALT-DEL, and ENTER
On OSX, CMD-SHIFT-q
On Windows, CTRL-ALT-DEL followed by ALT-l
On Ubuntu, CTRL-ALT-DEL, and ENTER
On OSX, CMD-SHIFT-q
To wake: Spacebar.
To wake: Spacebar.
Circuit:
- Arduino Leonardo or Micro
- wire to connect D2 to ground.
Circuit:
- Arduino Leonardo or Micro
- wire to connect D2 to ground.
created 6 Mar 2012
modified 27 Mar 2012
by Tom Igoe
created 6 Mar 2012
modified 27 Mar 2012
by Tom Igoe
This example is in the public domain
This example is in the public domain
http://www.arduino.cc/en/Tutorial/KeyboardLogout
http://www.arduino.cc/en/Tutorial/KeyboardLogout
*/
#define OSX 0

View File

@ -1,23 +1,23 @@
/*
Keyboard Message test
Keyboard Message test
For the Arduino Leonardo and Micro.
For the Arduino Leonardo and Micro.
Sends a text string when a button is pressed.
Sends a text string when a button is pressed.
The circuit:
- pushbutton attached from pin 4 to +5V
- 10-kilohm resistor attached from pin 4 to ground
The circuit:
- pushbutton attached from pin 4 to +5V
- 10-kilohm resistor attached from pin 4 to ground
created 24 Oct 2011
modified 27 Mar 2012
by Tom Igoe
modified 11 Nov 2013
by Scott Fitzgerald
created 24 Oct 2011
modified 27 Mar 2012
by Tom Igoe
modified 11 Nov 2013
by Scott Fitzgerald
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/KeyboardMessage
http://www.arduino.cc/en/Tutorial/KeyboardMessage
*/
#include "Keyboard.h"

View File

@ -1,30 +1,30 @@
/*
Arduino Programs Blink
This sketch demonstrates the Keyboard library.
This sketch demonstrates the Keyboard library.
For Leonardo and Due boards only.
For Leonardo and Due boards only.
When you connect pin 2 to ground, it creates a new
window with a key combination (CTRL-N),
then types in the Blink sketch, then auto-formats the text
using another key combination (CTRL-T), then
uploads the sketch to the currently selected Arduino using
a final key combination (CTRL-U).
When you connect pin 2 to ground, it creates a new
window with a key combination (CTRL-N),
then types in the Blink sketch, then auto-formats the text
using another key combination (CTRL-T), then
uploads the sketch to the currently selected Arduino using
a final key combination (CTRL-U).
Circuit:
- Arduino Leonardo, Micro, Due, LilyPad USB, or Yún
- wire to connect D2 to ground.
Circuit:
- Arduino Leonardo, Micro, Due, LilyPad USB, or Yún
- wire to connect D2 to ground.
created 5 Mar 2012
modified 29 Mar 2012
by Tom Igoe
modified 3 May 2014
by Scott Fitzgerald
created 5 Mar 2012
modified 29 Mar 2012
by Tom Igoe
modified 3 May 2014
by Scott Fitzgerald
This example is in the public domain
This example is in the public domain
http://www.arduino.cc/en/Tutorial/KeyboardReprogram
http://www.arduino.cc/en/Tutorial/KeyboardReprogram
*/
#include "Keyboard.h"

View File

@ -1,22 +1,22 @@
/*
Keyboard test
Keyboard test
For the Arduino Leonardo, Micro or Due
For the Arduino Leonardo, Micro or Due
Reads a byte from the serial port, sends a keystroke back.
The sent keystroke is one higher than what's received, e.g.
if you send a, you get b, send A you get B, and so forth.
Reads a byte from the serial port, sends a keystroke back.
The sent keystroke is one higher than what's received, e.g.
if you send a, you get b, send A you get B, and so forth.
The circuit:
- none
The circuit:
- none
created 21 Oct 2011
modified 27 Mar 2012
by Tom Igoe
created 21 Oct 2011
modified 27 Mar 2012
by Tom Igoe
This example code is in the public domain.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/KeyboardSerial
http://www.arduino.cc/en/Tutorial/KeyboardSerial
*/
#include "Keyboard.h"

View File

@ -2,22 +2,22 @@
/*
KeyboardAndMouseControl
Controls the mouse from five pushbuttons on an Arduino Leonardo, Micro or Due.
Controls the mouse from five pushbuttons on an Arduino Leonardo, Micro or Due.
Hardware:
- 5 pushbuttons attached to D2, D3, D4, D5, D6
Hardware:
- 5 pushbuttons attached to D2, D3, D4, D5, D6
The mouse movement is always relative. This sketch reads
four pushbuttons, and uses them to set the movement of the mouse.
The mouse movement is always relative. This sketch reads
four pushbuttons, and uses them to set the movement of the mouse.
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.
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.
created 15 Mar 2012
modified 27 Mar 2012
by Tom Igoe
created 15 Mar 2012
modified 27 Mar 2012
by Tom Igoe
this code is in the public domain
this code is in the public domain
*/

View File

@ -2,25 +2,25 @@
/*
ButtonMouseControl
For Leonardo and Due boards only.
For Leonardo and Due boards only.
Controls the mouse from five pushbuttons on an Arduino Leonardo, Micro or Due.
Controls the mouse from five pushbuttons on an Arduino Leonardo, Micro or Due.
Hardware:
- 5 pushbuttons attached to D2, D3, D4, D5, D6
Hardware:
- 5 pushbuttons attached to D2, D3, D4, D5, D6
The mouse movement is always relative. This sketch reads
four pushbuttons, and uses them to set the movement of the mouse.
The mouse movement is always relative. This sketch reads
four pushbuttons, and uses them to set the movement of the mouse.
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.
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.
created 15 Mar 2012
modified 27 Mar 2012
by Tom Igoe
created 15 Mar 2012
modified 27 Mar 2012
by Tom Igoe
this code is in the public domain
this code is in the public domain
*/

View File

@ -1,30 +1,30 @@
/*
JoystickMouseControl
Controls the mouse from a joystick on an Arduino Leonardo, Micro or Due.
Uses a pushbutton to turn on and off mouse control, and
a second pushbutton to click the left mouse button
Controls the mouse from a joystick on an Arduino Leonardo, Micro or Due.
Uses a pushbutton to turn on and off mouse control, and
a second pushbutton to click the left mouse button
Hardware:
- 2-axis joystick connected to pins A0 and A1
- pushbuttons connected to pin D2 and D3
Hardware:
- 2-axis joystick connected to pins A0 and A1
- pushbuttons connected to pin D2 and D3
The mouse movement is always relative. This sketch reads
two analog inputs that range from 0 to 1023 (or less on either end)
and translates them into ranges of -6 to 6.
The sketch assumes that the joystick resting values are around the
middle of the range, but that they vary within a threshold.
The mouse movement is always relative. This sketch reads
two analog inputs that range from 0 to 1023 (or less on either end)
and translates them into ranges of -6 to 6.
The sketch assumes that the joystick resting values are around the
middle of the range, but that they vary within a threshold.
WARNING: When you use the Mouse.move() command, the Arduino takes
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
you can turn on and off mouse control.
WARNING: When you use the Mouse.move() command, the Arduino takes
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
you can turn on and off mouse control.
created 15 Sept 2011
updated 28 Mar 2012
by Tom Igoe
created 15 Sept 2011
updated 28 Mar 2012
by Tom Igoe
this code is in the public domain
this code is in the public domain
*/
@ -97,7 +97,7 @@ void loop() {
/*
reads an axis (0 or 1 for x or y) and scales the
analog input range to a range from 0 to <range>
analog input range to a range from 0 to <range>
*/
int readAxis(int thisAxis) {

View File

@ -1,23 +1,23 @@
/*
Arduino Starter Kit example
Project 2 - Spaceship Interface
Project 2 - Spaceship Interface
This sketch is written to accompany Project 2 in the
Arduino Starter Kit
This sketch is written to accompany Project 2 in the
Arduino Starter Kit
Parts required:
1 green LED
2 red LEDs
pushbutton
10 kilohm resistor
3 220 ohm resistors
Parts required:
1 green LED
2 red LEDs
pushbutton
10 kilohm resistor
3 220 ohm resistors
Created 13 September 2012
by Scott Fitzgerald
Created 13 September 2012
by Scott Fitzgerald
http://www.arduino.cc/starterKit
http://www.arduino.cc/starterKit
This example code is part of the public domain
This example code is part of the public domain
*/
// Create a global variable to hold the

View File

@ -1,21 +1,21 @@
/*
Arduino Starter Kit example
Project 3 - Love-O-Meter
Project 3 - Love-O-Meter
This sketch is written to accompany Project 3 in the
Arduino Starter Kit
This sketch is written to accompany Project 3 in the
Arduino Starter Kit
Parts required:
1 TMP36 temperature sensor
3 red LEDs
3 220 ohm resistors
Parts required:
1 TMP36 temperature sensor
3 red LEDs
3 220 ohm resistors
Created 13 September 2012
by Scott Fitzgerald
Created 13 September 2012
by Scott Fitzgerald
http://www.arduino.cc/starterKit
http://www.arduino.cc/starterKit
This example code is part of the public domain
This example code is part of the public domain
*/
// named constant for the pin the sensor is connected to

View File

@ -1,25 +1,25 @@
/*
Arduino Starter Kit example
Project 4 - Color Mixing Lamp
Project 4 - Color Mixing Lamp
This sketch is written to accompany Project 3 in the
Arduino Starter Kit
This sketch is written to accompany Project 3 in the
Arduino Starter Kit
Parts required:
1 RGB LED
three 10 kilohm resistors
3 220 ohm resistors
3 photoresistors
red green and blue colored gels
Parts required:
1 RGB LED
three 10 kilohm resistors
3 220 ohm resistors
3 photoresistors
red green and blue colored gels
Created 13 September 2012
Modified 14 November 2012
by Scott Fitzgerald
Thanks to Federico Vanzati for improvements
Created 13 September 2012
Modified 14 November 2012
by Scott Fitzgerald
Thanks to Federico Vanzati for improvements
http://www.arduino.cc/starterKit
http://www.arduino.cc/starterKit
This example code is part of the public domain
This example code is part of the public domain
*/
const int greenLEDPin = 9; // LED connected to digital pin 9
@ -71,10 +71,10 @@ void loop() {
Serial.println(blueSensorValue);
/*
In order to use the values from the sensor for the LED,
you need to do some math. The ADC provides a 10-bit number,
but analogWrite() uses 8 bits. You'll want to divide your
sensor readings by 4 to keep them in range of the output.
In order to use the values from the sensor for the LED,
you need to do some math. The ADC provides a 10-bit number,
but analogWrite() uses 8 bits. You'll want to divide your
sensor readings by 4 to keep them in range of the output.
*/
redValue = redSensorValue / 4;
greenValue = greenSensorValue / 4;

View File

@ -1,21 +1,21 @@
/*
Arduino Starter Kit example
Project 5 - Servo Mood Indicator
Project 5 - Servo Mood Indicator
This sketch is written to accompany Project 5 in the
Arduino Starter Kit
This sketch is written to accompany Project 5 in the
Arduino Starter Kit
Parts required:
servo motor
10 kilohm potentiometer
2 100 uF electrolytic capacitors
Parts required:
servo motor
10 kilohm potentiometer
2 100 uF electrolytic capacitors
Created 13 September 2012
by Scott Fitzgerald
Created 13 September 2012
by Scott Fitzgerald
http://www.arduino.cc/starterKit
http://www.arduino.cc/starterKit
This example code is part of the public domain
This example code is part of the public domain
*/
// include the Servo library

View File

@ -1,21 +1,21 @@
/*
Arduino Starter Kit example
Project 6 - Light Theremin
Project 6 - Light Theremin
This sketch is written to accompany Project 6 in the
Arduino Starter Kit
This sketch is written to accompany Project 6 in the
Arduino Starter Kit
Parts required:
photoresistor
10 kilohm resistor
piezo
Parts required:
photoresistor
10 kilohm resistor
piezo
Created 13 September 2012
by Scott Fitzgerald
Created 13 September 2012
by Scott Fitzgerald
http://www.arduino.cc/starterKit
http://www.arduino.cc/starterKit
This example code is part of the public domain
This example code is part of the public domain
*/
// variable to hold sensor value

View File

@ -1,23 +1,23 @@
/*
Arduino Starter Kit example
Project 7 - Keyboard
Project 7 - Keyboard
This sketch is written to accompany Project 7 in the
Arduino Starter Kit
This sketch is written to accompany Project 7 in the
Arduino Starter Kit
Parts required:
two 10 kilohm resistors
1 Megohm resistor
220 ohm resistor
4 pushbuttons
piezo
Parts required:
two 10 kilohm resistors
1 Megohm resistor
220 ohm resistor
4 pushbuttons
piezo
Created 13 September 2012
by Scott Fitzgerald
Created 13 September 2012
by Scott Fitzgerald
http://www.arduino.cc/starterKit
http://www.arduino.cc/starterKit
This example code is part of the public domain
This example code is part of the public domain
*/
// create an array of notes

View File

@ -1,22 +1,22 @@
/*
Arduino Starter Kit example
Project 8 - Digital Hourglass
Project 8 - Digital Hourglass
This sketch is written to accompany Project 8 in the
Arduino Starter Kit
This sketch is written to accompany Project 8 in the
Arduino Starter Kit
Parts required:
10 kilohm resistor
six 220 ohm resistors
six LEDs
tilt switch
Parts required:
10 kilohm resistor
six 220 ohm resistors
six LEDs
tilt switch
Created 13 September 2012
by Scott Fitzgerald
Created 13 September 2012
by Scott Fitzgerald
http://www.arduino.cc/starterKit
http://www.arduino.cc/starterKit
This example code is part of the public domain
This example code is part of the public domain
*/
// named constant for the switch pin

View File

@ -1,24 +1,24 @@
/*
Arduino Starter Kit example
Project 9 - Motorized Pinwheel
Project 9 - Motorized Pinwheel
This sketch is written to accompany Project 9 in the
Arduino Starter Kit
This sketch is written to accompany Project 9 in the
Arduino Starter Kit
Parts required:
10 kilohm resistor
pushbutton
motor
9V battery
IRF520 MOSFET
1N4007 diode
Parts required:
10 kilohm resistor
pushbutton
motor
9V battery
IRF520 MOSFET
1N4007 diode
Created 13 September 2012
by Scott Fitzgerald
Created 13 September 2012
by Scott Fitzgerald
http://www.arduino.cc/starterKit
http://www.arduino.cc/starterKit
This example code is part of the public domain
This example code is part of the public domain
*/
// named constants for the switch and motor pins

View File

@ -1,25 +1,25 @@
/*
Arduino Starter Kit example
Project 10 - Zoetrope
Project 10 - Zoetrope
This sketch is written to accompany Project 10 in the
Arduino Starter Kit
This sketch is written to accompany Project 10 in the
Arduino Starter Kit
Parts required:
two 10 kilohm resistors
2 momentary pushbuttons
one 10 kilohm potentiometer
motor
9V battery
H-Bridge
Parts required:
two 10 kilohm resistors
2 momentary pushbuttons
one 10 kilohm potentiometer
motor
9V battery
H-Bridge
Created 13 September 2012
by Scott Fitzgerald
Thanks to Federico Vanzati for improvements
Created 13 September 2012
by Scott Fitzgerald
Thanks to Federico Vanzati for improvements
http://www.arduino.cc/starterKit
http://www.arduino.cc/starterKit
This example code is part of the public domain
This example code is part of the public domain
*/
const int controlPin1 = 2; // connected to pin 7 on the H-bridge

View File

@ -1,24 +1,24 @@
/*
Arduino Starter Kit example
Project 11 - Crystal Ball
Project 11 - Crystal Ball
This sketch is written to accompany Project 11 in the
Arduino Starter Kit
This sketch is written to accompany Project 11 in the
Arduino Starter Kit
Parts required:
220 ohm resistor
10 kilohm resistor
10 kilohm potentiometer
16x2 LCD screen
tilt switch
Parts required:
220 ohm resistor
10 kilohm resistor
10 kilohm potentiometer
16x2 LCD screen
tilt switch
Created 13 September 2012
by Scott Fitzgerald
Created 13 September 2012
by Scott Fitzgerald
http://www.arduino.cc/starterKit
http://www.arduino.cc/starterKit
This example code is part of the public domain
This example code is part of the public domain
*/
// include the library code:

View File

@ -1,29 +1,29 @@
/*
Arduino Starter Kit example
Project 12 - Knock Lock
Project 12 - Knock Lock
This sketch is written to accompany Project 12 in the
Arduino Starter Kit
This sketch is written to accompany Project 12 in the
Arduino Starter Kit
Parts required:
1 Megohm resistor
10 kilohm resistor
three 220 ohm resistors
piezo
servo motor
push button
one red LED
one yellow LED
one green LED
100 uF capacitor
Parts required:
1 Megohm resistor
10 kilohm resistor
three 220 ohm resistors
piezo
servo motor
push button
one red LED
one yellow LED
one green LED
100 uF capacitor
Created 18 September 2012
by Scott Fitzgerald
Thanks to Federico Vanzati for improvements
Created 18 September 2012
by Scott Fitzgerald
Thanks to Federico Vanzati for improvements
http://www.arduino.cc/starterKit
http://www.arduino.cc/starterKit
This example code is part of the public domain
This example code is part of the public domain
*/
// import the library

View File

@ -1,26 +1,26 @@
/*
Arduino Starter Kit example
Project 13 - Touch Sensor Lamp
Project 13 - Touch Sensor Lamp
This sketch is written to accompany Project 13 in the
Arduino Starter Kit
This sketch is written to accompany Project 13 in the
Arduino Starter Kit
Parts required:
1 Megohm resistor
metal foil or copper mesh
220 ohm resistor
LED
Parts required:
1 Megohm resistor
metal foil or copper mesh
220 ohm resistor
LED
Software required :
CapacitiveSensor library by Paul Badger
http://www.arduino.cc/playground/Main/CapacitiveSensor
Software required :
CapacitiveSensor library by Paul Badger
http://www.arduino.cc/playground/Main/CapacitiveSensor
Created 18 September 2012
by Scott Fitzgerald
Created 18 September 2012
by Scott Fitzgerald
http://www.arduino.cc/starterKit
http://www.arduino.cc/starterKit
This example code is part of the public domain
This example code is part of the public domain
*/
// import the library (must be located in the

View File

@ -1,23 +1,23 @@
/*
Arduino Starter Kit example
Project 14 - Tweak the Arduino Logo
Project 14 - Tweak the Arduino Logo
This sketch is written to accompany Project 14 in the
Arduino Starter Kit
This sketch is written to accompany Project 14 in the
Arduino Starter Kit
Parts required:
10 kilohm potentiometer
Parts required:
10 kilohm potentiometer
Software required :
Processing (3.0 or newer) http://processing.org
Active Internet connection
Software required :
Processing (3.0 or newer) http://processing.org
Active Internet connection
Created 18 September 2012
by Scott Fitzgerald
Created 18 September 2012
by Scott Fitzgerald
http://www.arduino.cc/starterKit
http://www.arduino.cc/starterKit
This example code is part of the public domain
This example code is part of the public domain
*/
@ -34,69 +34,69 @@ void loop() {
}
/* Processing code for this example
// Tweak the Arduino Logo
// by Scott Fitzgerald
// This example code is in the public domain
// Tweak the Arduino Logo
// by Scott Fitzgerald
// This example code is in the public domain
// import the serial library
import processing.serial.*;
// import the serial library
import processing.serial.*;
// create an instance of the serial library
Serial myPort;
// create an instance of the serial library
Serial myPort;
// create an instance of PImage
PImage logo;
// create an instance of PImage
PImage logo;
// a variable to hold the background color
int bgcolor = 0;
// a variable to hold the background color
int bgcolor = 0;
void setup() {
size(1, 1);
surface.setResizable(true);
// set the color mode to Hue/Saturation/Brightness
colorMode(HSB, 255);
void setup() {
size(1, 1);
surface.setResizable(true);
// set the color mode to Hue/Saturation/Brightness
colorMode(HSB, 255);
// load the Arduino logo into the PImage instance
logo = loadImage("http://www.arduino.cc/arduino_logo.png");
// load the Arduino logo into the PImage instance
logo = loadImage("http://www.arduino.cc/arduino_logo.png");
// make the window the same size as the image
surface.setSize(logo.width, logo.height);
// make the window the same size as the image
surface.setSize(logo.width, logo.height);
// print a list of available serial ports to the
// Processing status window
println("Available serial ports:");
println(Serial.list());
// print a list of available serial ports to the
// Processing status window
println("Available serial ports:");
println(Serial.list());
// Tell the serial object the information it needs to communicate
// with the Arduino. Change Serial.list()[0] to the correct
// port corresponding to your Arduino board. The last
// parameter (e.g. 9600) is the speed of the communication. It
// has to correspond to the value passed to Serial.begin() in your
// Arduino sketch.
myPort = new Serial(this, Serial.list()[0], 9600);
// Tell the serial object the information it needs to communicate
// with the Arduino. Change Serial.list()[0] to the correct
// port corresponding to your Arduino board. The last
// parameter (e.g. 9600) is the speed of the communication. It
// has to correspond to the value passed to Serial.begin() in your
// Arduino sketch.
myPort = new Serial(this, Serial.list()[0], 9600);
// If you know the name of the port used by the Arduino board, you
// can specify it directly like this.
// port = new Serial(this, "COM1", 9600);
}
void draw() {
// if there is information in the serial port
if ( myPort.available() > 0) {
// read the value and store it in a variable
bgcolor = myPort.read();
// print the value to the status window
println(bgcolor);
// If you know the name of the port used by the Arduino board, you
// can specify it directly like this.
// port = new Serial(this, "COM1", 9600);
}
// Draw the background. the variable bgcolor
// contains the Hue, determined by the value
// from the serial port
background(bgcolor, 255, 255);
void draw() {
// draw the Arduino logo
image(logo, 0, 0);
}
// if there is information in the serial port
if ( myPort.available() > 0) {
// read the value and store it in a variable
bgcolor = myPort.read();
// print the value to the status window
println(bgcolor);
}
// Draw the background. the variable bgcolor
// contains the Hue, determined by the value
// from the serial port
background(bgcolor, 255, 255);
// draw the Arduino logo
image(logo, 0, 0);
}
*/

View File

@ -1,21 +1,21 @@
/*
Arduino Starter Kit example
Project 15 - Hacking Buttons
Project 15 - Hacking Buttons
This sketch is written to accompany Project 15 in the
Arduino Starter Kit
This sketch is written to accompany Project 15 in the
Arduino Starter Kit
Parts required:
battery powered component
220 ohm resistor
4N35 optocoupler
Parts required:
battery powered component
220 ohm resistor
4N35 optocoupler
Created 18 September 2012
by Scott Fitzgerald
Created 18 September 2012
by Scott Fitzgerald
http://www.arduino.cc/starterKit
http://www.arduino.cc/starterKit
This example code is part of the public domain
This example code is part of the public domain
*/
const int optoPin = 2; // the pin the optocoupler is connected to