Skip to main content
added 168 characters in body
Source Link
6v6gt
  • 1.2k
  • 6
  • 9

You can try replacing the function revmotor() with this code. That is instead of using the separate debounce code that you have found. It works by locking out presses of the switch for 100ms following the last press.

void revmotor (){
  static uint32_t lastSwitchAtMs = 0 ;
  if ( millis() - lastSwitchAtMs > 100UL ) {  // debounce 100ms
    setdir = !setdir;  
  }
  lastSwitchAtMs = millis() ; 
}

Note that the variable setdir should really be declared so volatile boolean setdir = LOW; // Set Direction

EDIT:

Incidentally, found the article that you followed here: https://dronebotworkshop.com/big-stepper-motors/ which includes the code and a schematic diagram.

You can try replacing the function revmotor() with this code. That is instead of using the separate debounce code that you have found. It works by locking out presses of the switch for 100ms following the last press.

void revmotor (){
  static uint32_t lastSwitchAtMs = 0 ;
  if ( millis() - lastSwitchAtMs > 100UL ) {  // debounce 100ms
    setdir = !setdir;  
  }
  lastSwitchAtMs = millis() ; 
}

Note that the variable setdir should really be declared so volatile boolean setdir = LOW; // Set Direction

You can try replacing the function revmotor() with this code. That is instead of using the separate debounce code that you have found. It works by locking out presses of the switch for 100ms following the last press.

void revmotor (){
  static uint32_t lastSwitchAtMs = 0 ;
  if ( millis() - lastSwitchAtMs > 100UL ) {  // debounce 100ms
    setdir = !setdir;  
  }
  lastSwitchAtMs = millis() ; 
}

Note that the variable setdir should really be declared so volatile boolean setdir = LOW; // Set Direction

EDIT:

Incidentally, found the article that you followed here: https://dronebotworkshop.com/big-stepper-motors/ which includes the code and a schematic diagram.

Source Link
6v6gt
  • 1.2k
  • 6
  • 9

You can try replacing the function revmotor() with this code. That is instead of using the separate debounce code that you have found. It works by locking out presses of the switch for 100ms following the last press.

void revmotor (){
  static uint32_t lastSwitchAtMs = 0 ;
  if ( millis() - lastSwitchAtMs > 100UL ) {  // debounce 100ms
    setdir = !setdir;  
  }
  lastSwitchAtMs = millis() ; 
}

Note that the variable setdir should really be declared so volatile boolean setdir = LOW; // Set Direction