Skip to content

Commit

Permalink
additional stepper example
Browse files Browse the repository at this point in the history
release as version 2.4.3
  • Loading branch information
Franz-Peter committed Apr 28, 2022
1 parent 0b18f3d commit 636329b
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
Binary file modified MobaTools-243-en.pdf
Binary file not shown.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ A documentation file in [german](MobaTools-241-de.pdf) and [english](MobaTools-2

| Version | Release Date | Description
| ------- | ------------ | -----------
| 2.4.3 | 2022-xx-x| small bugfix to suppress warnings (issue [#10](https://github.com/MicroBahner/MobaTools/issues/10) )
| 2.4.3 | 2022-04-28| small bugfix to suppress warnings (issue [#10](https://github.com/MicroBahner/MobaTools/issues/10) )
| | | bugfix for setZero(position) for steppers in FULLSTEP mode
| | | bugfix with AccelStepper like method names ( compiler error if both libs have been included )
| | | 2 additional timer examples commented in english
| | | 1 additional stepper example
| 2.4.2 | 2021-12-23| fix bug in MoToStepper.setSpeedSteps ( was possible divide by zero )
| | | ESP crashed
| 2.4.1 | 2021-11-12| fix typo: arduino.h -> Arduino.h ( created an error on linux )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* Example for MobaTools
Moving a stepper back and forth
*/
#include <MobaTools.h>

// Adjust pins, steps and time as needed
const byte stepPin = 9;
const byte dirPin = 8;
const int stepsPerRev = 800; // Steps per Revolution ( example with 1/4 microsteps )
const long targetPos = 1600; // stepper moves between 0 and targetpos
long nextPos;


MoToStepper myStepper ( stepsPerRev, STEPDIR );
MoToTimer pause; // Pause between stepper moves
bool stepperRunning;

void setup() {
myStepper.attach( stepPin, dirPin );
myStepper.setSpeed( 600 ); // 60 Rev/Min ( if stepsPerRev is set correctly )
myStepper.setRampLen( 200 );
stepperRunning = true;
}

void loop() {
if ( stepperRunning ) {
// Wait till stepper has reached target, then set pause time
if ( !myStepper.moving() ) {
// stepper has reached target, start pause
pause.setTime( 1000 );
stepperRunning = false;
}
} else {
// stepper doesn't move, wait till pause time expires
if ( pause.expired() ) {
// pause time expired. Start stepper in opposite direction
if ( nextPos == 0 ) {
nextPos = targetPos;
} else {
nextPos = 0;
}
myStepper.moveTo( nextPos );
stepperRunning = true;
}
}

// The sketch is not blocked while the stepper is moving nor while it is stopped.
// Other nonblocking tasks can be added here
}
13 changes: 10 additions & 3 deletions src/MobaTools.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef MOBATOOLS_H
#define MOBATOOLS_H
/*
MobaTools.h - a library for model railroaders
Author: fpm, fpm-gh@mnet-mail.de
MobaTools.h - a library for model makers - and others too ;-)
Author: Franz-Peter Müller, f-pm+gh@mailbox.org
Copyright (c) 2021 All rights reserved.
This library is free software; you can redistribute it and/or
Expand All @@ -19,9 +19,16 @@
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
MobaTools V2.4.1
MobaTools V2.4.3
History:
V2.4.3 04-2022
- bugfix for setZero(position) for steppers in FULLSTEP mode
- bugfix with AccelStepper like method names ( compiler error if both libs have been included )
- 2 additional timer examples commented in english
- 1 additional stepper example
V2.4.2 12-2021
- fix bug in MoToStepper.setSpeedSteps ( was possible divide by zero ), ESP crashed
V2.4.1 11-2021
- fix typo ( arduino.h -> Arduino.h ). This created an error on linux.
- some fixes in MoToButtons and documentation
Expand Down

0 comments on commit 636329b

Please sign in to comment.