Skip to content

Instantly share code, notes, and snippets.

@shawngrimes
Created July 15, 2016 15:43
Show Gist options
  • Save shawngrimes/b31c0763761d827c3d08fadca83fd623 to your computer and use it in GitHub Desktop.
Save shawngrimes/b31c0763761d827c3d08fadca83fd623 to your computer and use it in GitHub Desktop.
int ledPin=9; //Variable to store pin of LED
int photoPin=A0; //Variable to store pin of potentiometer
int photoValue=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:
photoValue=analogRead(photoPin); //Read the value of the potentiometer pin
brightnessValue=map(photoValue,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