1
0
Fork 0
This repository has been archived on 2019-12-23. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
arduinisten/arduino-0022-linux-x64/examples/3.Analog/AnalogInput/AnalogInput.pde

50 lines
1.5 KiB
Text
Raw Normal View History

2010-03-30 20:09:55 +02:00
/*
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
2011-02-23 21:47:18 +01:00
Modified 4 Sep 2010
2010-03-30 20:09:55 +02:00
By Tom Igoe
2011-02-23 21:47:18 +01:00
This example code is in the public domain.
2010-03-30 20:09:55 +02:00
http://arduino.cc/en/Tutorial/AnalogInput
*/
2011-02-23 21:47:18 +01:00
int sensorPin = A0; // select the input pin for the potentiometer
2010-03-30 20:09:55 +02:00
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);
}