Analogue Input
Program #4(Analogue Input)
/*
- AnalogInput
*
*
- 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 PhotoResistor to analog pin 2.
*/
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
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as an 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
}
page_revision: 6, last_edited: 4 Sep 2008, 12:38 GMT+05 (13 minutes ago)
page revision: 0, last edited: 04 Sep 2008 07:22