Advertisement
jmyean

Adding a Potentiometer to the Continuous Motor Circuit

Apr 25th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  /*
  2.   *  Jung Min Yean
  3.   *  Learning How to Use a Continuous Motor
  4.   *  04/23/2019
  5.   */
  6.  
  7. const int motorPin = 9;
  8. const int PotPin = A0;
  9. int PotVal = 0;
  10.  
  11.  
  12. void setup()
  13. {
  14.   pinMode(motorPin, OUTPUT);
  15.   pinMode(PotPin, INPUT);
  16.   Serial.begin(9600);
  17. }
  18.  
  19. void loop()
  20. {
  21.   PotVal = analogRead(PotPin);
  22.   int MapVal = map(PotVal,0,1023,0,255);
  23.   analogWrite(motorPin, PotVal);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement