a

Dependencies:   LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI

Revision:
4:e48aee3e8d09
Child:
5:3c19c3ae6286
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stepper.cpp	Thu May 21 11:03:32 2020 +0000
@@ -0,0 +1,57 @@
+#include "stepper.h"
+
+enum Step{LEFT,RIGHT};
+
+Stepper::Stepper() : Button(USER_BUTTON){
+}
+
+void Stepper::Step(enum Step eStep){
+    if(eStep == LEFT){
+        ucLedIdx++;
+    }
+    else if(eStep == RIGHT){
+        ucLedIdx--;
+    }
+    else{}
+    ucLedIdx = ucLedIdx % 4;
+    MyLed.On(ucLedIdx);
+}
+
+void Stepper::StepLeft(void){
+    Step(LEFT);
+}
+
+void Stepper::StepRight(void){
+    Step(RIGHT);
+}
+
+void Stepper::Callib(void) {
+    while(!Button) {
+        StepRight();
+        wait(0.1);
+    }
+}
+
+void Stepper::Goto(unsigned char ucDestination) {
+    ucDesiredPos = ucDestination;
+    while (ucCurrentPos > ucDesiredPos) {
+        StepLeft();
+        ucCurrentPos --;
+        wait(0.2);
+    }
+    while (ucCurrentPos < ucDesiredPos) {
+        StepRight();
+        ucCurrentPos ++;
+        wait(0.2);
+    } 
+}
+
+void Stepper::Step(unsigned char ucSteps) {
+    ucDesiredPos = ucCurrentPos + ucSteps;
+    while (ucCurrentPos < ucDesiredPos) {
+        StepRight();
+        ucCurrentPos ++;
+        wait(0.2);
+    } 
+}
+