Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #define potmeterPin A3
  2.  
  3. // defines pins numbers
  4. const int stepPin = 3;
  5. const int dirPin = 2;
  6.  
  7.  
  8. int p;
  9. float delay_time=100;
  10.  
  11. void setup() {
  12.  
  13. Serial.begin(9600);
  14.  
  15.  
  16. // Sets the two pins as Outputs
  17. pinMode(stepPin,OUTPUT);
  18. pinMode(dirPin,OUTPUT);
  19.  
  20.  
  21.  
  22. // Set Dir to Home switch
  23. digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
  24.  
  25.  
  26. }
  27. void loop() {
  28.  
  29. p = analogRead(potmeterPin);
  30. delay_time = map(p,0,923,100,250);
  31.  
  32. motorStep(1);
  33.  
  34. }
  35. void motorStep( int MAX){
  36.  
  37. for(int x = 0; x < MAX; x++) {
  38. digitalWrite(stepPin,HIGH);
  39. delayMicroseconds(delay_time);
  40. digitalWrite(stepPin,LOW);
  41. delayMicroseconds(delay_time);
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement