Created
April 8, 2016 03:20
-
-
Save shawngrimes/d0c7b6572d55153a765020585d7edb3c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | |
Serial.begin(9600); //Setup serial console | |
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 | |
Serial.print("Analog Read: "); //Output to serial console | |
Serial.println(potentValue); //Output potentValue to serial console and add a new line at the end | |
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