Skip to content

Commit 3577761

Browse files
author
Tom Igoe
committed
Changed all .pde examples to .ino
All examples in /build/shared/examples/ and /libraries/ have had their extensions changed to .ino
1 parent 4553cee commit 3577761

File tree

124 files changed

+2850
-57
lines changed

Some content is hidden

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

124 files changed

+2850
-57
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
AnalogReadSerial
3+
Reads an analog input on pin 0, prints the result to the serial monitor
4+
5+
This example code is in the public domain.
6+
*/
7+
8+
void setup() {
9+
Serial.begin(9600);
10+
}
11+
12+
void loop() {
13+
int sensorValue = analogRead(A0);
14+
Serial.println(sensorValue);
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
void setup() {
9+
Serial.begin(9600);
10+
pinMode(2, INPUT);
11+
}
12+
13+
void loop() {
14+
int sensorValue = digitalRead(2);
15+
Serial.println(sensorValue);
16+
}
17+
18+
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Button
3+
4+
Turns on and off a light emitting diode(LED) connected to digital
5+
pin 13, when pressing a pushbutton attached to pin 2.
6+
7+
8+
The circuit:
9+
* LED attached from pin 13 to ground
10+
* pushbutton attached to pin 2 from +5V
11+
* 10K resistor attached to pin 2 from ground
12+
13+
* Note: on most Arduinos there is already an LED on the board
14+
attached to pin 13.
15+
16+
17+
created 2005
18+
by DojoDave <http://www.0j0.org>
19+
modified 30 Aug 2011
20+
by Tom Igoe
21+
22+
This example code is in the public domain.
23+
24+
http://www.arduino.cc/en/Tutorial/Button
25+
*/
26+
27+
// constants won't change. They're used here to
28+
// set pin numbers:
29+
const int buttonPin = 2; // the number of the pushbutton pin
30+
const int ledPin = 13; // the number of the LED pin
31+
32+
// variables will change:
33+
int buttonState = 0; // variable for reading the pushbutton status
34+
35+
void setup() {
36+
// initialize the LED pin as an output:
37+
pinMode(ledPin, OUTPUT);
38+
// initialize the pushbutton pin as an input:
39+
pinMode(buttonPin, INPUT);
40+
}
41+
42+
void loop(){
43+
// read the state of the pushbutton value:
44+
buttonState = digitalRead(buttonPin);
45+
46+
// check if the pushbutton is pressed.
47+
// if it is, the buttonState is HIGH:
48+
if (buttonState == HIGH) {
49+
// turn LED on:
50+
digitalWrite(ledPin, HIGH);
51+
}
52+
else {
53+
// turn LED off:
54+
digitalWrite(ledPin, LOW);
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
Debounce
3+
4+
Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
5+
press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's
6+
a minimum delay between toggles to debounce the circuit (i.e. to ignore
7+
noise).
8+
9+
The circuit:
10+
* LED attached from pin 13 to ground
11+
* pushbutton attached from pin 2 to +5V
12+
* 10K resistor attached from pin 2 to ground
13+
14+
* Note: On most Arduino boards, there is already an LED on the board
15+
connected to pin 13, so you don't need any extra components for this example.
16+
17+
18+
created 21 November 2006
19+
by David A. Mellis
20+
modified 30 Aug 2011
21+
by Limor Fried
22+
23+
This example code is in the public domain.
24+
25+
http://www.arduino.cc/en/Tutorial/Debounce
26+
*/
27+
28+
// constants won't change. They're used here to
29+
// 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+
33+
// Variables will change:
34+
int ledState = HIGH; // the current state of the output pin
35+
int buttonState; // the current reading from the input pin
36+
int lastButtonState = LOW; // the previous reading from the input pin
37+
38+
// the following variables are long's because the time, measured in miliseconds,
39+
// will quickly become a bigger number than can be stored in an int.
40+
long lastDebounceTime = 0; // the last time the output pin was toggled
41+
long debounceDelay = 50; // the debounce time; increase if the output flickers
42+
43+
void setup() {
44+
pinMode(buttonPin, INPUT);
45+
pinMode(ledPin, OUTPUT);
46+
}
47+
48+
void loop() {
49+
// read the state of the switch into a local variable:
50+
int reading = digitalRead(buttonPin);
51+
52+
// check to see if you just pressed the button
53+
// (i.e. the input went from LOW to HIGH), and you've waited
54+
// long enough since the last press to ignore any noise:
55+
56+
// If the switch changed, due to noise or pressing:
57+
if (reading != lastButtonState) {
58+
// reset the debouncing timer
59+
lastDebounceTime = millis();
60+
}
61+
62+
if ((millis() - lastDebounceTime) > debounceDelay) {
63+
// whatever the reading is at, it's been there for longer
64+
// than the debounce delay, so take it as the actual current state:
65+
buttonState = reading;
66+
}
67+
68+
// set the LED using the state of the button:
69+
digitalWrite(ledPin, buttonState);
70+
71+
// save the reading. Next time through the loop,
72+
// it'll be the lastButtonState:
73+
lastButtonState = reading;
74+
}
75+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
State change detection (edge detection)
3+
4+
Often, you don't need to know the state of a digital input all the time,
5+
but you just need to know when the input changes from one state to another.
6+
For example, you want to know when a button goes from OFF to ON. This is called
7+
state change detection, or edge detection.
8+
9+
This example shows how to detect when a button or button changes from off to on
10+
and on to off.
11+
12+
The circuit:
13+
* pushbutton attached to pin 2 from +5V
14+
* 10K resistor attached to pin 2 from ground
15+
* LED attached from pin 13 to ground (or use the built-in LED on
16+
most Arduino boards)
17+
18+
created 27 Sep 2005
19+
modified 30 Aug 2011
20+
by Tom Igoe
21+
22+
This example code is in the public domain.
23+
24+
http://arduino.cc/en/Tutorial/ButtonStateChange
25+
26+
*/
27+
28+
// this constant won't change:
29+
const int buttonPin = 2; // the pin that the pushbutton is attached to
30+
const int ledPin = 13; // the pin that the LED is attached to
31+
32+
// Variables will change:
33+
int buttonPushCounter = 0; // counter for the number of button presses
34+
int buttonState = 0; // current state of the button
35+
int lastButtonState = 0; // previous state of the button
36+
37+
void setup() {
38+
// initialize the button pin as a input:
39+
pinMode(buttonPin, INPUT);
40+
// initialize the LED as an output:
41+
pinMode(ledPin, OUTPUT);
42+
// initialize serial communication:
43+
Serial.begin(9600);
44+
}
45+
46+
47+
void loop() {
48+
// read the pushbutton input pin:
49+
buttonState = digitalRead(buttonPin);
50+
51+
// compare the buttonState to its previous state
52+
if (buttonState != lastButtonState) {
53+
// if the state has changed, increment the counter
54+
if (buttonState == HIGH) {
55+
// if the current state is HIGH then the button
56+
// wend from off to on:
57+
buttonPushCounter++;
58+
Serial.println("on");
59+
Serial.print("number of button pushes: ");
60+
Serial.println(buttonPushCounter);
61+
}
62+
else {
63+
// if the current state is LOW then the button
64+
// wend from on to off:
65+
Serial.println("off");
66+
}
67+
}
68+
// save the current state as the last state,
69+
//for next time through the loop
70+
lastButtonState = buttonState;
71+
72+
73+
// turns on the LED every four button pushes by
74+
// checking the modulo of the button push counter.
75+
// the modulo function gives you the remainder of
76+
// the division of two numbers:
77+
if (buttonPushCounter % 4 == 0) {
78+
digitalWrite(ledPin, HIGH);
79+
} else {
80+
digitalWrite(ledPin, LOW);
81+
}
82+
83+
}
84+
85+
86+
87+
88+
89+
90+
91+
92+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
keyboard
3+
4+
Plays a pitch that changes based on a changing analog input
5+
6+
circuit:
7+
* 3 force-sensing resistors from +5V to analog in 0 through 5
8+
* 3 10K resistors from analog in 0 through 5 to ground
9+
* 8-ohm speaker on digital pin 8
10+
11+
created 21 Jan 2010
12+
modified 30 Aug 2011
13+
by Tom Igoe
14+
15+
This example code is in the public domain.
16+
17+
http://arduino.cc/en/Tutorial/Tone3
18+
19+
*/
20+
21+
#include "pitches.h"
22+
23+
const int threshold = 10; // minimum reading of the sensors that generates a note
24+
25+
// notes to play, corresponding to the 3 sensors:
26+
int notes[] = {
27+
NOTE_A4, NOTE_B4,NOTE_C3 };
28+
29+
void setup() {
30+
31+
}
32+
33+
void loop() {
34+
for (int thisSensor = 0; thisSensor < 3; thisSensor++) {
35+
// get a sensor reading:
36+
int sensorReading = analogRead(thisSensor);
37+
38+
// if the sensor is pressed hard enough:
39+
if (sensorReading > threshold) {
40+
// play the note corresponding to this sensor:
41+
tone(8, notes[thisSensor], 20);
42+
}
43+
}
44+
Serial.println();
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Melody
3+
4+
Plays a melody
5+
6+
circuit:
7+
* 8-ohm speaker on digital pin 8
8+
9+
created 21 Jan 2010
10+
modified 30 Aug 2011
11+
by Tom Igoe
12+
13+
This example code is in the public domain.
14+
15+
http://arduino.cc/en/Tutorial/Tone
16+
17+
*/
18+
#include "pitches.h"
19+
20+
// notes in the melody:
21+
int melody[] = {
22+
NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};
23+
24+
// note durations: 4 = quarter note, 8 = eighth note, etc.:
25+
int noteDurations[] = {
26+
4, 8, 8, 4,4,4,4,4 };
27+
28+
void setup() {
29+
// iterate over the notes of the melody:
30+
for (int thisNote = 0; thisNote < 8; thisNote++) {
31+
32+
// to calculate the note duration, take one second
33+
// divided by the note type.
34+
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
35+
int noteDuration = 1000/noteDurations[thisNote];
36+
tone(8, melody[thisNote],noteDuration);
37+
38+
// to distinguish the notes, set a minimum time between them.
39+
// the note's duration + 30% seems to work well:
40+
int pauseBetweenNotes = noteDuration * 1.30;
41+
delay(pauseBetweenNotes);
42+
// stop the tone playing:
43+
noTone(8);
44+
}
45+
}
46+
47+
void loop() {
48+
// no need to repeat the melody.
49+
}

0 commit comments

Comments
 (0)