Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <SD.h>
- #include <AccelStepper.h>
- int STP = 4;
- int DIR = 3;
- const int chipSelect = 53;
- double Acceleration = 0;
- double Previous_Acceleration = 0;
- double Velocity = 0;
- double Previous_Velocity = 0;
- double Distance = 0;
- double Previous_Distance;
- AccelStepper stepper(AccelStepper::DRIVER,STP,DIR);
- void setup(){
- pinMode(STP,OUTPUT);
- pinMode(DIR,OUTPUT);
- Serial.begin(38400);
- Serial.println("Starting Program");
- delay(1000);
- while (!Serial){
- ;
- }
- Serial.println("Initializing SD Card...");
- if (!SD.begin(chipSelect)){
- Serial.println("SD Card Error");
- while(1);
- }
- Serial.println("Card Initialized");
- File dataFile = SD.open("sinx.txt");
- if (dataFile){
- while (dataFile.available()){
- Acceleration = dataFile.parseFloat();
- Velocity = ((Previous_Acceleration + Acceleration)/2) + Previous_Velocity;
- Distance = ((Previous_Velocity + Velocity)/2) + Previous_Distance;
- stepper.setSpeed(Velocity);
- stepper.setAcceleration(Acceleration);
- stepper.runToNewPosition(Distance - Previous_Distance);
- }
- }
- else{
- Serial.println("Error");
- }
- }
- void loop(){
- }
Add Comment
Please, Sign In to add comment