jmyean

Using AnalogRead and AnalogWrite with Potentiometer

Apr 1st, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  *  Jung Min Yean
  3.  *  03/28/19
  4.  *  Learning How to Use Analog Read and Write
  5.  */
  6.  
  7.  const int LedPin1 = 9;
  8.  const int LedPin2 = 10;
  9.  const int LedPin3 = 11;
  10.  const int PotPin = A0;
  11.  int PotVal = 0;
  12.  
  13. void setup()
  14. {
  15.  pinMode(LedPin1, OUTPUT);
  16.  pinMode(LedPin2, OUTPUT);
  17.  pinMode(LedPin3, OUTPUT);
  18.  pinMode(PotPin, INPUT);
  19.  Serial.begin(9600);
  20. }
  21.  
  22. void loop()
  23. {
  24.   // test potentiometer
  25.   PotVal = analogRead(PotPin);
  26.   Serial.println(PotVal);
  27.   PotVal = PotVal/4;
  28.   analogWrite(LedPin1, PotVal);
  29.   analogWrite(LedPin2, PotVal);
  30.   analogWrite(LedPin3, PotVal);
  31. }
Add Comment
Please, Sign In to add comment