arduino-0018-linux-x64
This commit is contained in:
parent
8e4748e499
commit
ed785c5798
426 changed files with 76732 additions and 0 deletions
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
Analog input, analog output, serial output
|
||||
|
||||
Reads an analog input pin, maps the result to a range from 0 to 255
|
||||
and uses the result to set the pulsewidth modulation (PWM) of an output pin.
|
||||
Also prints the results to the serial monitor.
|
||||
|
||||
The circuit:
|
||||
* potentiometer connected to analog pin 0.
|
||||
Center pin of the potentiometer goes to the analog pin.
|
||||
side pins of the potentiometer go to +5V and ground
|
||||
* LED connected from digital pin 9 to ground
|
||||
|
||||
created 29 Dec. 2008
|
||||
by Tom Igoe
|
||||
|
||||
*/
|
||||
|
||||
// These constants won't change. They're used to give names
|
||||
// to the pins used:
|
||||
const int analogInPin = 0; // Analog input pin that the potentiometer is attached to
|
||||
const int analogOutPin = 9; // Analog output pin that the LED is attached to
|
||||
|
||||
int sensorValue = 0; // value read from the pot
|
||||
int outputValue = 0; // value output to the PWM (analog out)
|
||||
|
||||
void setup() {
|
||||
// initialize serial communications at 9600 bps:
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the analog in value:
|
||||
sensorValue = analogRead(analogInPin);
|
||||
// map it to the range of the analog out:
|
||||
outputValue = map(sensorValue, 0, 1023, 0, 255);
|
||||
// change the analog out value:
|
||||
analogWrite(analogOutPin, outputValue);
|
||||
|
||||
// print the results to the serial monitor:
|
||||
Serial.print("sensor = " );
|
||||
Serial.print(sensorValue);
|
||||
Serial.print("\t output = ");
|
||||
Serial.println(outputValue);
|
||||
|
||||
// wait 10 milliseconds before the next loop
|
||||
// for the analog-to-digital converter to settle
|
||||
// after the last reading:
|
||||
delay(10);
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
Analog input, serial output
|
||||
|
||||
Reads an analog input pin, prints the results to the serial monitor.
|
||||
|
||||
The circuit:
|
||||
|
||||
* potentiometer connected to analog pin 0.
|
||||
Center pin of the potentiometer goes to the analog pin.
|
||||
side pins of the potentiometer go to +5V and ground
|
||||
|
||||
created over and over again
|
||||
by Tom Igoe and everyone who's ever used Arduino
|
||||
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the analog input into a variable:
|
||||
int analogValue = analogRead(0);
|
||||
// print the result:
|
||||
Serial.println(analogValue);
|
||||
// wait 10 milliseconds for the analog-to-digital converter
|
||||
// to settle after the last reading:
|
||||
delay(10);
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
Analog Input
|
||||
Demonstrates analog input by reading an analog sensor on analog pin 0 and
|
||||
turning on and off a light emitting diode(LED) connected to digital pin 13.
|
||||
The amount of time the LED will be on and off depends on
|
||||
the value obtained by analogRead().
|
||||
|
||||
The circuit:
|
||||
* Potentiometer attached to analog input 0
|
||||
* center pin of the potentiometer to the analog pin
|
||||
* one side pin (either one) to ground
|
||||
* the other side pin to +5V
|
||||
* LED anode (long leg) attached to digital output 13
|
||||
* LED cathode (short leg) attached to ground
|
||||
|
||||
* Note: because most Arduinos have a built-in LED attached
|
||||
to pin 13 on the board, the LED is optional.
|
||||
|
||||
|
||||
Created by David Cuartielles
|
||||
Modified 16 Jun 2009
|
||||
By Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/AnalogInput
|
||||
|
||||
*/
|
||||
|
||||
int sensorPin = 0; // select the input pin for the potentiometer
|
||||
int ledPin = 13; // select the pin for the LED
|
||||
int sensorValue = 0; // variable to store the value coming from the sensor
|
||||
|
||||
void setup() {
|
||||
// declare the ledPin as an OUTPUT:
|
||||
pinMode(ledPin, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the value from the sensor:
|
||||
sensorValue = analogRead(sensorPin);
|
||||
// turn the ledPin on
|
||||
digitalWrite(ledPin, HIGH);
|
||||
// stop the program for <sensorValue> milliseconds:
|
||||
delay(sensorValue);
|
||||
// turn the ledPin off:
|
||||
digitalWrite(ledPin, LOW);
|
||||
// stop the program for for <sensorValue> milliseconds:
|
||||
delay(sensorValue);
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
Mega analogWrite() test
|
||||
|
||||
This sketch fades LEDs up and down one at a time on digital pins 2 through 13.
|
||||
This sketch was written for the Arduino Mega, and will not work on previous boards.
|
||||
|
||||
The circuit:
|
||||
* LEDs attached from pins 2 through 13 to ground.
|
||||
|
||||
created 8 Feb 2009
|
||||
by Tom Igoe
|
||||
*/
|
||||
// These constants won't change. They're used to give names
|
||||
// to the pins used:
|
||||
const int lowestPin = 2;
|
||||
const int highestPin = 13;
|
||||
|
||||
|
||||
void setup() {
|
||||
// set pins 2 through 13 as outputs:
|
||||
for (int thisPin =lowestPin; thisPin <= highestPin; thisPin++) {
|
||||
pinMode(thisPin, OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// iterate over the pins:
|
||||
for (int thisPin =lowestPin; thisPin <= highestPin; thisPin++) {
|
||||
// fade the LED on thisPin from off to brightest:
|
||||
for (int brightness = 0; brightness < 255; brightness++) {
|
||||
analogWrite(thisPin, brightness);
|
||||
delay(2);
|
||||
}
|
||||
// fade the LED on thisPin from brithstest to off:
|
||||
for (int brightness = 255; brightness >= 0; brightness--) {
|
||||
analogWrite(thisPin, brightness);
|
||||
delay(2);
|
||||
}
|
||||
// pause between LEDs:
|
||||
delay(100);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
Calibration
|
||||
|
||||
Demonstrates one techinque for calibrating sensor input. The
|
||||
sensor readings during the first five seconds of the sketch
|
||||
execution define the minimum and maximum of expected values
|
||||
attached to the sensor pin.
|
||||
|
||||
The sensor minumum and maximum initial values may seem backwards.
|
||||
Initially, you set the minimum high and listen for anything
|
||||
lower, saving it as the new minumum. Likewise, you set the
|
||||
maximum low and listen for anything higher as the new maximum.
|
||||
|
||||
The circuit:
|
||||
* Analog sensor (potentiometer will do) attached to analog input 0
|
||||
* LED attached from digital pin 9 to ground
|
||||
|
||||
created 29 Oct 2008
|
||||
By David A Mellis
|
||||
Modified 17 Jun 2009
|
||||
By Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/Calibration
|
||||
|
||||
*/
|
||||
|
||||
// These constants won't change:
|
||||
const int sensorPin = 2; // pin that the sensor is attached to
|
||||
const int ledPin = 9; // pin that the LED is attached to
|
||||
|
||||
// variables:
|
||||
int sensorValue = 0; // the sensor value
|
||||
int sensorMin = 1023; // minimum sensor value
|
||||
int sensorMax = 0; // maximum sensor value
|
||||
|
||||
|
||||
void setup() {
|
||||
// turn on LED to signal the start of the calibration period:
|
||||
pinMode(13, OUTPUT);
|
||||
digitalWrite(13, HIGH);
|
||||
|
||||
// calibrate during the first five seconds
|
||||
while (millis() < 5000) {
|
||||
sensorValue = analogRead(sensorPin);
|
||||
|
||||
// record the maximum sensor value
|
||||
if (sensorValue > sensorMax) {
|
||||
sensorMax = sensorValue;
|
||||
}
|
||||
|
||||
// record the minimum sensor value
|
||||
if (sensorValue < sensorMin) {
|
||||
sensorMin = sensorValue;
|
||||
}
|
||||
}
|
||||
|
||||
// signal the end of the calibration period
|
||||
digitalWrite(13, LOW);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the sensor:
|
||||
sensorValue = analogRead(sensorPin);
|
||||
|
||||
// apply the calibration to the sensor reading
|
||||
sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);
|
||||
|
||||
// in case the sensor value is outside the range seen during calibration
|
||||
sensorValue = constrain(sensorValue, 0, 255);
|
||||
|
||||
// fade the LED using the calibrated value:
|
||||
analogWrite(ledPin, sensorValue);
|
||||
}
|
43
arduino-0018-linux-x64/examples/Analog/Fading/Fading.pde
Normal file
43
arduino-0018-linux-x64/examples/Analog/Fading/Fading.pde
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
Fading
|
||||
|
||||
This example shows how to fade an LED using the analogWrite() function.
|
||||
|
||||
The circuit:
|
||||
* LED attached from digital pin 9 to ground.
|
||||
|
||||
Created 1 Nov 2008
|
||||
By David A. Mellis
|
||||
Modified 17 June 2009
|
||||
By Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/Fading
|
||||
|
||||
*/
|
||||
|
||||
|
||||
int ledPin = 9; // LED connected to digital pin 9
|
||||
|
||||
void setup() {
|
||||
// nothing happens in setup
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// fade in from min to max in increments of 5 points:
|
||||
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
|
||||
// sets the value (range from 0 to 255):
|
||||
analogWrite(ledPin, fadeValue);
|
||||
// wait for 30 milliseconds to see the dimming effect
|
||||
delay(30);
|
||||
}
|
||||
|
||||
// fade out from max to min in increments of 5 points:
|
||||
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
|
||||
// sets the value (range from 0 to 255):
|
||||
analogWrite(ledPin, fadeValue);
|
||||
// wait for 30 milliseconds to see the dimming effect
|
||||
delay(30);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
|
||||
Smoothing
|
||||
|
||||
Reads repeatedly from an analog input, calculating a running average
|
||||
and printing it to the computer. Keeps ten readings in an array and
|
||||
continually averages them.
|
||||
|
||||
The circuit:
|
||||
* Analog sensor (potentiometer will do) attached to analog input 0
|
||||
|
||||
Created 22 April 2007
|
||||
By David A. Mellis <dam@mellis.org>
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Smoothing
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
// Define the number of samples to keep track of. The higher the number,
|
||||
// the more the readings will be smoothed, but the slower the output will
|
||||
// respond to the input. Using a constant rather than a normal variable lets
|
||||
// use this value to determine the size of the readings array.
|
||||
const int numReadings = 10;
|
||||
|
||||
int readings[numReadings]; // the readings from the analog input
|
||||
int index = 0; // the index of the current reading
|
||||
int total = 0; // the running total
|
||||
int average = 0; // the average
|
||||
|
||||
int inputPin = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// initialize serial communication with computer:
|
||||
Serial.begin(9600);
|
||||
// initialize all the readings to 0:
|
||||
for (int thisReading = 0; thisReading < numReadings; thisReading++)
|
||||
readings[thisReading] = 0;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// subtract the last reading:
|
||||
total= total - readings[index];
|
||||
// read from the sensor:
|
||||
readings[index] = analogRead(inputPin);
|
||||
// add the reading to the total:
|
||||
total= total + readings[index];
|
||||
// advance to the next position in the array:
|
||||
index = index + 1;
|
||||
|
||||
// if we're at the end of the array...
|
||||
if (index >= numReadings)
|
||||
// ...wrap around to the beginning:
|
||||
index = 0;
|
||||
|
||||
// calculate the average:
|
||||
average = total / numReadings;
|
||||
// send it to the computer (as ASCII digits)
|
||||
Serial.println(average, DEC);
|
||||
}
|
||||
|
||||
|
Reference in a new issue