mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-18 07:52:14 +01:00
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:
parent
499c424d59
commit
8f48433f33
@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
DigitalReadSerial
|
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:
|
// digital pin 2 has a pushbutton attached to it. Give it a name:
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
Fade
|
Fade
|
||||||
|
|
||||||
This example shows how to fade an LED on pin 9
|
This example shows how to fade an LED on pin 9
|
||||||
using the analogWrite() function.
|
using the analogWrite() function.
|
||||||
|
|
||||||
The analogWrite() function uses PWM, so if
|
The analogWrite() function uses PWM, so if
|
||||||
you want to change the pin you're using, be
|
you want to change the pin you're using, be
|
||||||
sure to use another PWM capable pin. On most
|
sure to use another PWM capable pin. On most
|
||||||
Arduino, the PWM pins are identified with
|
Arduino, the PWM pins are identified with
|
||||||
a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11.
|
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
|
int led = 9; // the PWM pin the LED is attached to
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
/* Blink without Delay
|
/* Blink without Delay
|
||||||
|
|
||||||
Turns on and off a light emitting diode (LED) connected to a digital
|
Turns on and off a light emitting diode (LED) connected to a digital
|
||||||
pin, without using the delay() function. This means that other code
|
pin, without using the delay() function. This means that other code
|
||||||
can run at the same time without being interrupted by the LED code.
|
can run at the same time without being interrupted by the LED code.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
- Use the onboard LED.
|
- Use the onboard LED.
|
||||||
- Note: Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
|
- 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
|
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.
|
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
|
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 Technical Specs of your board at https://www.arduino.cc/en/Main/Products
|
||||||
|
|
||||||
created 2005
|
created 2005
|
||||||
by David A. Mellis
|
by David A. Mellis
|
||||||
modified 8 Feb 2010
|
modified 8 Feb 2010
|
||||||
by Paul Stoffregen
|
by Paul Stoffregen
|
||||||
modified 11 Nov 2013
|
modified 11 Nov 2013
|
||||||
by Scott Fitzgerald
|
by Scott Fitzgerald
|
||||||
modified 9 Jan 2017
|
modified 9 Jan 2017
|
||||||
by Arturo Guadalupi
|
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:
|
// constants won't change. Used here to set a pin number:
|
||||||
|
@ -1,27 +1,27 @@
|
|||||||
/*
|
/*
|
||||||
Button
|
Button
|
||||||
|
|
||||||
Turns on and off a light emitting diode(LED) connected to digital
|
Turns on and off a light emitting diode(LED) connected to digital
|
||||||
pin 13, when pressing a pushbutton attached to pin 2.
|
pin 13, when pressing a pushbutton attached to pin 2.
|
||||||
|
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
- LED attached from pin 13 to ground
|
- LED attached from pin 13 to ground
|
||||||
- pushbutton attached to pin 2 from +5V
|
- pushbutton attached to pin 2 from +5V
|
||||||
- 10K resistor attached to pin 2 from ground
|
- 10K resistor attached to pin 2 from ground
|
||||||
|
|
||||||
- Note: on most Arduinos there is already an LED on the board
|
- Note: on most Arduinos there is already an LED on the board
|
||||||
attached to pin 13.
|
attached to pin 13.
|
||||||
|
|
||||||
|
|
||||||
created 2005
|
created 2005
|
||||||
by DojoDave <http://www.0j0.org>
|
by DojoDave <http://www.0j0.org>
|
||||||
modified 30 Aug 2011
|
modified 30 Aug 2011
|
||||||
by Tom Igoe
|
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
|
// constants won't change. They're used here to
|
||||||
|
@ -1,33 +1,33 @@
|
|||||||
/*
|
/*
|
||||||
Debounce
|
Debounce
|
||||||
|
|
||||||
Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
|
Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
|
||||||
press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's
|
press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's
|
||||||
a minimum delay between toggles to debounce the circuit (i.e. to ignore
|
a minimum delay between toggles to debounce the circuit (i.e. to ignore
|
||||||
noise).
|
noise).
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
- LED attached from pin 13 to ground
|
- LED attached from pin 13 to ground
|
||||||
- pushbutton attached from pin 2 to +5V
|
- pushbutton attached from pin 2 to +5V
|
||||||
- 10K resistor attached from pin 2 to ground
|
- 10K resistor attached from pin 2 to ground
|
||||||
|
|
||||||
- Note: On most Arduino boards, there is already an LED on the board
|
- 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.
|
connected to pin 13, so you don't need any extra components for this example.
|
||||||
|
|
||||||
|
|
||||||
created 21 November 2006
|
created 21 November 2006
|
||||||
by David A. Mellis
|
by David A. Mellis
|
||||||
modified 30 Aug 2011
|
modified 30 Aug 2011
|
||||||
by Limor Fried
|
by Limor Fried
|
||||||
modified 28 Dec 2012
|
modified 28 Dec 2012
|
||||||
by Mike Walters
|
by Mike Walters
|
||||||
modified 30 Aug 2016
|
modified 30 Aug 2016
|
||||||
by Arturo Guadalupi
|
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
|
// constants won't change. They're used here to
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
Input Pull-up Serial
|
Input Pull-up Serial
|
||||||
|
|
||||||
This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a
|
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.
|
digital input on pin 2 and prints the results to the Serial Monitor.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
- Momentary switch attached from pin 2 to ground
|
- Momentary switch attached from pin 2 to ground
|
||||||
- Built-in LED on pin 13
|
- Built-in LED on pin 13
|
||||||
|
|
||||||
Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal
|
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
|
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.
|
read HIGH when the switch is open, and LOW when it is closed.
|
||||||
|
|
||||||
created 14 March 2012
|
created 14 March 2012
|
||||||
by Scott Fitzgerald
|
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
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,27 +1,27 @@
|
|||||||
/*
|
/*
|
||||||
State change detection (edge detection)
|
State change detection (edge detection)
|
||||||
|
|
||||||
Often, you don't need to know the state of a digital input all the time,
|
Often, you don't need to know the state of a digital input all the time,
|
||||||
but you just need to know when the input changes from one state to another.
|
but you just need to know when the input changes from one state to another.
|
||||||
For example, you want to know when a button goes from OFF to ON. This is called
|
For example, you want to know when a button goes from OFF to ON. This is called
|
||||||
state change detection, or edge detection.
|
state change detection, or edge detection.
|
||||||
|
|
||||||
This example shows how to detect when a button or button changes from off to on
|
This example shows how to detect when a button or button changes from off to on
|
||||||
and on to off.
|
and on to off.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
- pushbutton attached to pin 2 from +5V
|
- pushbutton attached to pin 2 from +5V
|
||||||
- 10K resistor attached to pin 2 from ground
|
- 10K resistor attached to pin 2 from ground
|
||||||
- LED attached from pin 13 to ground (or use the built-in LED on
|
- LED attached from pin 13 to ground (or use the built-in LED on
|
||||||
most Arduino boards)
|
most Arduino boards)
|
||||||
|
|
||||||
created 27 Sep 2005
|
created 27 Sep 2005
|
||||||
modified 30 Aug 2011
|
modified 30 Aug 2011
|
||||||
by Tom Igoe
|
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
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
keyboard
|
keyboard
|
||||||
|
|
||||||
Plays a pitch that changes based on a changing analog input
|
Plays a pitch that changes based on a changing analog input
|
||||||
|
|
||||||
circuit:
|
circuit:
|
||||||
- 3 force-sensing resistors from +5V to analog in 0 through 5
|
- 3 force-sensing resistors from +5V to analog in 0 through 5
|
||||||
- 3 10K resistors from analog in 0 through 5 to ground
|
- 3 10K resistors from analog in 0 through 5 to ground
|
||||||
- 8-ohm speaker on digital pin 8
|
- 8-ohm speaker on digital pin 8
|
||||||
|
|
||||||
created 21 Jan 2010
|
created 21 Jan 2010
|
||||||
modified 9 Apr 2012
|
modified 9 Apr 2012
|
||||||
by Tom Igoe
|
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
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
Melody
|
Melody
|
||||||
|
|
||||||
Plays a melody
|
Plays a melody
|
||||||
|
|
||||||
circuit:
|
circuit:
|
||||||
- 8-ohm speaker on digital pin 8
|
- 8-ohm speaker on digital pin 8
|
||||||
|
|
||||||
created 21 Jan 2010
|
created 21 Jan 2010
|
||||||
modified 30 Aug 2011
|
modified 30 Aug 2011
|
||||||
by Tom Igoe
|
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"
|
#include "pitches.h"
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
Multiple tone player
|
Multiple tone player
|
||||||
|
|
||||||
Plays multiple tones on multiple pins in sequence
|
Plays multiple tones on multiple pins in sequence
|
||||||
|
|
||||||
circuit:
|
circuit:
|
||||||
- 3 8-ohm speaker on digital pins 6, 7, and 8
|
- 3 8-ohm speaker on digital pins 6, 7, and 8
|
||||||
|
|
||||||
created 8 March 2010
|
created 8 March 2010
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
based on a snippet from Greg Borenstein
|
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
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
Pitch follower
|
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:
|
circuit:
|
||||||
- 8-ohm speaker on digital pin 9
|
- 8-ohm speaker on digital pin 9
|
||||||
- photoresistor on analog 0 to 5V
|
- photoresistor on analog 0 to 5V
|
||||||
- 4.7K resistor on analog 0 to ground
|
- 4.7K resistor on analog 0 to ground
|
||||||
|
|
||||||
created 21 Jan 2010
|
created 21 Jan 2010
|
||||||
modified 31 May 2012
|
modified 31 May 2012
|
||||||
by Tom Igoe, with suggestion from Michael Flynn
|
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
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
/*
|
/*
|
||||||
Analog input, analog output, serial output
|
Analog input, analog output, serial output
|
||||||
|
|
||||||
Reads an analog input pin, maps the result to a range from 0 to 255
|
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.
|
and uses the result to set the pulse width modulation (PWM) of an output pin.
|
||||||
Also prints the results to the Serial Monitor.
|
Also prints the results to the Serial Monitor.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
- potentiometer connected to analog pin 0.
|
- potentiometer connected to analog pin 0.
|
||||||
Center pin of the potentiometer goes to the analog pin.
|
Center pin of the potentiometer goes to the analog pin.
|
||||||
side pins of the potentiometer go to +5V and ground
|
side pins of the potentiometer go to +5V and ground
|
||||||
- LED connected from digital pin 9 to ground
|
- LED connected from digital pin 9 to ground
|
||||||
|
|
||||||
created 29 Dec. 2008
|
created 29 Dec. 2008
|
||||||
modified 9 Apr 2012
|
modified 9 Apr 2012
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,29 +1,29 @@
|
|||||||
/*
|
/*
|
||||||
Analog Input
|
Analog Input
|
||||||
Demonstrates analog input by reading an analog sensor on analog pin 0 and
|
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.
|
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 amount of time the LED will be on and off depends on
|
||||||
the value obtained by analogRead().
|
the value obtained by analogRead().
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
- Potentiometer attached to analog input 0
|
- Potentiometer attached to analog input 0
|
||||||
- center pin of the potentiometer to the analog pin
|
- center pin of the potentiometer to the analog pin
|
||||||
- one side pin (either one) to ground
|
- one side pin (either one) to ground
|
||||||
- the other side pin to +5V
|
- the other side pin to +5V
|
||||||
- LED anode (long leg) attached to digital output 13
|
- LED anode (long leg) attached to digital output 13
|
||||||
- LED cathode (short leg) attached to ground
|
- LED cathode (short leg) attached to ground
|
||||||
|
|
||||||
- Note: because most Arduinos have a built-in LED attached
|
- Note: because most Arduinos have a built-in LED attached
|
||||||
to pin 13 on the board, the LED is optional.
|
to pin 13 on the board, the LED is optional.
|
||||||
|
|
||||||
|
|
||||||
Created by David Cuartielles
|
Created by David Cuartielles
|
||||||
modified 30 Aug 2011
|
modified 30 Aug 2011
|
||||||
By Tom Igoe
|
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
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,28 +1,28 @@
|
|||||||
/*
|
/*
|
||||||
Calibration
|
Calibration
|
||||||
|
|
||||||
Demonstrates one technique for calibrating sensor input. The
|
Demonstrates one technique for calibrating sensor input. The
|
||||||
sensor readings during the first five seconds of the sketch
|
sensor readings during the first five seconds of the sketch
|
||||||
execution define the minimum and maximum of expected values
|
execution define the minimum and maximum of expected values
|
||||||
attached to the sensor pin.
|
attached to the sensor pin.
|
||||||
|
|
||||||
The sensor minimum and maximum initial values may seem backwards.
|
The sensor minimum and maximum initial values may seem backwards.
|
||||||
Initially, you set the minimum high and listen for anything
|
Initially, you set the minimum high and listen for anything
|
||||||
lower, saving it as the new minimum. Likewise, you set the
|
lower, saving it as the new minimum. Likewise, you set the
|
||||||
maximum low and listen for anything higher as the new maximum.
|
maximum low and listen for anything higher as the new maximum.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
- Analog sensor (potentiometer will do) attached to analog input 0
|
- Analog sensor (potentiometer will do) attached to analog input 0
|
||||||
- LED attached from digital pin 9 to ground
|
- LED attached from digital pin 9 to ground
|
||||||
|
|
||||||
created 29 Oct 2008
|
created 29 Oct 2008
|
||||||
By David A Mellis
|
By David A Mellis
|
||||||
modified 30 Aug 2011
|
modified 30 Aug 2011
|
||||||
By Tom Igoe
|
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.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -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:
|
The circuit:
|
||||||
- LED attached from digital pin 9 to ground.
|
- LED attached from digital pin 9 to ground.
|
||||||
|
|
||||||
Created 1 Nov 2008
|
Created 1 Nov 2008
|
||||||
By David A. Mellis
|
By David A. Mellis
|
||||||
modified 30 Aug 2011
|
modified 30 Aug 2011
|
||||||
By Tom Igoe
|
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.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
/*
|
/*
|
||||||
ASCII table
|
ASCII table
|
||||||
|
|
||||||
Prints out byte values in all possible formats:
|
Prints out byte values in all possible formats:
|
||||||
- as raw binary values
|
- as raw binary values
|
||||||
- as ASCII-encoded decimal, hex, octal, and 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
|
created 2006
|
||||||
by Nicholas Zambetti
|
by Nicholas Zambetti
|
||||||
modified 9 Apr 2012
|
modified 9 Apr 2012
|
||||||
by Tom Igoe
|
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() {
|
void setup() {
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
Dimmer
|
Dimmer
|
||||||
|
|
||||||
Demonstrates sending data from the computer to the Arduino board,
|
Demonstrates sending data from the computer to the Arduino board,
|
||||||
in this case to control the brightness of an LED. The data is sent
|
in this case to control the brightness of an LED. The data is sent
|
||||||
in individual bytes, each of which ranges from 0 to 255. Arduino
|
in individual bytes, each of which ranges from 0 to 255. Arduino
|
||||||
reads these bytes and uses them to set the brightness of the LED.
|
reads these bytes and uses them to set the brightness of the LED.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
LED attached from digital pin 9 to ground.
|
LED attached from digital pin 9 to ground.
|
||||||
Serial connection to Processing, Max/MSP, or another serial application
|
Serial connection to Processing, Max/MSP, or another serial application
|
||||||
|
|
||||||
created 2006
|
created 2006
|
||||||
by David A. Mellis
|
by David A. Mellis
|
||||||
modified 30 Aug 2011
|
modified 30 Aug 2011
|
||||||
by Tom Igoe and Scott Fitzgerald
|
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
|
/* Processing code for this example
|
||||||
// Dimmer - sends bytes over a serial port
|
// Dimmer - sends bytes over a serial port
|
||||||
// by David A. Mellis
|
// by David A. Mellis
|
||||||
// This example code is in the public domain.
|
// This example code is in the public domain.
|
||||||
|
|
||||||
import processing.serial.*;
|
import processing.serial.*;
|
||||||
Serial port;
|
Serial port;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
size(256, 150);
|
size(256, 150);
|
||||||
|
|
||||||
println("Available serial ports:");
|
println("Available serial ports:");
|
||||||
// if using Processing 2.1 or later, use Serial.printArray()
|
// if using Processing 2.1 or later, use Serial.printArray()
|
||||||
println(Serial.list());
|
println(Serial.list());
|
||||||
|
|
||||||
// Uses the first port in this list (number 0). Change this to
|
// Uses the first port in this list (number 0). Change this to
|
||||||
// select the port corresponding to your Arduino board. The last
|
// select the port corresponding to your Arduino board. The last
|
||||||
// parameter (e.g. 9600) is the speed of the communication. It
|
// parameter (e.g. 9600) is the speed of the communication. It
|
||||||
// has to correspond to the value passed to Serial.begin() in your
|
// has to correspond to the value passed to Serial.begin() in your
|
||||||
// Arduino sketch.
|
// Arduino sketch.
|
||||||
port = new Serial(this, Serial.list()[0], 9600);
|
port = new Serial(this, Serial.list()[0], 9600);
|
||||||
|
|
||||||
// If you know the name of the port used by the Arduino board, you
|
// If you know the name of the port used by the Arduino board, you
|
||||||
// can specify it directly like this.
|
// can specify it directly like this.
|
||||||
//port = new Serial(this, "COM1", 9600);
|
//port = new Serial(this, "COM1", 9600);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw() {
|
void draw() {
|
||||||
// draw a gradient from black to white
|
// draw a gradient from black to white
|
||||||
for (int i = 0; i < 256; i++) {
|
for (int i = 0; i < 256; i++) {
|
||||||
stroke(i);
|
stroke(i);
|
||||||
line(i, 0, i, 150);
|
line(i, 0, i, 150);
|
||||||
}
|
}
|
||||||
|
|
||||||
// write the current X-position of the mouse to the serial port as
|
// write the current X-position of the mouse to the serial port as
|
||||||
// a single byte
|
// a single byte
|
||||||
port.write(mouseX);
|
port.write(mouseX);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Max/MSP v5 patch for this example
|
/* Max/MSP v5 patch for this example
|
||||||
|
@ -1,29 +1,29 @@
|
|||||||
/*
|
/*
|
||||||
Graph
|
Graph
|
||||||
|
|
||||||
A simple example of communication from the Arduino board to the computer:
|
A simple example of communication from the Arduino board to the computer:
|
||||||
the value of analog input 0 is sent out the serial port. We call this "serial"
|
the value of analog input 0 is sent out the serial port. We call this "serial"
|
||||||
communication because the connection appears to both the Arduino and the
|
communication because the connection appears to both the Arduino and the
|
||||||
computer as a serial port, even though it may actually use
|
computer as a serial port, even though it may actually use
|
||||||
a USB cable. Bytes are sent one after another (serially) from the Arduino
|
a USB cable. Bytes are sent one after another (serially) from the Arduino
|
||||||
to the computer.
|
to the computer.
|
||||||
|
|
||||||
You can use the Arduino Serial Monitor to view the sent data, or it can
|
You can use the Arduino Serial Monitor to view the sent data, or it can
|
||||||
be read by Processing, PD, Max/MSP, or any other program capable of reading
|
be read by Processing, PD, Max/MSP, or any other program capable of reading
|
||||||
data from a serial port. The Processing code below graphs the data received
|
data from a serial port. The Processing code below graphs the data received
|
||||||
so you can see the value of the analog input changing over time.
|
so you can see the value of the analog input changing over time.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
Any analog input sensor is attached to analog in pin 0.
|
Any analog input sensor is attached to analog in pin 0.
|
||||||
|
|
||||||
created 2006
|
created 2006
|
||||||
by David A. Mellis
|
by David A. Mellis
|
||||||
modified 9 Apr 2012
|
modified 9 Apr 2012
|
||||||
by Tom Igoe and Scott Fitzgerald
|
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() {
|
void setup() {
|
||||||
@ -41,72 +41,72 @@ void loop() {
|
|||||||
|
|
||||||
/* Processing code for this example
|
/* Processing code for this example
|
||||||
|
|
||||||
// Graphing sketch
|
// Graphing sketch
|
||||||
|
|
||||||
|
|
||||||
// This program takes ASCII-encoded strings
|
// This program takes ASCII-encoded strings
|
||||||
// from the serial port at 9600 baud and graphs them. It expects values in the
|
// 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
|
// range 0 to 1023, followed by a newline, or newline and carriage return
|
||||||
|
|
||||||
// Created 20 Apr 2005
|
// Created 20 Apr 2005
|
||||||
// Updated 24 Nov 2015
|
// Updated 24 Nov 2015
|
||||||
// by Tom Igoe
|
// by Tom Igoe
|
||||||
// This example code is in the public domain.
|
// This example code is in the public domain.
|
||||||
|
|
||||||
import processing.serial.*;
|
import processing.serial.*;
|
||||||
|
|
||||||
Serial myPort; // The serial port
|
Serial myPort; // The serial port
|
||||||
int xPos = 1; // horizontal position of the graph
|
int xPos = 1; // horizontal position of the graph
|
||||||
float inByte = 0;
|
float inByte = 0;
|
||||||
|
|
||||||
void setup () {
|
void setup () {
|
||||||
// set the window size:
|
// set the window size:
|
||||||
size(400, 300);
|
size(400, 300);
|
||||||
|
|
||||||
// List all the available serial ports
|
// List all the available serial ports
|
||||||
// if using Processing 2.1 or later, use Serial.printArray()
|
// if using Processing 2.1 or later, use Serial.printArray()
|
||||||
println(Serial.list());
|
println(Serial.list());
|
||||||
|
|
||||||
// I know that the first port in the serial list on my Mac
|
// I know that the first port in the serial list on my Mac
|
||||||
// is always my Arduino, so I open Serial.list()[0].
|
// is always my Arduino, so I open Serial.list()[0].
|
||||||
// Open whatever port is the one you're using.
|
// Open whatever port is the one you're using.
|
||||||
myPort = new Serial(this, Serial.list()[0], 9600);
|
myPort = new Serial(this, Serial.list()[0], 9600);
|
||||||
|
|
||||||
// don't generate a serialEvent() unless you get a newline character:
|
// don't generate a serialEvent() unless you get a newline character:
|
||||||
myPort.bufferUntil('\n');
|
myPort.bufferUntil('\n');
|
||||||
|
|
||||||
// set initial background:
|
// 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;
|
|
||||||
background(0);
|
background(0);
|
||||||
} else {
|
|
||||||
// increment the horizontal position:
|
|
||||||
xPos++;
|
|
||||||
}
|
}
|
||||||
}
|
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:
|
||||||
void serialEvent (Serial myPort) {
|
if (xPos >= width) {
|
||||||
// get the ASCII string:
|
xPos = 0;
|
||||||
String inString = myPort.readStringUntil('\n');
|
background(0);
|
||||||
|
} else {
|
||||||
if (inString != null) {
|
// increment the horizontal position:
|
||||||
// trim off any whitespace:
|
xPos++;
|
||||||
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);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -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.
|
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
|
If this circuit is connected to a MIDI synth, it will play
|
||||||
the notes F#-0 (0x1E) to F#-5 (0x5A) in sequence.
|
the notes F#-0 (0x1E) to F#-5 (0x5A) in sequence.
|
||||||
|
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
- digital in 1 connected to MIDI jack pin 5
|
- digital in 1 connected to MIDI jack pin 5
|
||||||
- MIDI jack pin 2 connected to ground
|
- MIDI jack pin 2 connected to ground
|
||||||
- MIDI jack pin 4 connected to +5V through 220-ohm resistor
|
- 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.
|
Attach a MIDI cable to the jack, then to a MIDI synth, and play music.
|
||||||
|
|
||||||
created 13 Jun 2006
|
created 13 Jun 2006
|
||||||
modified 13 Aug 2012
|
modified 13 Aug 2012
|
||||||
by Tom Igoe
|
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
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
/*
|
/*
|
||||||
Multiple Serial test
|
Multiple Serial test
|
||||||
|
|
||||||
Receives from the main serial port, sends to the others.
|
Receives from the main serial port, sends to the others.
|
||||||
Receives from serial port 1, sends to the main serial (Serial 0).
|
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:
|
The circuit:
|
||||||
- Any serial device attached to Serial port 1
|
- Any serial device attached to Serial port 1
|
||||||
- Serial monitor open on Serial port 0:
|
- Serial monitor open on Serial port 0:
|
||||||
|
|
||||||
created 30 Dec. 2008
|
created 30 Dec. 2008
|
||||||
modified 20 May 2012
|
modified 20 May 2012
|
||||||
by Tom Igoe & Jed Roach
|
by Tom Igoe & Jed Roach
|
||||||
modified 27 Nov 2015
|
modified 27 Nov 2015
|
||||||
by Arturo Guadalupi
|
by Arturo Guadalupi
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,26 +1,26 @@
|
|||||||
/*
|
/*
|
||||||
Physical Pixel
|
Physical Pixel
|
||||||
|
|
||||||
An example of using the Arduino board to receive data from the
|
An example of using the Arduino board to receive data from the
|
||||||
computer. In this case, the Arduino boards turns on an LED when
|
computer. In this case, the Arduino boards turns on an LED when
|
||||||
it receives the character 'H', and turns off the LED when it
|
it receives the character 'H', and turns off the LED when it
|
||||||
receives the character 'L'.
|
receives the character 'L'.
|
||||||
|
|
||||||
The data can be sent from the Arduino Serial Monitor, or another
|
The data can be sent from the Arduino Serial Monitor, or another
|
||||||
program like Processing (see code below), Flash (via a serial-net
|
program like Processing (see code below), Flash (via a serial-net
|
||||||
proxy), PD, or Max/MSP.
|
proxy), PD, or Max/MSP.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
- LED connected from digital pin 13 to ground
|
- LED connected from digital pin 13 to ground
|
||||||
|
|
||||||
created 2006
|
created 2006
|
||||||
by David A. Mellis
|
by David A. Mellis
|
||||||
modified 30 Aug 2011
|
modified 30 Aug 2011
|
||||||
by Tom Igoe and Scott Fitzgerald
|
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
|
const int ledPin = 13; // the pin that the LED is attached to
|
||||||
@ -51,74 +51,74 @@ void loop() {
|
|||||||
|
|
||||||
/* Processing code for this example
|
/* 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
|
// 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
|
// turn ON a light if the mouse is over a square and turn it off
|
||||||
// if the mouse is not.
|
// if the mouse is not.
|
||||||
|
|
||||||
// created 2003-4
|
// created 2003-4
|
||||||
// based on examples by Casey Reas and Hernando Barragan
|
// based on examples by Casey Reas and Hernando Barragan
|
||||||
// modified 30 Aug 2011
|
// modified 30 Aug 2011
|
||||||
// by Tom Igoe
|
// by Tom Igoe
|
||||||
// This example code is in the public domain.
|
// This example code is in the public domain.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import processing.serial.*;
|
import processing.serial.*;
|
||||||
|
|
||||||
float boxX;
|
float boxX;
|
||||||
float boxY;
|
float boxY;
|
||||||
int boxSize = 20;
|
int boxSize = 20;
|
||||||
boolean mouseOverBox = false;
|
boolean mouseOverBox = false;
|
||||||
|
|
||||||
Serial port;
|
Serial port;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
size(200, 200);
|
size(200, 200);
|
||||||
boxX = width/2.0;
|
boxX = width/2.0;
|
||||||
boxY = height/2.0;
|
boxY = height/2.0;
|
||||||
rectMode(RADIUS);
|
rectMode(RADIUS);
|
||||||
|
|
||||||
// List all the available serial ports in the output pane.
|
// List all the available serial ports in the output pane.
|
||||||
// You will need to choose the port that the Arduino board is
|
// You will need to choose the port that the Arduino board is
|
||||||
// connected to from this list. The first port in the list 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.
|
// port #0 and the third port in the list is port #2.
|
||||||
// if using Processing 2.1 or later, use Serial.printArray()
|
// if using Processing 2.1 or later, use Serial.printArray()
|
||||||
println(Serial.list());
|
println(Serial.list());
|
||||||
|
|
||||||
// Open the port that the Arduino board is connected to (in this case #0)
|
// 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)
|
// Make sure to open the port at the same speed Arduino is using (9600bps)
|
||||||
port = new Serial(this, Serial.list()[0], 9600);
|
port = new Serial(this, Serial.list()[0], 9600);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw()
|
void draw()
|
||||||
{
|
{
|
||||||
background(0);
|
background(0);
|
||||||
|
|
||||||
// Test if the cursor is over the box
|
// Test if the cursor is over the box
|
||||||
if (mouseX > boxX-boxSize && mouseX < boxX+boxSize &&
|
if (mouseX > boxX-boxSize && mouseX < boxX+boxSize &&
|
||||||
mouseY > boxY-boxSize && mouseY < boxY+boxSize) {
|
mouseY > boxY-boxSize && mouseY < boxY+boxSize) {
|
||||||
mouseOverBox = true;
|
mouseOverBox = true;
|
||||||
// draw a line around the box and change its color:
|
// draw a line around the box and change its color:
|
||||||
stroke(255);
|
stroke(255);
|
||||||
fill(153);
|
fill(153);
|
||||||
// send an 'H' to indicate mouse is over square:
|
// send an 'H' to indicate mouse is over square:
|
||||||
port.write('H');
|
port.write('H');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// return the box to its inactive state:
|
// return the box to its inactive state:
|
||||||
stroke(153);
|
stroke(153);
|
||||||
fill(153);
|
fill(153);
|
||||||
// send an 'L' to turn the LED off:
|
// send an 'L' to turn the LED off:
|
||||||
port.write('L');
|
port.write('L');
|
||||||
mouseOverBox = false;
|
mouseOverBox = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw the box
|
// Draw the box
|
||||||
rect(boxX, boxY, boxSize, boxSize);
|
rect(boxX, boxY, boxSize, boxSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
Reading a serial ASCII-encoded string.
|
Reading a serial ASCII-encoded string.
|
||||||
|
|
||||||
This sketch demonstrates the Serial parseInt() function.
|
This sketch demonstrates the Serial parseInt() function.
|
||||||
It looks for an ASCII string of comma-separated values.
|
It looks for an ASCII string of comma-separated values.
|
||||||
It parses them into ints, and uses those to fade an RGB LED.
|
It parses them into ints, and uses those to fade an RGB LED.
|
||||||
|
|
||||||
Circuit: Common-Cathode RGB LED wired like so:
|
Circuit: Common-Cathode RGB LED wired like so:
|
||||||
- Red anode: digital pin 3
|
- Red anode: digital pin 3
|
||||||
- Green anode: digital pin 5
|
- Green anode: digital pin 5
|
||||||
- Blue anode: digital pin 6
|
- Blue anode: digital pin 6
|
||||||
- Cathode : GND
|
- Cathode : GND
|
||||||
|
|
||||||
created 13 Apr 2012
|
created 13 Apr 2012
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
|
|
||||||
modified 14 Mar 2016
|
modified 14 Mar 2016
|
||||||
by Arturo Guadalupi
|
by Arturo Guadalupi
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// pins for the LEDs:
|
// pins for the LEDs:
|
||||||
|
@ -1,26 +1,26 @@
|
|||||||
/*
|
/*
|
||||||
Serial Call and Response
|
Serial Call and Response
|
||||||
Language: Wiring/Arduino
|
Language: Wiring/Arduino
|
||||||
|
|
||||||
This program sends an ASCII A (byte of value 65) on startup
|
This program sends an ASCII A (byte of value 65) on startup
|
||||||
and repeats that until it gets some data in.
|
and repeats that until it gets some data in.
|
||||||
Then it waits for a byte in the serial port, and
|
Then it waits for a byte in the serial port, and
|
||||||
sends three sensor values whenever it gets a byte in.
|
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:
|
The circuit:
|
||||||
- potentiometers attached to analog inputs 0 and 1
|
- potentiometers attached to analog inputs 0 and 1
|
||||||
- pushbutton attached to digital I/O 2
|
- pushbutton attached to digital I/O 2
|
||||||
|
|
||||||
Created 26 Sept. 2005
|
Created 26 Sept. 2005
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
modified 24 April 2012
|
modified 24 April 2012
|
||||||
by Tom Igoe and Scott Fitzgerald
|
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 bgcolor; // Background color
|
||||||
int fgcolor; // Fill color
|
int fgcolor; // Fill color
|
||||||
Serial myPort; // The serial port
|
Serial myPort; // The serial port
|
||||||
int[] serialInArray = new int[3]; // Where we'll put what we receive
|
int[] serialInArray = new int[3]; // Where we'll put what we receive
|
||||||
int serialCount = 0; // A count of how many bytes we receive
|
int serialCount = 0; // A count of how many bytes we receive
|
||||||
int xpos, ypos; // Starting position of the ball
|
int xpos, ypos; // Starting position of the ball
|
||||||
boolean firstContact = false; // Whether we've heard from the microcontroller
|
boolean firstContact = false; // Whether we've heard from the microcontroller
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
size(256, 256); // Stage size
|
size(256, 256); // Stage size
|
||||||
noStroke(); // No border on the next thing drawn
|
noStroke(); // No border on the next thing drawn
|
||||||
|
|
||||||
// Set the starting position of the ball (middle of the stage)
|
// Set the starting position of the ball (middle of the stage)
|
||||||
xpos = width/2;
|
xpos = width/2;
|
||||||
ypos = height/2;
|
ypos = height/2;
|
||||||
|
|
||||||
// Print a list of the serial ports for debugging purposes
|
// Print a list of the serial ports for debugging purposes
|
||||||
// if using Processing 2.1 or later, use Serial.printArray()
|
// if using Processing 2.1 or later, use Serial.printArray()
|
||||||
println(Serial.list());
|
println(Serial.list());
|
||||||
|
|
||||||
// I know that the first port in the serial list on my Mac
|
// I know that the first port in the serial list on my Mac
|
||||||
// is always my FTDI adaptor, so I open Serial.list()[0].
|
// is always my FTDI adaptor, so I open Serial.list()[0].
|
||||||
// On Windows machines, this generally opens COM1.
|
// On Windows machines, this generally opens COM1.
|
||||||
// Open whatever port is the one you're using.
|
// Open whatever port is the one you're using.
|
||||||
String portName = Serial.list()[0];
|
String portName = Serial.list()[0];
|
||||||
myPort = new Serial(this, portName, 9600);
|
myPort = new Serial(this, portName, 9600);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw() {
|
void draw() {
|
||||||
background(bgcolor);
|
background(bgcolor);
|
||||||
fill(fgcolor);
|
fill(fgcolor);
|
||||||
// Draw the shape
|
// Draw the shape
|
||||||
ellipse(xpos, ypos, 20, 20);
|
ellipse(xpos, ypos, 20, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
void serialEvent(Serial myPort) {
|
void serialEvent(Serial myPort) {
|
||||||
// read a byte from the serial port:
|
// read a byte from the serial port:
|
||||||
int inByte = myPort.read();
|
int inByte = myPort.read();
|
||||||
// if this is the first byte received, and it's an A,
|
// if this is the first byte received, and it's an A,
|
||||||
// clear the serial buffer and note that you've
|
// clear the serial buffer and note that you've
|
||||||
// had first contact from the microcontroller.
|
// had first contact from the microcontroller.
|
||||||
// Otherwise, add the incoming byte to the array:
|
// Otherwise, add the incoming byte to the array:
|
||||||
if (firstContact == false) {
|
if (firstContact == false) {
|
||||||
if (inByte == 'A') {
|
if (inByte == 'A') {
|
||||||
myPort.clear(); // clear the serial port buffer
|
myPort.clear(); // clear the serial port buffer
|
||||||
firstContact = true; // you've had first contact from the microcontroller
|
firstContact = true; // you've had first contact from the microcontroller
|
||||||
myPort.write('A'); // ask for more
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
/*
|
/*
|
||||||
Serial Call and Response in ASCII
|
Serial Call and Response in ASCII
|
||||||
Language: Wiring/Arduino
|
Language: Wiring/Arduino
|
||||||
|
|
||||||
This program sends an ASCII A (byte of value 65) on startup
|
This program sends an ASCII A (byte of value 65) on startup
|
||||||
and repeats that until it gets some data in.
|
and repeats that until it gets some data in.
|
||||||
Then it waits for a byte in the serial port, and
|
Then it waits for a byte in the serial port, and
|
||||||
sends three ASCII-encoded, comma-separated sensor values,
|
sends three ASCII-encoded, comma-separated sensor values,
|
||||||
truncated by a linefeed and carriage return,
|
truncated by a linefeed and carriage return,
|
||||||
whenever it gets a byte in.
|
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:
|
The circuit:
|
||||||
- potentiometers attached to analog inputs 0 and 1
|
- potentiometers attached to analog inputs 0 and 1
|
||||||
- pushbutton attached to digital I/O 2
|
- pushbutton attached to digital I/O 2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Created 26 Sept. 2005
|
Created 26 Sept. 2005
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
modified 24 Apr 2012
|
modified 24 Apr 2012
|
||||||
by Tom Igoe and Scott Fitzgerald
|
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
|
import processing.serial.*; // import the Processing serial library
|
||||||
Serial myPort; // The serial port
|
Serial myPort; // The serial port
|
||||||
|
|
||||||
float bgcolor; // Background color
|
float bgcolor; // Background color
|
||||||
float fgcolor; // Fill color
|
float fgcolor; // Fill color
|
||||||
float xpos, ypos; // Starting position of the ball
|
float xpos, ypos; // Starting position of the ball
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
size(640,480);
|
size(640,480);
|
||||||
|
|
||||||
// List all the available serial ports
|
// List all the available serial ports
|
||||||
// if using Processing 2.1 or later, use Serial.printArray()
|
// if using Processing 2.1 or later, use Serial.printArray()
|
||||||
println(Serial.list());
|
println(Serial.list());
|
||||||
|
|
||||||
// I know that the first port in the serial list on my Mac
|
// I know that the first port in the serial list on my Mac
|
||||||
// is always my Arduino board, so I open Serial.list()[0].
|
// is always my Arduino board, so I open Serial.list()[0].
|
||||||
// Change the 0 to the appropriate number of the serial port
|
// Change the 0 to the appropriate number of the serial port
|
||||||
// that your microcontroller is attached to.
|
// that your microcontroller is attached to.
|
||||||
myPort = new Serial(this, Serial.list()[0], 9600);
|
myPort = new Serial(this, Serial.list()[0], 9600);
|
||||||
|
|
||||||
// read bytes into a buffer until you get a linefeed (ASCII 10):
|
// read bytes into a buffer until you get a linefeed (ASCII 10):
|
||||||
myPort.bufferUntil('\n');
|
myPort.bufferUntil('\n');
|
||||||
|
|
||||||
// draw with smooth edges:
|
// draw with smooth edges:
|
||||||
smooth();
|
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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
/*
|
/*
|
||||||
Serial Event example
|
Serial Event example
|
||||||
|
|
||||||
When new serial data arrives, this sketch adds it to a String.
|
When new serial data arrives, this sketch adds it to a String.
|
||||||
When a newline is received, the loop prints the string and
|
When a newline is received, the loop prints the string and
|
||||||
clears it.
|
clears it.
|
||||||
|
|
||||||
A good test for this is to try it with a GPS receiver
|
A good test for this is to try it with a GPS receiver
|
||||||
that sends out NMEA 0183 sentences.
|
that sends out NMEA 0183 sentences.
|
||||||
|
|
||||||
NOTE: The serialEvent() feature is not available on the
|
NOTE: The serialEvent() feature is not available on the
|
||||||
Leonardo, Micro, or other ATmega32U4 based boards.
|
Leonardo, Micro, or other ATmega32U4 based boards.
|
||||||
|
|
||||||
Created 9 May 2011
|
Created 9 May 2011
|
||||||
by Tom Igoe
|
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
|
SerialEvent occurs whenever a new data comes in the
|
||||||
hardware serial RX. This routine is run between each
|
hardware serial RX. This routine is run between each
|
||||||
time loop() runs, so using delay inside loop can delay
|
time loop() runs, so using delay inside loop can delay
|
||||||
response. Multiple bytes of data may be available.
|
response. Multiple bytes of data may be available.
|
||||||
*/
|
*/
|
||||||
void serialEvent() {
|
void serialEvent() {
|
||||||
while (Serial.available()) {
|
while (Serial.available()) {
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
This example reads three analog sensors (potentiometers are easiest)
|
This example reads three analog sensors (potentiometers are easiest)
|
||||||
and sends their values serially. The Processing and Max/MSP programs at the bottom
|
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.
|
take those three values and use them to change the background color of the screen.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
- potentiometers attached to analog inputs 0, 1, and 2
|
- 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
|
created 2 Dec 2006
|
||||||
by David A. Mellis
|
by David A. Mellis
|
||||||
modified 30 Aug 2011
|
modified 30 Aug 2011
|
||||||
by Tom Igoe and Scott Fitzgerald
|
by Tom Igoe and Scott Fitzgerald
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
*/
|
*/
|
||||||
@ -34,57 +34,57 @@ void loop() {
|
|||||||
|
|
||||||
/* Processing code for this example
|
/* 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 redValue = 0; // red value
|
||||||
float greenValue = 0; // green value
|
float greenValue = 0; // green value
|
||||||
float blueValue = 0; // blue value
|
float blueValue = 0; // blue value
|
||||||
|
|
||||||
Serial myPort;
|
Serial myPort;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
size(200, 200);
|
size(200, 200);
|
||||||
|
|
||||||
// List all the available serial ports
|
// List all the available serial ports
|
||||||
// if using Processing 2.1 or later, use Serial.printArray()
|
// if using Processing 2.1 or later, use Serial.printArray()
|
||||||
println(Serial.list());
|
println(Serial.list());
|
||||||
|
|
||||||
// I know that the first port in the serial list on my Mac
|
// I know that the first port in the serial list on my Mac
|
||||||
// is always my Arduino, so I open Serial.list()[0].
|
// is always my Arduino, so I open Serial.list()[0].
|
||||||
// Open whatever port is the one you're using.
|
// Open whatever port is the one you're using.
|
||||||
myPort = new Serial(this, Serial.list()[0], 9600);
|
myPort = new Serial(this, Serial.list()[0], 9600);
|
||||||
// don't generate a serialEvent() unless you get a newline character:
|
// don't generate a serialEvent() unless you get a newline character:
|
||||||
myPort.bufferUntil('\n');
|
myPort.bufferUntil('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw() {
|
void draw() {
|
||||||
// set the background color with the color values:
|
// set the background color with the color values:
|
||||||
background(redValue, greenValue, blueValue);
|
background(redValue, greenValue, blueValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void serialEvent(Serial myPort) {
|
void serialEvent(Serial myPort) {
|
||||||
// get the ASCII string:
|
// get the ASCII string:
|
||||||
String inString = myPort.readStringUntil('\n');
|
String inString = myPort.readStringUntil('\n');
|
||||||
|
|
||||||
if (inString != null) {
|
if (inString != null) {
|
||||||
// trim off any whitespace:
|
// trim off any whitespace:
|
||||||
inString = trim(inString);
|
inString = trim(inString);
|
||||||
// split the string on the commas and convert the
|
// split the string on the commas and convert the
|
||||||
// resulting substrings into an integer array:
|
// resulting substrings into an integer array:
|
||||||
float[] colors = float(split(inString, ","));
|
float[] colors = float(split(inString, ","));
|
||||||
// if the array has at least three elements, you know
|
// if the array has at least three elements, you know
|
||||||
// you got the whole thing. Put the numbers in the
|
// you got the whole thing. Put the numbers in the
|
||||||
// color variables:
|
// color variables:
|
||||||
if (colors.length >=3) {
|
if (colors.length >=3) {
|
||||||
// map them to the range 0-255:
|
// map them to the range 0-255:
|
||||||
redValue = map(colors[0], 0, 1023, 0, 255);
|
redValue = map(colors[0], 0, 1023, 0, 255);
|
||||||
greenValue = map(colors[1], 0, 1023, 0, 255);
|
greenValue = map(colors[1], 0, 1023, 0, 255);
|
||||||
blueValue = map(colors[2], 0, 1023, 0, 255);
|
blueValue = map(colors[2], 0, 1023, 0, 255);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
/*
|
/*
|
||||||
Arrays
|
Arrays
|
||||||
|
|
||||||
Demonstrates the use of an array to hold pin numbers
|
Demonstrates the use of an array to hold pin numbers
|
||||||
in order to iterate over the pins in a sequence.
|
in order to iterate over the pins in a sequence.
|
||||||
Lights multiple LEDs in sequence, then in reverse.
|
Lights multiple LEDs in sequence, then in reverse.
|
||||||
|
|
||||||
Unlike the For Loop tutorial, where the pins have to be
|
Unlike the For Loop tutorial, where the pins have to be
|
||||||
contiguous, here the pins can be in any random order.
|
contiguous, here the pins can be in any random order.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
- LEDs from pins 2 through 7 to ground
|
- LEDs from pins 2 through 7 to ground
|
||||||
|
|
||||||
created 2006
|
created 2006
|
||||||
by David A. Mellis
|
by David A. Mellis
|
||||||
modified 30 Aug 2011
|
modified 30 Aug 2011
|
||||||
by Tom Igoe
|
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.
|
int timer = 100; // The higher the number, the slower the timing.
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
For Loop Iteration
|
For Loop Iteration
|
||||||
|
|
||||||
Demonstrates the use of a for() loop.
|
Demonstrates the use of a for() loop.
|
||||||
Lights multiple LEDs in sequence, then in reverse.
|
Lights multiple LEDs in sequence, then in reverse.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
- LEDs from pins 2 through 7 to ground
|
- LEDs from pins 2 through 7 to ground
|
||||||
|
|
||||||
created 2006
|
created 2006
|
||||||
by David A. Mellis
|
by David A. Mellis
|
||||||
modified 30 Aug 2011
|
modified 30 Aug 2011
|
||||||
by Tom Igoe
|
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.
|
int timer = 100; // The higher the number, the slower the timing.
|
||||||
|
@ -1,27 +1,27 @@
|
|||||||
/*
|
/*
|
||||||
Conditionals - If statement
|
Conditionals - If statement
|
||||||
|
|
||||||
This example demonstrates the use of if() statements.
|
This example demonstrates the use of if() statements.
|
||||||
It reads the state of a potentiometer (an analog input) and turns on an LED
|
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
|
only if the potentiometer goes above a certain threshold level. It prints the analog value
|
||||||
regardless of the level.
|
regardless of the level.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
- potentiometer connected to analog pin 0.
|
- potentiometer connected to analog pin 0.
|
||||||
Center pin of the potentiometer goes to the analog pin.
|
Center pin of the potentiometer goes to the analog pin.
|
||||||
side pins of the potentiometer go to +5V and ground
|
side pins of the potentiometer go to +5V and ground
|
||||||
- LED connected from digital pin 13 to ground
|
- LED connected from digital pin 13 to ground
|
||||||
|
|
||||||
- Note: On most Arduino boards, there is already an LED on the board
|
- 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.
|
connected to pin 13, so you don't need any extra components for this example.
|
||||||
|
|
||||||
created 17 Jan 2009
|
created 17 Jan 2009
|
||||||
modified 9 Apr 2012
|
modified 9 Apr 2012
|
||||||
by Tom Igoe
|
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
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
/*
|
/*
|
||||||
Conditionals - while statement
|
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.
|
While the pushbutton is pressed, the sketch runs the calibration routine.
|
||||||
The sensor readings during the while loop define the minimum and maximum
|
The sensor readings during the while loop define the minimum and maximum
|
||||||
of expected values from the photoresistor.
|
of expected values from the photoresistor.
|
||||||
|
|
||||||
This is a variation on the calibrate example.
|
This is a variation on the calibrate example.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
- photoresistor connected from +5V to analog in pin 0
|
- photoresistor connected from +5V to analog in pin 0
|
||||||
- 10K resistor connected from ground 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
|
- LED connected from digital pin 9 to ground through 220 ohm resistor
|
||||||
- pushbutton attached from pin 2 to +5V
|
- pushbutton attached from pin 2 to +5V
|
||||||
- 10K resistor attached from pin 2 to ground
|
- 10K resistor attached from pin 2 to ground
|
||||||
|
|
||||||
created 17 Jan 2009
|
created 17 Jan 2009
|
||||||
modified 30 Aug 2011
|
modified 30 Aug 2011
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
modified 20 Jan 2017
|
modified 20 Jan 2017
|
||||||
by Arturo Guadalupi
|
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
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,25 +1,25 @@
|
|||||||
/*
|
/*
|
||||||
Switch statement
|
Switch statement
|
||||||
|
|
||||||
Demonstrates the use of a switch statement. The switch
|
Demonstrates the use of a switch statement. The switch
|
||||||
statement allows you to choose from among a set of discrete values
|
statement allows you to choose from among a set of discrete values
|
||||||
of a variable. It's like a series of if statements.
|
of a variable. It's like a series of if statements.
|
||||||
|
|
||||||
To see this sketch in action, put the board and sensor in a well-lit
|
To see this sketch in action, put the board and sensor in a well-lit
|
||||||
room, open the Serial Monitor, and move your hand gradually down
|
room, open the Serial Monitor, and move your hand gradually down
|
||||||
over the sensor.
|
over the sensor.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
- photoresistor from analog in 0 to +5V
|
- photoresistor from analog in 0 to +5V
|
||||||
- 10K resistor from analog in 0 to ground
|
- 10K resistor from analog in 0 to ground
|
||||||
|
|
||||||
created 1 Jul 2009
|
created 1 Jul 2009
|
||||||
modified 9 Apr 2012
|
modified 9 Apr 2012
|
||||||
by Tom Igoe
|
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
|
// these constants won't change. They are the
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
Switch statement with serial input
|
Switch statement with serial input
|
||||||
|
|
||||||
Demonstrates the use of a switch statement. The switch
|
Demonstrates the use of a switch statement. The switch
|
||||||
statement allows you to choose from among a set of discrete values
|
statement allows you to choose from among a set of discrete values
|
||||||
of a variable. It's like a series of if statements.
|
of a variable. It's like a series of if statements.
|
||||||
|
|
||||||
To see this sketch in action, open the Serial monitor and send any character.
|
To see this sketch in action, open the Serial monitor and send any character.
|
||||||
The characters a, b, c, d, and e, will turn on LEDs. Any other character will turn
|
The characters a, b, c, d, and e, will turn on LEDs. Any other character will turn
|
||||||
the LEDs off.
|
the LEDs off.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
- 5 LEDs attached to digital pins 2 through 6 through 220-ohm resistors
|
- 5 LEDs attached to digital pins 2 through 6 through 220-ohm resistors
|
||||||
|
|
||||||
created 1 Jul 2009
|
created 1 Jul 2009
|
||||||
by Tom Igoe
|
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() {
|
void setup() {
|
||||||
|
@ -1,28 +1,28 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
ADXL3xx
|
ADXL3xx
|
||||||
|
|
||||||
Reads an Analog Devices ADXL3xx accelerometer and communicates the
|
Reads an Analog Devices ADXL3xx accelerometer and communicates the
|
||||||
acceleration to the computer. The pins used are designed to be easily
|
acceleration to the computer. The pins used are designed to be easily
|
||||||
compatible with the breakout boards from SparkFun, available from:
|
compatible with the breakout boards from SparkFun, available from:
|
||||||
http://www.sparkfun.com/commerce/categories.php?c=80
|
http://www.sparkfun.com/commerce/categories.php?c=80
|
||||||
|
|
||||||
http://www.arduino.cc/en/Tutorial/ADXL3xx
|
http://www.arduino.cc/en/Tutorial/ADXL3xx
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
analog 0: accelerometer self test
|
analog 0: accelerometer self test
|
||||||
analog 1: z-axis
|
analog 1: z-axis
|
||||||
analog 2: y-axis
|
analog 2: y-axis
|
||||||
analog 3: x-axis
|
analog 3: x-axis
|
||||||
analog 4: ground
|
analog 4: ground
|
||||||
analog 5: vcc
|
analog 5: vcc
|
||||||
|
|
||||||
created 2 Jul 2008
|
created 2 Jul 2008
|
||||||
by David A. Mellis
|
by David A. Mellis
|
||||||
modified 30 Aug 2011
|
modified 30 Aug 2011
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
/* Knock Sensor
|
/* Knock Sensor
|
||||||
|
|
||||||
This sketch reads a piezo element to detect a knocking sound.
|
This sketch reads a piezo element to detect a knocking sound.
|
||||||
It reads an analog pin and compares the result to a set threshold.
|
It reads an analog pin and compares the result to a set threshold.
|
||||||
If the result is greater than the threshold, it writes
|
If the result is greater than the threshold, it writes
|
||||||
"knock" to the serial port, and toggles the LED on pin 13.
|
"knock" to the serial port, and toggles the LED on pin 13.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
- + connection of the piezo attached to analog in 0
|
- + connection of the piezo attached to analog in 0
|
||||||
- - connection of the piezo attached to ground
|
- - connection of the piezo attached to ground
|
||||||
- 1-megohm resistor attached from analog in 0 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
|
created 25 Mar 2007
|
||||||
by David Cuartielles <http://www.0j0.org>
|
by David Cuartielles <http://www.0j0.org>
|
||||||
modified 30 Aug 2011
|
modified 30 Aug 2011
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,25 +1,25 @@
|
|||||||
/*
|
/*
|
||||||
Memsic2125
|
Memsic2125
|
||||||
|
|
||||||
Read the Memsic 2125 two-axis accelerometer. Converts the
|
Read the Memsic 2125 two-axis accelerometer. Converts the
|
||||||
pulses output by the 2125 into milli-g's (1/1000 of Earth's
|
pulses output by the 2125 into milli-g's (1/1000 of Earth's
|
||||||
gravity) and prints them over the serial connection to the
|
gravity) and prints them over the serial connection to the
|
||||||
computer.
|
computer.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
- X output of accelerometer to digital pin 2
|
- X output of accelerometer to digital pin 2
|
||||||
- Y output of accelerometer to digital pin 3
|
- Y output of accelerometer to digital pin 3
|
||||||
- +V of accelerometer to +5V
|
- +V of accelerometer to +5V
|
||||||
- GND of accelerometer to ground
|
- GND of accelerometer to ground
|
||||||
|
|
||||||
http://www.arduino.cc/en/Tutorial/Memsic2125
|
http://www.arduino.cc/en/Tutorial/Memsic2125
|
||||||
|
|
||||||
created 6 Nov 2008
|
created 6 Nov 2008
|
||||||
by David A. Mellis
|
by David A. Mellis
|
||||||
modified 30 Aug 2011
|
modified 30 Aug 2011
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
/* Ping))) Sensor
|
/* Ping))) Sensor
|
||||||
|
|
||||||
This sketch reads a PING))) ultrasonic rangefinder and returns the
|
This sketch reads a PING))) ultrasonic rangefinder and returns the
|
||||||
distance to the closest object in range. To do this, it sends a pulse
|
distance to the closest object in range. To do this, it sends a pulse
|
||||||
to the sensor to initiate a reading, then listens for a pulse
|
to the sensor to initiate a reading, then listens for a pulse
|
||||||
to return. The length of the returning pulse is proportional to
|
to return. The length of the returning pulse is proportional to
|
||||||
the distance of the object from the sensor.
|
the distance of the object from the sensor.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
- +V connection of the PING))) attached to +5V
|
- +V connection of the PING))) attached to +5V
|
||||||
- GND connection of the PING))) attached to ground
|
- GND connection of the PING))) attached to ground
|
||||||
- SIG connection of the PING))) attached to digital pin 7
|
- 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
|
created 3 Nov 2008
|
||||||
by David A. Mellis
|
by David A. Mellis
|
||||||
modified 30 Aug 2011
|
modified 30 Aug 2011
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,36 +1,36 @@
|
|||||||
/*
|
/*
|
||||||
Row-Column Scanning an 8x8 LED matrix with X-Y input
|
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
|
created 27 May 2009
|
||||||
modified 30 Aug 2011
|
modified 30 Aug 2011
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
|
|
||||||
This example works for the Lumex LDM-24488NI Matrix. See
|
This example works for the Lumex LDM-24488NI Matrix. See
|
||||||
http://sigma.octopart.com/140413/datasheet/Lumex-LDM-24488NI.pdf
|
http://sigma.octopart.com/140413/datasheet/Lumex-LDM-24488NI.pdf
|
||||||
for the pin connections
|
for the pin connections
|
||||||
|
|
||||||
For other LED cathode column matrixes, you should only need to change
|
For other LED cathode column matrixes, you should only need to change
|
||||||
the pin numbers in the row[] and column[] arrays
|
the pin numbers in the row[] and column[] arrays
|
||||||
|
|
||||||
rows are the anodes
|
rows are the anodes
|
||||||
cols are the cathodes
|
cols are the cathodes
|
||||||
---------
|
---------
|
||||||
|
|
||||||
Pin numbers:
|
Pin numbers:
|
||||||
Matrix:
|
Matrix:
|
||||||
- Digital pins 2 through 13,
|
- Digital pins 2 through 13,
|
||||||
- analog pins 2 through 5 used as digital 16 through 19
|
- analog pins 2 through 5 used as digital 16 through 19
|
||||||
Potentiometers:
|
Potentiometers:
|
||||||
- center pins are attached to analog pins 0 and 1, respectively
|
- center pins are attached to analog pins 0 and 1, respectively
|
||||||
- side pins attached to +5V and ground, 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,12 +12,12 @@
|
|||||||
The circuit:
|
The circuit:
|
||||||
- LEDs from pins 2 through 11 to ground
|
- LEDs from pins 2 through 11 to ground
|
||||||
|
|
||||||
created 4 Sep 2010
|
created 4 Sep 2010
|
||||||
by Tom Igoe
|
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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
Character analysis operators
|
Character analysis operators
|
||||||
|
|
||||||
Examples using the character analysis operators.
|
Examples using the character analysis operators.
|
||||||
Send any byte and the sketch will tell you about it.
|
Send any byte and the sketch will tell you about it.
|
||||||
|
|
||||||
created 29 Nov 2010
|
created 29 Nov 2010
|
||||||
modified 2 Apr 2012
|
modified 2 Apr 2012
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
Adding Strings together
|
Adding Strings together
|
||||||
|
|
||||||
Examples of how to add Strings together
|
Examples of how to add Strings together
|
||||||
You can also add several different data types to String, as shown here:
|
You can also add several different data types to String, as shown here:
|
||||||
|
|
||||||
created 27 July 2010
|
created 27 July 2010
|
||||||
modified 2 Apr 2012
|
modified 2 Apr 2012
|
||||||
by Tom Igoe
|
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:
|
// declare three Strings:
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
Appending to Strings using the += operator and concat()
|
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
|
created 27 July 2010
|
||||||
modified 2 Apr 2012
|
modified 2 Apr 2012
|
||||||
by Tom Igoe
|
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;
|
String stringOne, stringTwo;
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
String Case changes
|
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
|
created 27 July 2010
|
||||||
modified 2 Apr 2012
|
modified 2 Apr 2012
|
||||||
by Tom Igoe
|
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() {
|
void setup() {
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
String charAt() and setCharAt()
|
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
|
created 27 July 2010
|
||||||
modified 2 Apr 2012
|
modified 2 Apr 2012
|
||||||
by Tom Igoe
|
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() {
|
void setup() {
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
Comparing Strings
|
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
|
created 27 July 2010
|
||||||
modified 2 Apr 2012
|
modified 2 Apr 2012
|
||||||
by Tom Igoe
|
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;
|
String stringOne, stringTwo;
|
||||||
|
@ -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
|
created 27 July 2010
|
||||||
modified 30 Aug 2011
|
modified 30 Aug 2011
|
||||||
by Tom Igoe
|
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() {
|
void setup() {
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
String indexOf() and lastIndexOf() functions
|
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
|
created 27 July 2010
|
||||||
modified 2 Apr 2012
|
modified 2 Apr 2012
|
||||||
by Tom Igoe
|
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() {
|
void setup() {
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
String length()
|
String length()
|
||||||
|
|
||||||
Examples of how to use length() in a String.
|
Examples of how to use length() in a String.
|
||||||
Open the Serial Monitor and start sending characters to see the results.
|
Open the Serial Monitor and start sending characters to see the results.
|
||||||
|
|
||||||
created 1 Aug 2010
|
created 1 Aug 2010
|
||||||
by Tom Igoe
|
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
|
String txtMsg = ""; // a string for incoming text
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
String length() and trim()
|
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
|
created 27 July 2010
|
||||||
modified 2 Apr 2012
|
modified 2 Apr 2012
|
||||||
by Tom Igoe
|
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() {
|
void setup() {
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
String replace()
|
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
|
created 27 July 2010
|
||||||
modified 2 Apr 2012
|
modified 2 Apr 2012
|
||||||
by Tom Igoe
|
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() {
|
void setup() {
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
String startWith() and endsWith()
|
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
|
created 27 July 2010
|
||||||
modified 2 Apr 2012
|
modified 2 Apr 2012
|
||||||
by Tom Igoe
|
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() {
|
void setup() {
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
String substring()
|
String substring()
|
||||||
|
|
||||||
Examples of how to use substring in a String
|
Examples of how to use substring in a String
|
||||||
|
|
||||||
created 27 July 2010,
|
created 27 July 2010,
|
||||||
modified 2 Apr 2012
|
modified 2 Apr 2012
|
||||||
by Zach Eveland
|
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() {
|
void setup() {
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
String to Integer conversion
|
String to Integer conversion
|
||||||
|
|
||||||
Reads a serial input string until it sees a newline, then converts
|
Reads a serial input string until it sees a newline, then converts
|
||||||
the string to a number if the characters are digits.
|
the string to a number if the characters are digits.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
No external components needed.
|
No external components needed.
|
||||||
|
|
||||||
created 29 Nov 2010
|
created 29 Nov 2010
|
||||||
by Tom Igoe
|
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
|
String inString = ""; // string to hold input
|
||||||
|
@ -1,28 +1,28 @@
|
|||||||
/*
|
/*
|
||||||
Keyboard logout
|
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.
|
When you connect pin 2 to ground, it performs a logout.
|
||||||
It uses keyboard combinations to do this, as follows:
|
It uses keyboard combinations to do this, as follows:
|
||||||
|
|
||||||
On Windows, CTRL-ALT-DEL followed by ALT-l
|
On Windows, CTRL-ALT-DEL followed by ALT-l
|
||||||
On Ubuntu, CTRL-ALT-DEL, and ENTER
|
On Ubuntu, CTRL-ALT-DEL, and ENTER
|
||||||
On OSX, CMD-SHIFT-q
|
On OSX, CMD-SHIFT-q
|
||||||
|
|
||||||
To wake: Spacebar.
|
To wake: Spacebar.
|
||||||
|
|
||||||
Circuit:
|
Circuit:
|
||||||
- Arduino Leonardo or Micro
|
- Arduino Leonardo or Micro
|
||||||
- wire to connect D2 to ground.
|
- wire to connect D2 to ground.
|
||||||
|
|
||||||
created 6 Mar 2012
|
created 6 Mar 2012
|
||||||
modified 27 Mar 2012
|
modified 27 Mar 2012
|
||||||
by Tom Igoe
|
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
|
#define OSX 0
|
||||||
|
@ -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:
|
The circuit:
|
||||||
- pushbutton attached from pin 4 to +5V
|
- pushbutton attached from pin 4 to +5V
|
||||||
- 10-kilohm resistor attached from pin 4 to ground
|
- 10-kilohm resistor attached from pin 4 to ground
|
||||||
|
|
||||||
created 24 Oct 2011
|
created 24 Oct 2011
|
||||||
modified 27 Mar 2012
|
modified 27 Mar 2012
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
modified 11 Nov 2013
|
modified 11 Nov 2013
|
||||||
by Scott Fitzgerald
|
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"
|
#include "Keyboard.h"
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Programs Blink
|
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
|
When you connect pin 2 to ground, it creates a new
|
||||||
window with a key combination (CTRL-N),
|
window with a key combination (CTRL-N),
|
||||||
then types in the Blink sketch, then auto-formats the text
|
then types in the Blink sketch, then auto-formats the text
|
||||||
using another key combination (CTRL-T), then
|
using another key combination (CTRL-T), then
|
||||||
uploads the sketch to the currently selected Arduino using
|
uploads the sketch to the currently selected Arduino using
|
||||||
a final key combination (CTRL-U).
|
a final key combination (CTRL-U).
|
||||||
|
|
||||||
Circuit:
|
Circuit:
|
||||||
- Arduino Leonardo, Micro, Due, LilyPad USB, or Yún
|
- Arduino Leonardo, Micro, Due, LilyPad USB, or Yún
|
||||||
- wire to connect D2 to ground.
|
- wire to connect D2 to ground.
|
||||||
|
|
||||||
created 5 Mar 2012
|
created 5 Mar 2012
|
||||||
modified 29 Mar 2012
|
modified 29 Mar 2012
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
modified 3 May 2014
|
modified 3 May 2014
|
||||||
by Scott Fitzgerald
|
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"
|
#include "Keyboard.h"
|
||||||
|
@ -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.
|
Reads a byte from the serial port, sends a keystroke back.
|
||||||
The sent keystroke is one higher than what's received, e.g.
|
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.
|
if you send a, you get b, send A you get B, and so forth.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
- none
|
- none
|
||||||
|
|
||||||
created 21 Oct 2011
|
created 21 Oct 2011
|
||||||
modified 27 Mar 2012
|
modified 27 Mar 2012
|
||||||
by Tom Igoe
|
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"
|
#include "Keyboard.h"
|
||||||
|
@ -2,22 +2,22 @@
|
|||||||
/*
|
/*
|
||||||
KeyboardAndMouseControl
|
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:
|
Hardware:
|
||||||
- 5 pushbuttons attached to D2, D3, D4, D5, D6
|
- 5 pushbuttons attached to D2, D3, D4, D5, D6
|
||||||
|
|
||||||
The mouse movement is always relative. This sketch reads
|
The mouse movement is always relative. This sketch reads
|
||||||
four pushbuttons, and uses them to set the movement of the mouse.
|
four pushbuttons, and uses them to set the movement of the mouse.
|
||||||
|
|
||||||
WARNING: When you use the Mouse.move() command, the Arduino takes
|
WARNING: When you use the Mouse.move() command, the Arduino takes
|
||||||
over your mouse! Make sure you have control before you use the mouse commands.
|
over your mouse! Make sure you have control before you use the mouse commands.
|
||||||
|
|
||||||
created 15 Mar 2012
|
created 15 Mar 2012
|
||||||
modified 27 Mar 2012
|
modified 27 Mar 2012
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
|
|
||||||
this code is in the public domain
|
this code is in the public domain
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -2,25 +2,25 @@
|
|||||||
/*
|
/*
|
||||||
ButtonMouseControl
|
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:
|
Hardware:
|
||||||
- 5 pushbuttons attached to D2, D3, D4, D5, D6
|
- 5 pushbuttons attached to D2, D3, D4, D5, D6
|
||||||
|
|
||||||
|
|
||||||
The mouse movement is always relative. This sketch reads
|
The mouse movement is always relative. This sketch reads
|
||||||
four pushbuttons, and uses them to set the movement of the mouse.
|
four pushbuttons, and uses them to set the movement of the mouse.
|
||||||
|
|
||||||
WARNING: When you use the Mouse.move() command, the Arduino takes
|
WARNING: When you use the Mouse.move() command, the Arduino takes
|
||||||
over your mouse! Make sure you have control before you use the mouse commands.
|
over your mouse! Make sure you have control before you use the mouse commands.
|
||||||
|
|
||||||
created 15 Mar 2012
|
created 15 Mar 2012
|
||||||
modified 27 Mar 2012
|
modified 27 Mar 2012
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
|
|
||||||
this code is in the public domain
|
this code is in the public domain
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
/*
|
/*
|
||||||
JoystickMouseControl
|
JoystickMouseControl
|
||||||
|
|
||||||
Controls the mouse from a joystick on an Arduino Leonardo, Micro or Due.
|
Controls the mouse from a joystick on an Arduino Leonardo, Micro or Due.
|
||||||
Uses a pushbutton to turn on and off mouse control, and
|
Uses a pushbutton to turn on and off mouse control, and
|
||||||
a second pushbutton to click the left mouse button
|
a second pushbutton to click the left mouse button
|
||||||
|
|
||||||
Hardware:
|
Hardware:
|
||||||
- 2-axis joystick connected to pins A0 and A1
|
- 2-axis joystick connected to pins A0 and A1
|
||||||
- pushbuttons connected to pin D2 and D3
|
- pushbuttons connected to pin D2 and D3
|
||||||
|
|
||||||
The mouse movement is always relative. This sketch reads
|
The mouse movement is always relative. This sketch reads
|
||||||
two analog inputs that range from 0 to 1023 (or less on either end)
|
two analog inputs that range from 0 to 1023 (or less on either end)
|
||||||
and translates them into ranges of -6 to 6.
|
and translates them into ranges of -6 to 6.
|
||||||
The sketch assumes that the joystick resting values are around the
|
The sketch assumes that the joystick resting values are around the
|
||||||
middle of the range, but that they vary within a threshold.
|
middle of the range, but that they vary within a threshold.
|
||||||
|
|
||||||
WARNING: When you use the Mouse.move() command, the Arduino takes
|
WARNING: When you use the Mouse.move() command, the Arduino takes
|
||||||
over your mouse! Make sure you have control before you use the command.
|
over your mouse! Make sure you have control before you use the command.
|
||||||
This sketch includes a pushbutton to toggle the mouse control state, so
|
This sketch includes a pushbutton to toggle the mouse control state, so
|
||||||
you can turn on and off mouse control.
|
you can turn on and off mouse control.
|
||||||
|
|
||||||
created 15 Sept 2011
|
created 15 Sept 2011
|
||||||
updated 28 Mar 2012
|
updated 28 Mar 2012
|
||||||
by Tom Igoe
|
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
|
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) {
|
int readAxis(int thisAxis) {
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 2 - Spaceship Interface
|
Project 2 - Spaceship Interface
|
||||||
|
|
||||||
This sketch is written to accompany Project 2 in the
|
This sketch is written to accompany Project 2 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
|
|
||||||
Parts required:
|
Parts required:
|
||||||
1 green LED
|
1 green LED
|
||||||
2 red LEDs
|
2 red LEDs
|
||||||
pushbutton
|
pushbutton
|
||||||
10 kilohm resistor
|
10 kilohm resistor
|
||||||
3 220 ohm resistors
|
3 220 ohm resistors
|
||||||
|
|
||||||
Created 13 September 2012
|
Created 13 September 2012
|
||||||
by Scott Fitzgerald
|
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
|
// Create a global variable to hold the
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 3 - Love-O-Meter
|
Project 3 - Love-O-Meter
|
||||||
|
|
||||||
This sketch is written to accompany Project 3 in the
|
This sketch is written to accompany Project 3 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
|
|
||||||
Parts required:
|
Parts required:
|
||||||
1 TMP36 temperature sensor
|
1 TMP36 temperature sensor
|
||||||
3 red LEDs
|
3 red LEDs
|
||||||
3 220 ohm resistors
|
3 220 ohm resistors
|
||||||
|
|
||||||
Created 13 September 2012
|
Created 13 September 2012
|
||||||
by Scott Fitzgerald
|
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
|
// named constant for the pin the sensor is connected to
|
||||||
|
@ -1,25 +1,25 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 4 - Color Mixing Lamp
|
Project 4 - Color Mixing Lamp
|
||||||
|
|
||||||
This sketch is written to accompany Project 3 in the
|
This sketch is written to accompany Project 3 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
|
|
||||||
Parts required:
|
Parts required:
|
||||||
1 RGB LED
|
1 RGB LED
|
||||||
three 10 kilohm resistors
|
three 10 kilohm resistors
|
||||||
3 220 ohm resistors
|
3 220 ohm resistors
|
||||||
3 photoresistors
|
3 photoresistors
|
||||||
red green and blue colored gels
|
red green and blue colored gels
|
||||||
|
|
||||||
Created 13 September 2012
|
Created 13 September 2012
|
||||||
Modified 14 November 2012
|
Modified 14 November 2012
|
||||||
by Scott Fitzgerald
|
by Scott Fitzgerald
|
||||||
Thanks to Federico Vanzati for improvements
|
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
|
const int greenLEDPin = 9; // LED connected to digital pin 9
|
||||||
@ -71,10 +71,10 @@ void loop() {
|
|||||||
Serial.println(blueSensorValue);
|
Serial.println(blueSensorValue);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
In order to use the values from the sensor for the LED,
|
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,
|
you need to do some math. The ADC provides a 10-bit number,
|
||||||
but analogWrite() uses 8 bits. You'll want to divide your
|
but analogWrite() uses 8 bits. You'll want to divide your
|
||||||
sensor readings by 4 to keep them in range of the output.
|
sensor readings by 4 to keep them in range of the output.
|
||||||
*/
|
*/
|
||||||
redValue = redSensorValue / 4;
|
redValue = redSensorValue / 4;
|
||||||
greenValue = greenSensorValue / 4;
|
greenValue = greenSensorValue / 4;
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 5 - Servo Mood Indicator
|
Project 5 - Servo Mood Indicator
|
||||||
|
|
||||||
This sketch is written to accompany Project 5 in the
|
This sketch is written to accompany Project 5 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
|
|
||||||
Parts required:
|
Parts required:
|
||||||
servo motor
|
servo motor
|
||||||
10 kilohm potentiometer
|
10 kilohm potentiometer
|
||||||
2 100 uF electrolytic capacitors
|
2 100 uF electrolytic capacitors
|
||||||
|
|
||||||
Created 13 September 2012
|
Created 13 September 2012
|
||||||
by Scott Fitzgerald
|
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
|
// include the Servo library
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 6 - Light Theremin
|
Project 6 - Light Theremin
|
||||||
|
|
||||||
This sketch is written to accompany Project 6 in the
|
This sketch is written to accompany Project 6 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
|
|
||||||
Parts required:
|
Parts required:
|
||||||
photoresistor
|
photoresistor
|
||||||
10 kilohm resistor
|
10 kilohm resistor
|
||||||
piezo
|
piezo
|
||||||
|
|
||||||
Created 13 September 2012
|
Created 13 September 2012
|
||||||
by Scott Fitzgerald
|
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
|
// variable to hold sensor value
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 7 - Keyboard
|
Project 7 - Keyboard
|
||||||
|
|
||||||
This sketch is written to accompany Project 7 in the
|
This sketch is written to accompany Project 7 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
|
|
||||||
Parts required:
|
Parts required:
|
||||||
two 10 kilohm resistors
|
two 10 kilohm resistors
|
||||||
1 Megohm resistor
|
1 Megohm resistor
|
||||||
220 ohm resistor
|
220 ohm resistor
|
||||||
4 pushbuttons
|
4 pushbuttons
|
||||||
piezo
|
piezo
|
||||||
|
|
||||||
Created 13 September 2012
|
Created 13 September 2012
|
||||||
by Scott Fitzgerald
|
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
|
// create an array of notes
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 8 - Digital Hourglass
|
Project 8 - Digital Hourglass
|
||||||
|
|
||||||
This sketch is written to accompany Project 8 in the
|
This sketch is written to accompany Project 8 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
|
|
||||||
Parts required:
|
Parts required:
|
||||||
10 kilohm resistor
|
10 kilohm resistor
|
||||||
six 220 ohm resistors
|
six 220 ohm resistors
|
||||||
six LEDs
|
six LEDs
|
||||||
tilt switch
|
tilt switch
|
||||||
|
|
||||||
Created 13 September 2012
|
Created 13 September 2012
|
||||||
by Scott Fitzgerald
|
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
|
// named constant for the switch pin
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 9 - Motorized Pinwheel
|
Project 9 - Motorized Pinwheel
|
||||||
|
|
||||||
This sketch is written to accompany Project 9 in the
|
This sketch is written to accompany Project 9 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
|
|
||||||
Parts required:
|
Parts required:
|
||||||
10 kilohm resistor
|
10 kilohm resistor
|
||||||
pushbutton
|
pushbutton
|
||||||
motor
|
motor
|
||||||
9V battery
|
9V battery
|
||||||
IRF520 MOSFET
|
IRF520 MOSFET
|
||||||
1N4007 diode
|
1N4007 diode
|
||||||
|
|
||||||
Created 13 September 2012
|
Created 13 September 2012
|
||||||
by Scott Fitzgerald
|
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
|
// named constants for the switch and motor pins
|
||||||
|
@ -1,25 +1,25 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 10 - Zoetrope
|
Project 10 - Zoetrope
|
||||||
|
|
||||||
This sketch is written to accompany Project 10 in the
|
This sketch is written to accompany Project 10 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
|
|
||||||
Parts required:
|
Parts required:
|
||||||
two 10 kilohm resistors
|
two 10 kilohm resistors
|
||||||
2 momentary pushbuttons
|
2 momentary pushbuttons
|
||||||
one 10 kilohm potentiometer
|
one 10 kilohm potentiometer
|
||||||
motor
|
motor
|
||||||
9V battery
|
9V battery
|
||||||
H-Bridge
|
H-Bridge
|
||||||
|
|
||||||
Created 13 September 2012
|
Created 13 September 2012
|
||||||
by Scott Fitzgerald
|
by Scott Fitzgerald
|
||||||
Thanks to Federico Vanzati for improvements
|
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
|
const int controlPin1 = 2; // connected to pin 7 on the H-bridge
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 11 - Crystal Ball
|
Project 11 - Crystal Ball
|
||||||
|
|
||||||
This sketch is written to accompany Project 11 in the
|
This sketch is written to accompany Project 11 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
|
|
||||||
Parts required:
|
Parts required:
|
||||||
220 ohm resistor
|
220 ohm resistor
|
||||||
10 kilohm resistor
|
10 kilohm resistor
|
||||||
10 kilohm potentiometer
|
10 kilohm potentiometer
|
||||||
16x2 LCD screen
|
16x2 LCD screen
|
||||||
tilt switch
|
tilt switch
|
||||||
|
|
||||||
|
|
||||||
Created 13 September 2012
|
Created 13 September 2012
|
||||||
by Scott Fitzgerald
|
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:
|
// include the library code:
|
||||||
|
@ -1,29 +1,29 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 12 - Knock Lock
|
Project 12 - Knock Lock
|
||||||
|
|
||||||
This sketch is written to accompany Project 12 in the
|
This sketch is written to accompany Project 12 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
|
|
||||||
Parts required:
|
Parts required:
|
||||||
1 Megohm resistor
|
1 Megohm resistor
|
||||||
10 kilohm resistor
|
10 kilohm resistor
|
||||||
three 220 ohm resistors
|
three 220 ohm resistors
|
||||||
piezo
|
piezo
|
||||||
servo motor
|
servo motor
|
||||||
push button
|
push button
|
||||||
one red LED
|
one red LED
|
||||||
one yellow LED
|
one yellow LED
|
||||||
one green LED
|
one green LED
|
||||||
100 uF capacitor
|
100 uF capacitor
|
||||||
|
|
||||||
Created 18 September 2012
|
Created 18 September 2012
|
||||||
by Scott Fitzgerald
|
by Scott Fitzgerald
|
||||||
Thanks to Federico Vanzati for improvements
|
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
|
// import the library
|
||||||
|
@ -1,26 +1,26 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 13 - Touch Sensor Lamp
|
Project 13 - Touch Sensor Lamp
|
||||||
|
|
||||||
This sketch is written to accompany Project 13 in the
|
This sketch is written to accompany Project 13 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
|
|
||||||
Parts required:
|
Parts required:
|
||||||
1 Megohm resistor
|
1 Megohm resistor
|
||||||
metal foil or copper mesh
|
metal foil or copper mesh
|
||||||
220 ohm resistor
|
220 ohm resistor
|
||||||
LED
|
LED
|
||||||
|
|
||||||
Software required :
|
Software required :
|
||||||
CapacitiveSensor library by Paul Badger
|
CapacitiveSensor library by Paul Badger
|
||||||
http://www.arduino.cc/playground/Main/CapacitiveSensor
|
http://www.arduino.cc/playground/Main/CapacitiveSensor
|
||||||
|
|
||||||
Created 18 September 2012
|
Created 18 September 2012
|
||||||
by Scott Fitzgerald
|
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
|
// import the library (must be located in the
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
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
|
This sketch is written to accompany Project 14 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
|
|
||||||
Parts required:
|
Parts required:
|
||||||
10 kilohm potentiometer
|
10 kilohm potentiometer
|
||||||
|
|
||||||
Software required :
|
Software required :
|
||||||
Processing (3.0 or newer) http://processing.org
|
Processing (3.0 or newer) http://processing.org
|
||||||
Active Internet connection
|
Active Internet connection
|
||||||
|
|
||||||
Created 18 September 2012
|
Created 18 September 2012
|
||||||
by Scott Fitzgerald
|
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
|
/* Processing code for this example
|
||||||
// Tweak the Arduino Logo
|
// Tweak the Arduino Logo
|
||||||
// by Scott Fitzgerald
|
// by Scott Fitzgerald
|
||||||
// This example code is in the public domain
|
// This example code is in the public domain
|
||||||
|
|
||||||
// import the serial library
|
// import the serial library
|
||||||
import processing.serial.*;
|
import processing.serial.*;
|
||||||
|
|
||||||
// create an instance of the serial library
|
// create an instance of the serial library
|
||||||
Serial myPort;
|
Serial myPort;
|
||||||
|
|
||||||
// create an instance of PImage
|
// create an instance of PImage
|
||||||
PImage logo;
|
PImage logo;
|
||||||
|
|
||||||
// a variable to hold the background color
|
// a variable to hold the background color
|
||||||
int bgcolor = 0;
|
int bgcolor = 0;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
size(1, 1);
|
size(1, 1);
|
||||||
surface.setResizable(true);
|
surface.setResizable(true);
|
||||||
// set the color mode to Hue/Saturation/Brightness
|
// set the color mode to Hue/Saturation/Brightness
|
||||||
colorMode(HSB, 255);
|
colorMode(HSB, 255);
|
||||||
|
|
||||||
// load the Arduino logo into the PImage instance
|
// load the Arduino logo into the PImage instance
|
||||||
logo = loadImage("http://www.arduino.cc/arduino_logo.png");
|
logo = loadImage("http://www.arduino.cc/arduino_logo.png");
|
||||||
|
|
||||||
// make the window the same size as the image
|
// make the window the same size as the image
|
||||||
surface.setSize(logo.width, logo.height);
|
surface.setSize(logo.width, logo.height);
|
||||||
|
|
||||||
// print a list of available serial ports to the
|
// print a list of available serial ports to the
|
||||||
// Processing status window
|
// Processing status window
|
||||||
println("Available serial ports:");
|
println("Available serial ports:");
|
||||||
println(Serial.list());
|
println(Serial.list());
|
||||||
|
|
||||||
// Tell the serial object the information it needs to communicate
|
// Tell the serial object the information it needs to communicate
|
||||||
// with the Arduino. Change Serial.list()[0] to the correct
|
// with the Arduino. Change Serial.list()[0] to the correct
|
||||||
// port corresponding to your Arduino board. The last
|
// port corresponding to your Arduino board. The last
|
||||||
// parameter (e.g. 9600) is the speed of the communication. It
|
// parameter (e.g. 9600) is the speed of the communication. It
|
||||||
// has to correspond to the value passed to Serial.begin() in your
|
// has to correspond to the value passed to Serial.begin() in your
|
||||||
// Arduino sketch.
|
// Arduino sketch.
|
||||||
myPort = new Serial(this, Serial.list()[0], 9600);
|
myPort = new Serial(this, Serial.list()[0], 9600);
|
||||||
|
|
||||||
// If you know the name of the port used by the Arduino board, you
|
// If you know the name of the port used by the Arduino board, you
|
||||||
// can specify it directly like this.
|
// can specify it directly like this.
|
||||||
// port = new Serial(this, "COM1", 9600);
|
// 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw the background. the variable bgcolor
|
void draw() {
|
||||||
// contains the Hue, determined by the value
|
|
||||||
// from the serial port
|
|
||||||
background(bgcolor, 255, 255);
|
|
||||||
|
|
||||||
// draw the Arduino logo
|
// if there is information in the serial port
|
||||||
image(logo, 0, 0);
|
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);
|
||||||
|
}
|
||||||
*/
|
*/
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 15 - Hacking Buttons
|
Project 15 - Hacking Buttons
|
||||||
|
|
||||||
This sketch is written to accompany Project 15 in the
|
This sketch is written to accompany Project 15 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
|
|
||||||
Parts required:
|
Parts required:
|
||||||
battery powered component
|
battery powered component
|
||||||
220 ohm resistor
|
220 ohm resistor
|
||||||
4N35 optocoupler
|
4N35 optocoupler
|
||||||
|
|
||||||
Created 18 September 2012
|
Created 18 September 2012
|
||||||
by Scott Fitzgerald
|
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
|
const int optoPin = 2; // the pin the optocoupler is connected to
|
||||||
|
Loading…
x
Reference in New Issue
Block a user