Browse Source

tested and working limit system

digital and analog
will add hard limit on/off switch
titi 5 years ago
parent
commit
267eac5d0f
1 changed files with 10 additions and 8 deletions
  1. 10 8
      Atm_AccelStepper.cpp

+ 10 - 8
Atm_AccelStepper.cpp

@@ -59,12 +59,12 @@ int Atm_AccelStepper::event( int id ) {
         case 2:
 
           int analogTemp = analogRead(_limitLow_Pin);
-          limitLow_State = _limitLow_Thresholds[0] < analogTemp && analogTemp < _limitLow_Thresholds[1];
+          limitLow_State = (_limitLow_Thresholds[0] < analogTemp) && (analogTemp < _limitLow_Thresholds[1]);
           limitLow_State = _limitLow_Reversed ? !limitLow_State : limitLow_State;
-          // Serial.print("analog ");
-          // Serial.println(analogTemp);
-          // Serial.print("state ");
-          // Serial.println(limitLow_State);
+          Serial.print("analog ");
+          Serial.print(analogTemp);
+          Serial.print("  state ");
+          Serial.println(limitLow_State);
           return limitLow_State;
       }
     case EVT_ON_LIMIT_HIGH:
@@ -78,7 +78,7 @@ int Atm_AccelStepper::event( int id ) {
         case 2:
         //Serial.println("analog");
           int analogTemp = analogRead(_limitHigh_Pin);
-          limitHigh_State = _limitHigh_Thresholds[0] < analogTemp && analogTemp < _limitHigh_Thresholds[1];
+          limitHigh_State = (_limitHigh_Thresholds[0] < analogTemp) && (analogTemp < _limitHigh_Thresholds[1]);
           limitHigh_State = _limitHigh_Reversed ? !limitHigh_State : limitHigh_State;
           return limitHigh_State;
       }
@@ -235,7 +235,8 @@ Atm_AccelStepper& Atm_AccelStepper::limitLow_set(int mode,  int pin,  int revers
   _limitLow_Mode = mode ;
   _limitLow_Pin = pin ;
   _limitLow_Reversed = reversed ;
-  if (_limitLow_Mode) {pinMode(_limitLow_Pin, INPUT);}
+  if (_limitLow_Mode==1) {pinMode(_limitLow_Pin, INPUT_PULLUP);}
+  if (_limitLow_Mode==2) {pinMode(_limitLow_Pin, INPUT);}
   return *this;
 }
 
@@ -249,7 +250,8 @@ Atm_AccelStepper& Atm_AccelStepper::limitHigh_set(int mode,  int pin,  int rever
   _limitHigh_Mode = mode ;
   _limitHigh_Pin = pin ;
   _limitHigh_Reversed = reversed ;
-  if (_limitHigh_Mode) {pinMode(_limitHigh_Pin, INPUT);}
+  if (_limitHigh_Mode==1) {pinMode(_limitHigh_Pin, INPUT_PULLUP);}
+  if (_limitHigh_Mode==2) {pinMode(_limitHigh_Pin, INPUT);}
   return *this;
 }