/* * AnalogInput_Serial_Out BJ Furman 01APR2010 Demonstrates analog input by reading an analog sensor (pot) on analog pin 1 and turns on and off the blue LED on pin 6 at a rate proportional to the pot voltage: higher voltage, faster blinking; lower voltage, slower blinking. The amount of time the LED will be on and off depends on the value obtained by analogRead(). based on the AnalogInput example Created by David Cuartielles Modified 16 Jun 2009 By Tom Igoe http://arduino.cc/en/Tutorial/AnalogInput */ #define MAX_DELAY_TIME 1000 // max delay in ms #define MIN_DELAY_TIME 10 // min delay in ms #define MAX_POT_VALUE 855 // max pot reading #define MIN_POT_VALUE 0 // min pot reading const byte potPin = 1; // potentiometer output on pin 1 const byte ledPin = 6; // blue LED on pin 6 unsigned int potVoltage = 0; // pot voltage value unsigned int delay_ms; void setup() { // declare the ledPin as an output, potPin as an input: pinMode(ledPin, OUTPUT); pinMode(potPin, INPUT); // initialize serial communications at 9600 bps: Serial.begin(9600); } void loop() { // read the value from the sensor: potVoltage = analogRead(potPin); // print the results to the serial monitor: Serial.print("sensor = " ); Serial.print(potVoltage); Serial.print(" delay, ms = " ); Serial.println(delay_ms); // print delay value and end-of-line // map the pot voltage into a proportional delay delay_ms = map(potVoltage,MIN_POT_VALUE,MAX_POT_VALUE,MIN_DELAY_TIME,MAX_DELAY_TIME); // turn the LED on digitalWrite(ledPin, HIGH); // program waits for milliseconds: delay(delay_ms); // turn the LED off: digitalWrite(ledPin, LOW); // program waits for milliseconds: delay(delay_ms); }