From f886662ea0a94a9342f0b9f5129619d5800b9fbf Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Wed, 17 Jun 2009 21:26:02 +0000 Subject: [PATCH] --- .../Analog/AnalogInput/AnalogInput.pde | 59 +++++++++++++------ 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/build/shared/dist/examples/Analog/AnalogInput/AnalogInput.pde b/build/shared/dist/examples/Analog/AnalogInput/AnalogInput.pde index 131eb5549..1ee8ee37e 100644 --- a/build/shared/dist/examples/Analog/AnalogInput/AnalogInput.pde +++ b/build/shared/dist/examples/Analog/AnalogInput/AnalogInput.pde @@ -1,27 +1,48 @@ /* - * AnalogInput - * by DojoDave - * - * Turns 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(). In the easiest case we connect - * a potentiometer to analog pin 2. - * - * http://www.arduino.cc/en/Tutorial/AnalogInput + 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 potPin = 2; // select the input pin for the potentiometer -int ledPin = 13; // select the pin for the LED -int val = 0; // variable to store the value coming from the sensor +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() { - pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT + // declare the ledPin as an OUTPUT: + pinMode(ledPin, OUTPUT); } void loop() { - val = analogRead(potPin); // read the value from the sensor - digitalWrite(ledPin, HIGH); // turn the ledPin on - delay(val); // stop the program for some time - digitalWrite(ledPin, LOW); // turn the ledPin off - delay(val); // stop the program for some time -} + // read the value from the sensor: + sensorValue = analogRead(sensorPin); + // turn the ledPin on + digitalWrite(ledPin, HIGH); + // stop the program for milliseconds: + delay(sensorValue); + // turn the ledPin off: + digitalWrite(ledPin, LOW); + // stop the program for for milliseconds: + delay(sensorValue); +} \ No newline at end of file