#include <AccelStepper.h>
int startTl = 2;
int rychleTl = 3;
int StartBt;
int RychlostBt;
int Position;
int speedS; #define dirPin 6 #define stepPin 7 #define motorInterfaceType 1
I control the stepper motor (nema 23). StartBt is SWITCH button, RychlostBt is PUSH button. What I need to do is: after I switch StartBt to 1 and RychlostBt push (I'll just press one or more times it doesn't matter) motor accelerates and if I switch StartBt to 0, motor declerate.
Now I have to hold RychlostBt when I accelerate, and I don't want that.
Do you have pullup or pulldown resistors on input pins to keep the pins from "floating" and causing false HIGHs or LOWs when the button is not pressed? Best way is like S3 in the diagram, no external resistor needed, logic is reversed though (pin is LOW when button is pressed).
Look up state machines. Think of your code in discrete chunks. You have a button/switch which can have 2 states 0/1. Put it in its own function (outside loop) and call it in loop. in the function you should read the switch, carry out any debouncing required, and change the state which can be held in a global variable e.g. StartBtState.
Then you make code for what you to do if startBtState is 0 and one for if 1.
Do the same for button 2.
Remember the loop loops so all code should be understood in terms of running over and over again very fast and, as such, you can detect changes and enter different parts of code as required.