Skip to content

Instantly share code, notes, and snippets.

@machadolab

machadolab/auto_mode.ino

Last active Aug 5, 2016
Embed
What would you like to do?
particle photon stepper tests
// 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 #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