Advertisement
j0h

sysaphean

j0h
Feb 2nd, 2023
1,171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Include the Arduino Stepper Library
  2. //sysiphean robot. .. I think Im making it too complex though. this is a scratch page
  3. #include <Stepper.h>
  4.  
  5. // Number of steps per output rotation
  6. const int stepsPerRevolution = 100;
  7.  
  8. // Create Instance of Stepper library
  9. Stepper myStepper(stepsPerRevolution, 2,3,4,5);
  10. /*
  11. 2,3,4,5 --yes
  12. */
  13. int fw = 6;
  14. int rv = 7;
  15. int pot= A9;
  16. int T = 0;  //run time corrosponds to theta but who cares
  17.  
  18. void Forward(int T);
  19. void Reverse(int T);
  20. void Stap();
  21.  
  22. void setup(){
  23.   // set the speed at 60 rpm:
  24.   myStepper.setSpeed(100);
  25.  pinMode(6, OUTPUT);
  26.  pinMode(7, OUTPUT);
  27.   // initialize the serial port:
  28.   Serial.begin(9600);
  29. while (Serial.available() == 1){ // dont start moving untill the usb is unplugged.
  30.   delay(5000);
  31.   }
  32.   Forward(10000);
  33.  
  34. }
  35.  
  36. void loop(){
  37.   int sensor = analogRead(pot);
  38. Serial.println(sensor);
  39. //delay(1);
  40.  myStepper.setSpeed(sensor);
  41. if(sensor > 701){
  42.   myStepper.step(-stepsPerRevolution);
  43.   }
  44.   if(sensor < 700 && sensor > 500){
  45. myStepper.halt();
  46.     }if(sensor < 500){
  47.      myStepper.step(stepsPerRevolution);
  48.     }
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55. }
  56.  
  57. void Forward(int T){ //if the other direction is high, turn it off.
  58.  if(digitalRead(rv)){
  59. Stap();
  60.  }
  61.   digitalWrite(fw, HIGH);
  62.   delay(T);
  63.   digitalWrite(fw, LOW);
  64.   }
  65.  
  66. void Reverse(){
  67.   if(digitalRead(fw)){
  68. Stap();
  69. }
  70.     digitalWrite(rv, HIGH);
  71.     delay(T);
  72.     digitalWrite(fw, LOW);
  73.   }  
  74.  
  75. void Stap(){
  76.   digitalWrite(fw, LOW);
  77.   digitalWrite(rv, LOW);
  78.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement