Skip to content

Instantly share code, notes, and snippets.

@shawngrimes
Last active April 8, 2016 03:11
Show Gist options
  • Save shawngrimes/906279b6811d485f57a0afe92a5c56ea to your computer and use it in GitHub Desktop.
Save shawngrimes/906279b6811d485f57a0afe92a5c56ea to your computer and use it in GitHub Desktop.
Basic sketch to demonstrate analog input.
int ledPin=9; //Variable to store pin of LED
int potentPin=A0; //Variable to store pin of potentiometer
int potentValue=0; //Variable to store last known value of potentiometer
int brightnessValue=0; //Variable to store LED brightness
void setup() {
// put your setup code here, to run once:
pinMode(ledPin, OUTPUT); //Setup LED pin for output
}
void loop() {
// put your main code here, to run repeatedly:
potentValue=analogRead(potentPin); //Read the value of the potentiometer pin
brightnessValue=map(potentValue,0,1023,0,255); //Map the potentiometer value to a brightness
analogWrite(ledPin,brightnessValue); //Set the brightness of the ledPin
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment