Advertisement
3rdWard_Arduino

class2_potentiometer_Control_LED

Mar 18th, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. /*
  2.  Simple sketch to show output of potentiometer
  3.  value on the Serial Output Window and controlling
  4.  the brightness of an LED with pwm.
  5.  3/18/2012
  6.  */
  7.  
  8. int potPin = A0;// potentiometer attached to A0
  9. int potVal = 0; // potentiometer value 0-1023
  10. int pwmPin = 3; // pin for LED
  11. int pwmVal = 0; // PWM value, based on potVal, 0-255
  12.  
  13. void setup(){
  14.   Serial.begin(9600);
  15.   pinMode(pwmPin, OUTPUT);// not necessary, but is best practice
  16. }
  17.  
  18. void loop(){
  19.   potVal = analogRead(potPin);
  20.   Serial.println(potVal);
  21.  
  22.   pwmVal = map( potVal, 0, 1023, 0, 255 );
  23.   analogWrite(pwmPin, pwmVal);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement