Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of stepper by
Diff: stepper.cpp
- Revision:
- 3:fd565358f888
- Parent:
- 2:e537d08c705b
- Child:
- 4:35d44eec6939
diff -r e537d08c705b -r fd565358f888 stepper.cpp
--- a/stepper.cpp Wed Jul 25 08:25:10 2018 +0000
+++ b/stepper.cpp Wed Jul 25 11:09:25 2018 +0000
@@ -3,8 +3,11 @@
void stepperMotor::moveStepper()
{
- if(remain == 0)
+ if(remain == 0 || limitSwitch.read() == 0)
+ {
+ remain = 0;
return;
+ }
if(step)
{
step = 0; //STEP 1->0
@@ -23,7 +26,8 @@
void stepperMotor::enable(int inputRemain)
{
- remain = inputRemain;
+ setDir(inputRemain >= 0? true: false);
+ remain = inputRemain >= 0? inputRemain: -inputRemain;
enable();
}
@@ -43,8 +47,10 @@
dir = direction;
}
-stepperMotor::stepperMotor(PinName stepPin, PinName dirPin, PinName enPin, float period): remain(0), step(stepPin), dir(dirPin), en(enPin)
+stepperMotor::stepperMotor(PinName stepPin, PinName dirPin, PinName enPin, PinName limitSwitchPin, float period):
+ remain(0), step(stepPin), dir(dirPin), en(enPin), limitSwitch(limitSwitchPin)
{
disable();
+ limitSwitch.mode(PullUp);
stepper.attach(this, &stepperMotor::moveStepper, period);
}
