Hello guys, I tried to simulate something like the linear actuator but using LED to represent. I did the code and wire everything up in person and it worked, but somehow it doesn't work in the simulator. Is there anything wrong with the diagram? Also, what can I improve with the code?
learn about different variable types.
see if any of your port pin assignement is really two bytes large and chose the right variable type instead.
make variables const if they shouldn't change during runtime (spoiler: pin assignments don't change so much, make them const).
What do you mean with two switches pressed at the same time ? Do you mean the two buttons ?
You try to solve the problem with if-statements. However, you need a certain sequence of code.
There is something for that: a Finite State Machine. That is a fancy word for something simple: https://majenko.co.uk/blog/finite-state-machine.
It is small chunks of code, and a 'state' selects which chunk of code should run this time.
You can make a sketch without the Finite State Machine, but when you look at your code afterwards, you only have to reorganize the code to make it a Finite State Machine.
What I meant by two switches are pressed at the same time is that when actuator 1 hit the first limit switch, then the actuator 2 will starting moving and hit another limit switch. At the moment when 2nd actuator hit the switch, those two limit switches are pressed at the same time.