Last active
August 5, 2016 18:13
-
-
Save masha256/e3bf5fb534a2a65bd561311044e2df0a to your computer and use it in GitHub Desktop.
particle photon stepper tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This #include statement was automatically added by the Particle IDE. | |
#include "AccelStepperSpark/AccelStepperSpark.h" | |
#define STEP_FACTOR 8 | |
bool forward = true; | |
// Define a stepper and the pins it will use | |
AccelStepper stepper(AccelStepper::DRIVER, A1, A2); | |
void setup() { | |
stepper.setMaxSpeed(160*STEP_FACTOR); | |
stepper.setAcceleration(50*STEP_FACTOR); | |
} | |
void loop() { | |
if (stepper.distanceToGo() == 0) { | |
delay(1000); | |
if (forward) { | |
stepper.moveTo(400*STEP_FACTOR); | |
} else { | |
stepper.moveTo(0*STEP_FACTOR); | |
} | |
forward = !forward; | |
} | |
stepper.run(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This #include statement was automatically added by the Particle IDE. | |
#include "AccelStepperSpark/AccelStepperSpark.h" | |
// Give us CONTROL over the cloud! | |
SYSTEM_MODE(MANUAL); | |
#define STEP_FACTOR 8 | |
bool forward = true; | |
AccelStepper stepper(AccelStepper::DRIVER, A1, A2); | |
void setup() { | |
stepper.setMaxSpeed(160*STEP_FACTOR); | |
stepper.setAcceleration(50*STEP_FACTOR); | |
Particle.connect(); | |
} | |
void loop() { | |
if (stepper.distanceToGo() == 0) { | |
delay(1000); | |
if (forward) { | |
stepper.moveTo(400*STEP_FACTOR); | |
} else { | |
stepper.moveTo(0*STEP_FACTOR); | |
} | |
forward = !forward; | |
} | |
stepper.run(); | |
// only talk to particle cloud while not moving the stepper to avoid stepper delays | |
if (stepper.speed() == 0) { | |
// in case we lost our connection | |
if (!Particle.connected()) { | |
Particle.connect(); | |
} | |
Particle.process(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment