Back to Parent

//Prev Version (continuously shuttles bus back and forth):
#include "AccelStepper.h"

//Continuously moves bus back and forth. To move forward takes 5 minutes, to move back takes 1 minute

// Remember to set all MS pins high for 16th-microstepping
// defines pins
const int step = D2;
const int dir = D1;
AccelStepper Stepper(1, step, dir);
void setup() {
  Stepper.setMaxSpeed(1000);
  Stepper.moveTo(5000);
  Stepper.setSpeed(200);
  Stepper.setAcceleration(0);
}
void loop() {
   int time = Time.minute();
   transmit("time", Time.minute());
   //moves forward 1 step / 2.5 sec for 1200 steps => 5 min to span display
   Stepper.setSpeed(25);
   while (Stepper.currentPosition() < 1200){
       Stepper.runSpeed();
       delay(2500);
       transmit("position",Stepper.currentPosition());
   }
   Stepper.setSpeed(-200);
   while(Stepper.currentPosition() > 0){
       Stepper.runSpeed();
       delay(10);
       transmit("position",Stepper.currentPosition());
   }
   Stepper.setSpeed(200);
}
void transmit(char message[],int value){
  char valtext[1];
  sprintf(valtext,"%i", value);
  Particle.publish(message,valtext,PRIVATE);
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0