Guest User

Untitled

a guest
Jan 23rd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <SD.h>
  3. #include <AccelStepper.h>
  4. int STP = 4;
  5. int DIR = 3;
  6. const int chipSelect = 53;
  7. double Acceleration = 0;
  8. double Previous_Acceleration = 0;
  9. double Velocity = 0;
  10. double Previous_Velocity = 0;
  11. double Distance = 0;
  12. double Previous_Distance;
  13. AccelStepper stepper(AccelStepper::DRIVER,STP,DIR);
  14. void setup(){
  15. pinMode(STP,OUTPUT);
  16. pinMode(DIR,OUTPUT);
  17. Serial.begin(38400);
  18. Serial.println("Starting Program");
  19. delay(1000);
  20. while (!Serial){
  21. ;
  22. }
  23. Serial.println("Initializing SD Card...");
  24. if (!SD.begin(chipSelect)){
  25. Serial.println("SD Card Error");
  26. while(1);
  27. }
  28. Serial.println("Card Initialized");
  29.  
  30. File dataFile = SD.open("sinx.txt");
  31.  
  32. if (dataFile){
  33. while (dataFile.available()){
  34. Acceleration = dataFile.parseFloat();
  35. Velocity = ((Previous_Acceleration + Acceleration)/2) + Previous_Velocity;
  36. Distance = ((Previous_Velocity + Velocity)/2) + Previous_Distance;
  37. stepper.setSpeed(Velocity);
  38. stepper.setAcceleration(Acceleration);
  39. stepper.runToNewPosition(Distance - Previous_Distance);
  40.  
  41. }
  42. }
  43. else{
  44. Serial.println("Error");
  45. }
  46. }
  47.  
  48. void loop(){
  49.  
  50. }
Add Comment
Please, Sign In to add comment