Skip to content

Commit d609b4a

Browse files
committed
updated examples and libraries for Arduino 1.0.5
1 parent 10c22bb commit d609b4a

File tree

486 files changed

+44156
-6938
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

486 files changed

+44156
-6938
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
AnalogReadSerial
3+
Reads an analog input on pin 0, prints the result to the serial monitor.
4+
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
5+
6+
This example code is in the public domain.
7+
*/
8+
9+
// the setup routine runs once when you press reset:
10+
void setup() {
11+
// initialize serial communication at 9600 bits per second:
12+
Serial.begin(9600);
13+
}
14+
15+
// the loop routine runs over and over again forever:
16+
void loop() {
17+
// read the input on analog pin 0:
18+
int sensorValue = analogRead(A0);
19+
// print out the value you read:
20+
Serial.println(sensorValue);
21+
delay(1); // delay in between reads for stability
22+
}

examples/01.Basics/Blink/Blink.ino

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
Blink
3+
Turns on an LED on for one second, then off for one second, repeatedly.
4+
5+
This example code is in the public domain.
6+
*/
7+
8+
// Pin 13 has an LED connected on most Arduino boards.
9+
// give it a name:
10+
int led = 13;
11+
12+
// the setup routine runs once when you press reset:
13+
void setup() {
14+
// initialize the digital pin as an output.
15+
pinMode(led, OUTPUT);
16+
}
17+
18+
// the loop routine runs over and over again forever:
19+
void loop() {
20+
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
21+
delay(1000); // wait for a second
22+
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
23+
delay(1000); // wait for a second
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
DigitalReadSerial
3+
Reads a digital input on pin 2, prints the result to the serial monitor
4+
5+
This example code is in the public domain.
6+
*/
7+
8+
// digital pin 2 has a pushbutton attached to it. Give it a name:
9+
int pushButton = 2;
10+
11+
// the setup routine runs once when you press reset:
12+
void setup() {
13+
// initialize serial communication at 9600 bits per second:
14+
Serial.begin(9600);
15+
// make the pushbutton's pin an input:
16+
pinMode(pushButton, INPUT);
17+
}
18+
19+
// the loop routine runs over and over again forever:
20+
void loop() {
21+
// read the input pin:
22+
int buttonState = digitalRead(pushButton);
23+
// print out the state of the button:
24+
Serial.println(buttonState);
25+
delay(1); // delay in between reads for stability
26+
}
27+
28+
29+

examples/1.Basics/Fade/Fade.ino examples/01.Basics/Fade/Fade.ino

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@
55
using the analogWrite() function.
66
77
This example code is in the public domain.
8-
98
*/
9+
10+
int led = 9; // the pin that the LED is attached to
1011
int brightness = 0; // how bright the LED is
1112
int fadeAmount = 5; // how many points to fade the LED by
1213

14+
// the setup routine runs once when you press reset:
1315
void setup() {
1416
// declare pin 9 to be an output:
15-
pinMode(9, OUTPUT);
17+
pinMode(led, OUTPUT);
1618
}
1719

20+
// the loop routine runs over and over again forever:
1821
void loop() {
1922
// set the brightness of pin 9:
20-
analogWrite(9, brightness);
23+
analogWrite(led, brightness);
2124

2225
// change the brightness for next time through the loop:
2326
brightness = brightness + fadeAmount;
@@ -29,3 +32,4 @@ void loop() {
2932
// wait for 30 milliseconds to see the dimming effect
3033
delay(30);
3134
}
35+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
ReadAnalogVoltage
3+
Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
4+
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
5+
6+
This example code is in the public domain.
7+
*/
8+
9+
// the setup routine runs once when you press reset:
10+
void setup() {
11+
// initialize serial communication at 9600 bits per second:
12+
Serial.begin(9600);
13+
}
14+
15+
// the loop routine runs over and over again forever:
16+
void loop() {
17+
// read the input on analog pin 0:
18+
int sensorValue = analogRead(A0);
19+
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
20+
float voltage = sensorValue * (5.0 / 1023.0);
21+
// print out the value you read:
22+
Serial.println(voltage);
23+
}
File renamed without changes.

examples/2.Digital/Debounce/Debounce.ino examples/02.Digital/Debounce/Debounce.ino

+20-6
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@
1919
by David A. Mellis
2020
modified 30 Aug 2011
2121
by Limor Fried
22+
modified 28 Dec 2012
23+
by Mike Walters
2224
23-
This example code is in the public domain.
25+
This example code is in the public domain.
2426
2527
http://www.arduino.cc/en/Tutorial/Debounce
2628
*/
2729

2830
// constants won't change. They're used here to
2931
// set pin numbers:
30-
const int buttonPin = 2; // the number of the pushbutton pin
31-
const int ledPin = 13; // the number of the LED pin
32+
const int buttonPin = 2; // the number of the pushbutton pin
33+
const int ledPin = 13; // the number of the LED pin
3234

3335
// Variables will change:
3436
int ledState = HIGH; // the current state of the output pin
@@ -43,6 +45,9 @@ long debounceDelay = 50; // the debounce time; increase if the output flicker
4345
void setup() {
4446
pinMode(buttonPin, INPUT);
4547
pinMode(ledPin, OUTPUT);
48+
49+
// set initial LED state
50+
digitalWrite(ledPin, ledState);
4651
}
4752

4853
void loop() {
@@ -62,11 +67,20 @@ void loop() {
6267
if ((millis() - lastDebounceTime) > debounceDelay) {
6368
// whatever the reading is at, it's been there for longer
6469
// than the debounce delay, so take it as the actual current state:
65-
buttonState = reading;
70+
71+
// if the button state has changed:
72+
if (reading != buttonState) {
73+
buttonState = reading;
74+
75+
// only toggle the LED if the new button state is HIGH
76+
if (buttonState == HIGH) {
77+
ledState = !ledState;
78+
}
79+
}
6680
}
6781

68-
// set the LED using the state of the button:
69-
digitalWrite(ledPin, buttonState);
82+
// set the LED:
83+
digitalWrite(ledPin, ledState);
7084

7185
// save the reading. Next time through the loop,
7286
// it'll be the lastButtonState:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
Input Pullup Serial
3+
4+
This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a
5+
digital input on pin 2 and prints the results to the serial monitor.
6+
7+
The circuit:
8+
* Momentary switch attached from pin 2 to ground
9+
* Built-in LED on pin 13
10+
11+
Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal
12+
20K-ohm resistor is pulled to 5V. This configuration causes the input to
13+
read HIGH when the switch is open, and LOW when it is closed.
14+
15+
created 14 March 2012
16+
by Scott Fitzgerald
17+
18+
http://www.arduino.cc/en/Tutorial/InputPullupSerial
19+
20+
This example code is in the public domain
21+
22+
*/
23+
24+
void setup(){
25+
//start serial connection
26+
Serial.begin(9600);
27+
//configure pin2 as an input and enable the internal pull-up resistor
28+
pinMode(2, INPUT_PULLUP);
29+
pinMode(13, OUTPUT);
30+
31+
}
32+
33+
void loop(){
34+
//read the pushbutton value into a variable
35+
int sensorVal = digitalRead(2);
36+
//print out the value of the pushbutton
37+
Serial.println(sensorVal);
38+
39+
// Keep in mind the pullup means the pushbutton's
40+
// logic is inverted. It goes HIGH when it's open,
41+
// and LOW when it's pressed. Turn on pin 13 when the
42+
// button's pressed, and off when it's not:
43+
if (sensorVal == HIGH) {
44+
digitalWrite(13, LOW);
45+
}
46+
else {
47+
digitalWrite(13, HIGH);
48+
}
49+
}
50+
51+
52+

examples/2.Digital/toneKeyboard/toneKeyboard.ino examples/02.Digital/toneKeyboard/toneKeyboard.ino

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* 8-ohm speaker on digital pin 8
1010
1111
created 21 Jan 2010
12-
modified 30 Aug 2011
12+
modified 9 Apr 2012
1313
by Tom Igoe
1414
1515
This example code is in the public domain.
@@ -41,5 +41,4 @@ void loop() {
4141
tone(8, notes[thisSensor], 20);
4242
}
4343
}
44-
Serial.println();
4544
}

examples/2.Digital/tonePitchFollower/tonePitchFollower.ino examples/02.Digital/tonePitchFollower/tonePitchFollower.ino

+6-5
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
* 4.7K resistor on analog 0 to ground
1010
1111
created 21 Jan 2010
12-
modified 30 Aug 2011
13-
by Tom Igoe
12+
modified 31 May 2012
13+
by Tom Igoe, with suggestion from Michael Flynn
1414
1515
This example code is in the public domain.
1616
@@ -29,14 +29,15 @@ void loop() {
2929
int sensorReading = analogRead(A0);
3030
// print the sensor reading so you know its range
3131
Serial.println(sensorReading);
32-
// map the pitch to the range of the analog input.
32+
// map the analog input range (in this case, 400 - 1000 from the photoresistor)
33+
// to the output pitch range (120 - 1500Hz)
3334
// change the minimum and maximum input numbers below
3435
// depending on the range your sensor's giving:
35-
int thisPitch = map(sensorReading, 400, 1000, 100, 1000);
36+
int thisPitch = map(sensorReading, 400, 1000, 120, 1500);
3637

3738
// play the pitch:
3839
tone(9, thisPitch, 10);
39-
40+
delay(1); // delay in between reads for stability
4041
}
4142

4243

examples/3.Analog/AnalogInOutSerial/AnalogInOutSerial.ino examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* LED connected from digital pin 9 to ground
1313
1414
created 29 Dec. 2008
15-
modified 30 Aug 2011
15+
modified 9 Apr 2012
1616
by Tom Igoe
1717
1818
This example code is in the public domain.
@@ -46,8 +46,8 @@ void loop() {
4646
Serial.print("\t output = ");
4747
Serial.println(outputValue);
4848

49-
// wait 10 milliseconds before the next loop
49+
// wait 2 milliseconds before the next loop
5050
// for the analog-to-digital converter to settle
5151
// after the last reading:
52-
delay(10);
52+
delay(2);
5353
}
File renamed without changes.

examples/3.Analog/Smoothing/Smoothing.ino examples/03.Analog/Smoothing/Smoothing.ino

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
* Analog sensor (potentiometer will do) attached to analog input 0
1111
1212
Created 22 April 2007
13-
modified 30 Aug 2011
1413
By David A. Mellis <[email protected]>
15-
14+
modified 9 Apr 2012
15+
by Tom Igoe
1616
http://www.arduino.cc/en/Tutorial/Smoothing
1717
1818
This example code is in the public domain.
@@ -61,7 +61,8 @@ void loop() {
6161
// calculate the average:
6262
average = total / numReadings;
6363
// send it to the computer as ASCII digits
64-
Serial.println(average);
64+
Serial.println(average);
65+
delay(1); // delay in between reads for stability
6566
}
6667

6768

examples/4.Communication/ASCIITable/ASCIITable.ino examples/04.Communication/ASCIITable/ASCIITable.ino

+8-6
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,21 @@
1111
1212
created 2006
1313
by Nicholas Zambetti
14-
modified 30 Aug 2011
14+
modified 9 Apr 2012
1515
by Tom Igoe
1616
1717
This example code is in the public domain.
1818
1919
<http://www.zambetti.com>
2020
2121
*/
22-
void setup()
23-
{
22+
void setup() {
23+
//Initialize serial and wait for port to open:
2424
Serial.begin(9600);
25-
25+
while (!Serial) {
26+
; // wait for serial port to connect. Needed for Leonardo only
27+
}
28+
2629
// prints title with ending line break
2730
Serial.println("ASCII Table ~ Character Map");
2831
}
@@ -33,8 +36,7 @@ int thisByte = 33;
3336
// for example. '!' is the same as 33, so you could also use this:
3437
//int thisByte = '!';
3538

36-
void loop()
37-
{
39+
void loop() {
3840
// prints value unaltered, i.e. the raw binary version of the
3941
// byte. The serial monitor interprets all bytes as
4042
// ASCII, so 33, the first number, will show up as '!'

examples/4.Communication/Graph/Graph.ino examples/04.Communication/Graph/Graph.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
1919
created 2006
2020
by David A. Mellis
21-
modified 30 Aug 2011
21+
modified 9 Apr 2012
2222
by Tom Igoe and Scott Fitzgerald
2323
2424
This example code is in the public domain.
@@ -36,7 +36,7 @@ void loop() {
3636
Serial.println(analogRead(A0));
3737
// wait a bit for the analog-to-digital converter
3838
// to stabilize after the last reading:
39-
delay(10);
39+
delay(2);
4040
}
4141

4242
/* Processing code for this example

examples/4.Communication/MIDI/Midi.ino examples/04.Communication/MIDI/Midi.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
Attach a MIDI cable to the jack, then to a MIDI synth, and play music.
1414
1515
created 13 Jun 2006
16-
modified 30 Aug 2011
16+
modified 13 Aug 2012
1717
by Tom Igoe
1818
1919
This example code is in the public domain.
2020
21-
http://www.arduino.cc/en/Tutorial/MIDI
21+
http://www.arduino.cc/en/Tutorial/Midi
2222
2323
*/
2424

0 commit comments

Comments
 (0)