Advertisement
michaelmai

DC Motor

Sep 11th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define SoftPin A0
  2. static int DcMotorPin = 9;
  3.  
  4. void setup() {
  5.   // put your setup code here, to run once:
  6.   Serial.begin(9600);
  7.   pinMode(DcMotorPin, OUTPUT);
  8.   pinMode(SoftPin, INPUT);
  9. }
  10.  
  11. int i;
  12.  
  13. void loop() {
  14. //  i = 150;
  15. //  while(i < 255){
  16. //    analogWrite(DcMotorPin, i);
  17. //    delay(10);
  18. //    i ++;
  19. //    }
  20. //  while(i > 150){
  21. //    analogWrite(DcMotorPin, i);
  22. //    delay(10);
  23. //    i --;
  24. //    }
  25.   int r = analogRead(SoftPin);
  26.   //Serial.println(r);
  27.   int Speed = (r) * 255.0 / 1023.0;
  28.   Serial.println(Speed);
  29.   analogWrite(DcMotorPin, Speed);
  30.   delay(10);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement