Advertisement
3rdWard_Arduino

Class2_reading potentiometer and setting PWM

Feb 1st, 2012
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.   Reading a potentiometer on analog pin A0
  3.  and printing out the value
  4.  and controls the PWM of an LED
  5.  */
  6.  
  7. int potValue = 0;
  8. int potPin = A0;
  9. int pwmValue = 0;
  10. int ledPin = 6;
  11.  
  12. void setup(){
  13.   Serial.begin(9600);
  14.   pinMode(ledPin, OUTPUT);
  15. }
  16.  
  17. void loop(){
  18.   potValue = analogRead( potPin );
  19.   Serial.print("potValue = ");
  20.   Serial.println(potValue);
  21.  
  22.   pwmValue = map(potValue, 0, 1023, 0, 255);
  23.   analogWrite(ledPin, pwmValue);
  24.   delay(100);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement