Skip to content

Instantly share code, notes, and snippets.

@5v3n
Created April 13, 2011 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 5v3n/917295 to your computer and use it in GitHub Desktop.
Save 5v3n/917295 to your computer and use it in GitHub Desktop.
Corrected .pde for the example at http://fritzing.org/projects/analog-inputoutput/
// Controlling the modulation of an LED using a potentiometer (variable resistor)
int ledpin = 3; // light connected to digital pin 3
int potpin = A3; // analog pin used to connect the potentiometer
int sensorValue, outputValue; // variables to read the values
void setup()
{
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop()
{
sensorValue = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
outputValue = map(sensorValue, 0, 1023, 0, 254); // scale it to use it with the LED (value between 0 and 255)
analogWrite(ledpin, outputValue);
// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment