// Bounce.pde
// -*- mode: C++ -*-
//
// Make a single stepper bounce from one limit to another
//
// Copyright (C) 2012 Mike McCauley
// $Id: Random.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $
#include <AccelStepper.h>
#include <Button.h>
Button button1(7); // Connect your button between pin 2 and GND
// Define a stepper and the pins it will use
AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
bool running = false;
void setup()
{
// Change these to suit your stepper if you want
// stepper.setMaxSpeed(100);
// stepper.setAcceleration(20);
// stepper.moveTo(500);
stepper.setMaxSpeed(1000);
stepper.setAcceleration(5);
stepper.setSpeed(50);
button1.begin();
while (!Serial) { }; // for Leos
Serial.begin(9600);
}
void loop()
{
// If at the end of travel go to the other end
if (button1.pressed()) {
running = !running;
Serial.println("Button 1 pressed");
Serial.println(running);
}
// if (stepper.distanceToGo() == 0)
// stepper.moveTo(-stepper.currentPosition());
if (running) {
stepper.runSpeed();
}
}