mirror of
https://github.com/esp8266/Arduino.git
synced 2025-08-01 03:47:23 +03:00
Changed all .pde examples to .ino
All examples in /build/shared/examples/ and /libraries/ have had their extensions changed to .ino
This commit is contained in:
56
build/shared/examples/2.Digital/Button/Button.ino
Normal file
56
build/shared/examples/2.Digital/Button/Button.ino
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
Button
|
||||
|
||||
Turns on and off a light emitting diode(LED) connected to digital
|
||||
pin 13, when pressing a pushbutton attached to pin 2.
|
||||
|
||||
|
||||
The circuit:
|
||||
* LED attached from pin 13 to ground
|
||||
* pushbutton attached to pin 2 from +5V
|
||||
* 10K resistor attached to pin 2 from ground
|
||||
|
||||
* Note: on most Arduinos there is already an LED on the board
|
||||
attached to pin 13.
|
||||
|
||||
|
||||
created 2005
|
||||
by DojoDave <http://www.0j0.org>
|
||||
modified 30 Aug 2011
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Button
|
||||
*/
|
||||
|
||||
// constants won't change. They're used here to
|
||||
// set pin numbers:
|
||||
const int buttonPin = 2; // the number of the pushbutton pin
|
||||
const int ledPin = 13; // the number of the LED pin
|
||||
|
||||
// variables will change:
|
||||
int buttonState = 0; // variable for reading the pushbutton status
|
||||
|
||||
void setup() {
|
||||
// initialize the LED pin as an output:
|
||||
pinMode(ledPin, OUTPUT);
|
||||
// initialize the pushbutton pin as an input:
|
||||
pinMode(buttonPin, INPUT);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
// read the state of the pushbutton value:
|
||||
buttonState = digitalRead(buttonPin);
|
||||
|
||||
// check if the pushbutton is pressed.
|
||||
// if it is, the buttonState is HIGH:
|
||||
if (buttonState == HIGH) {
|
||||
// turn LED on:
|
||||
digitalWrite(ledPin, HIGH);
|
||||
}
|
||||
else {
|
||||
// turn LED off:
|
||||
digitalWrite(ledPin, LOW);
|
||||
}
|
||||
}
|
75
build/shared/examples/2.Digital/Debounce/Debounce.ino
Normal file
75
build/shared/examples/2.Digital/Debounce/Debounce.ino
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
Debounce
|
||||
|
||||
Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
|
||||
press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's
|
||||
a minimum delay between toggles to debounce the circuit (i.e. to ignore
|
||||
noise).
|
||||
|
||||
The circuit:
|
||||
* LED attached from pin 13 to ground
|
||||
* pushbutton attached from pin 2 to +5V
|
||||
* 10K resistor attached from pin 2 to ground
|
||||
|
||||
* Note: On most Arduino boards, there is already an LED on the board
|
||||
connected to pin 13, so you don't need any extra components for this example.
|
||||
|
||||
|
||||
created 21 November 2006
|
||||
by David A. Mellis
|
||||
modified 30 Aug 2011
|
||||
by Limor Fried
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Debounce
|
||||
*/
|
||||
|
||||
// constants won't change. They're used here to
|
||||
// set pin numbers:
|
||||
const int buttonPin = 2; // the number of the pushbutton pin
|
||||
const int ledPin = 13; // the number of the LED pin
|
||||
|
||||
// Variables will change:
|
||||
int ledState = HIGH; // the current state of the output pin
|
||||
int buttonState; // the current reading from the input pin
|
||||
int lastButtonState = LOW; // the previous reading from the input pin
|
||||
|
||||
// the following variables are long's because the time, measured in miliseconds,
|
||||
// will quickly become a bigger number than can be stored in an int.
|
||||
long lastDebounceTime = 0; // the last time the output pin was toggled
|
||||
long debounceDelay = 50; // the debounce time; increase if the output flickers
|
||||
|
||||
void setup() {
|
||||
pinMode(buttonPin, INPUT);
|
||||
pinMode(ledPin, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the state of the switch into a local variable:
|
||||
int reading = digitalRead(buttonPin);
|
||||
|
||||
// check to see if you just pressed the button
|
||||
// (i.e. the input went from LOW to HIGH), and you've waited
|
||||
// long enough since the last press to ignore any noise:
|
||||
|
||||
// If the switch changed, due to noise or pressing:
|
||||
if (reading != lastButtonState) {
|
||||
// reset the debouncing timer
|
||||
lastDebounceTime = millis();
|
||||
}
|
||||
|
||||
if ((millis() - lastDebounceTime) > debounceDelay) {
|
||||
// whatever the reading is at, it's been there for longer
|
||||
// than the debounce delay, so take it as the actual current state:
|
||||
buttonState = reading;
|
||||
}
|
||||
|
||||
// set the LED using the state of the button:
|
||||
digitalWrite(ledPin, buttonState);
|
||||
|
||||
// save the reading. Next time through the loop,
|
||||
// it'll be the lastButtonState:
|
||||
lastButtonState = reading;
|
||||
}
|
||||
|
@ -0,0 +1,92 @@
|
||||
/*
|
||||
State change detection (edge detection)
|
||||
|
||||
Often, you don't need to know the state of a digital input all the time,
|
||||
but you just need to know when the input changes from one state to another.
|
||||
For example, you want to know when a button goes from OFF to ON. This is called
|
||||
state change detection, or edge detection.
|
||||
|
||||
This example shows how to detect when a button or button changes from off to on
|
||||
and on to off.
|
||||
|
||||
The circuit:
|
||||
* pushbutton attached to pin 2 from +5V
|
||||
* 10K resistor attached to pin 2 from ground
|
||||
* LED attached from pin 13 to ground (or use the built-in LED on
|
||||
most Arduino boards)
|
||||
|
||||
created 27 Sep 2005
|
||||
modified 30 Aug 2011
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
http://arduino.cc/en/Tutorial/ButtonStateChange
|
||||
|
||||
*/
|
||||
|
||||
// this constant won't change:
|
||||
const int buttonPin = 2; // the pin that the pushbutton is attached to
|
||||
const int ledPin = 13; // the pin that the LED is attached to
|
||||
|
||||
// Variables will change:
|
||||
int buttonPushCounter = 0; // counter for the number of button presses
|
||||
int buttonState = 0; // current state of the button
|
||||
int lastButtonState = 0; // previous state of the button
|
||||
|
||||
void setup() {
|
||||
// initialize the button pin as a input:
|
||||
pinMode(buttonPin, INPUT);
|
||||
// initialize the LED as an output:
|
||||
pinMode(ledPin, OUTPUT);
|
||||
// initialize serial communication:
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// read the pushbutton input pin:
|
||||
buttonState = digitalRead(buttonPin);
|
||||
|
||||
// compare the buttonState to its previous state
|
||||
if (buttonState != lastButtonState) {
|
||||
// if the state has changed, increment the counter
|
||||
if (buttonState == HIGH) {
|
||||
// if the current state is HIGH then the button
|
||||
// wend from off to on:
|
||||
buttonPushCounter++;
|
||||
Serial.println("on");
|
||||
Serial.print("number of button pushes: ");
|
||||
Serial.println(buttonPushCounter);
|
||||
}
|
||||
else {
|
||||
// if the current state is LOW then the button
|
||||
// wend from on to off:
|
||||
Serial.println("off");
|
||||
}
|
||||
}
|
||||
// save the current state as the last state,
|
||||
//for next time through the loop
|
||||
lastButtonState = buttonState;
|
||||
|
||||
|
||||
// turns on the LED every four button pushes by
|
||||
// checking the modulo of the button push counter.
|
||||
// the modulo function gives you the remainder of
|
||||
// the division of two numbers:
|
||||
if (buttonPushCounter % 4 == 0) {
|
||||
digitalWrite(ledPin, HIGH);
|
||||
} else {
|
||||
digitalWrite(ledPin, LOW);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
keyboard
|
||||
|
||||
Plays a pitch that changes based on a changing analog input
|
||||
|
||||
circuit:
|
||||
* 3 force-sensing resistors from +5V to analog in 0 through 5
|
||||
* 3 10K resistors from analog in 0 through 5 to ground
|
||||
* 8-ohm speaker on digital pin 8
|
||||
|
||||
created 21 Jan 2010
|
||||
modified 30 Aug 2011
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
http://arduino.cc/en/Tutorial/Tone3
|
||||
|
||||
*/
|
||||
|
||||
#include "pitches.h"
|
||||
|
||||
const int threshold = 10; // minimum reading of the sensors that generates a note
|
||||
|
||||
// notes to play, corresponding to the 3 sensors:
|
||||
int notes[] = {
|
||||
NOTE_A4, NOTE_B4,NOTE_C3 };
|
||||
|
||||
void setup() {
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
for (int thisSensor = 0; thisSensor < 3; thisSensor++) {
|
||||
// get a sensor reading:
|
||||
int sensorReading = analogRead(thisSensor);
|
||||
|
||||
// if the sensor is pressed hard enough:
|
||||
if (sensorReading > threshold) {
|
||||
// play the note corresponding to this sensor:
|
||||
tone(8, notes[thisSensor], 20);
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
}
|
49
build/shared/examples/2.Digital/toneMelody/toneMelody.ino
Normal file
49
build/shared/examples/2.Digital/toneMelody/toneMelody.ino
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
Melody
|
||||
|
||||
Plays a melody
|
||||
|
||||
circuit:
|
||||
* 8-ohm speaker on digital pin 8
|
||||
|
||||
created 21 Jan 2010
|
||||
modified 30 Aug 2011
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
http://arduino.cc/en/Tutorial/Tone
|
||||
|
||||
*/
|
||||
#include "pitches.h"
|
||||
|
||||
// notes in the melody:
|
||||
int melody[] = {
|
||||
NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};
|
||||
|
||||
// note durations: 4 = quarter note, 8 = eighth note, etc.:
|
||||
int noteDurations[] = {
|
||||
4, 8, 8, 4,4,4,4,4 };
|
||||
|
||||
void setup() {
|
||||
// iterate over the notes of the melody:
|
||||
for (int thisNote = 0; thisNote < 8; thisNote++) {
|
||||
|
||||
// to calculate the note duration, take one second
|
||||
// divided by the note type.
|
||||
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
|
||||
int noteDuration = 1000/noteDurations[thisNote];
|
||||
tone(8, melody[thisNote],noteDuration);
|
||||
|
||||
// to distinguish the notes, set a minimum time between them.
|
||||
// the note's duration + 30% seems to work well:
|
||||
int pauseBetweenNotes = noteDuration * 1.30;
|
||||
delay(pauseBetweenNotes);
|
||||
// stop the tone playing:
|
||||
noTone(8);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// no need to repeat the melody.
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
Pitch follower
|
||||
|
||||
Plays a pitch that changes based on a changing analog input
|
||||
|
||||
circuit:
|
||||
* 8-ohm speaker on digital pin 8
|
||||
* photoresistor on analog 0 to 5V
|
||||
* 4.7K resistor on analog 0 to ground
|
||||
|
||||
created 21 Jan 2010
|
||||
modified 30 Aug 2011
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
http://arduino.cc/en/Tutorial/Tone2
|
||||
|
||||
*/
|
||||
|
||||
|
||||
void setup() {
|
||||
// initialize serial communications (for debugging only):
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the sensor:
|
||||
int sensorReading = analogRead(A0);
|
||||
// print the sensor reading so you know its range
|
||||
Serial.println(sensorReading);
|
||||
// map the pitch to the range of the analog input.
|
||||
// change the minimum and maximum input numbers below
|
||||
// depending on the range your sensor's giving:
|
||||
int thisPitch = map(sensorReading, 400, 1000, 100, 1000);
|
||||
|
||||
// play the pitch:
|
||||
tone(9, thisPitch, 10);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user