Help with java coding

How can i program a motor to spin 180 degrees forward when i press a button and then spin 180 degrees backwards when i press a different button?

Well, if you want to spin a certain number of degrees you’ll need a sensor on your motor shaft.

You can attach a potentiometer to your motor shaft. A potentiometer is an analog sensor that measures how far you have rotated based on the change in its resistance. Sure “program potentiometer” on Chief Delphi and I’m sure there are threads devoted to it. If I recall, you can hook the potentiometer up to an analog channel and read the data it gives you (a certain change in voltage will correspond to a certain change in degrees). You would read your potentiometer, then tell the motor to run. You would continue to read your potentiometer and tell the motor to stop running when it had turned a certain amount.

If it’s an arm of some sorts, you can use a limit switch. A limit switch is a very simple sensor that gives off a signal when a small lever is touched. One came in the kit of parts. You could tell your motor to stop running when the arm or whatever is attached to it rotated 180 degrees.

Of course, the simplest and crudest way would be to set your motor to a certain speed, measure how long it takes to turn 180 degrees, then tell your motor to turn for that amount of time and stop.

Hope this helps.

it kinda helped but m confused how to do the coding

for it in operated controls. i am programing in java BTW