|
Unlike the buttons, the wheels are analog controls that will have a value between 0 and 254, with 127 being the middle. Based on the fact that you are going to be controlling relays with them, you only need to know whether the wheel is greater than 127 or less than it. The following code will accomplish this:
relayX_fwd = p1_wheel / 127
relayX_rev = 1 - relayX_fwd
This works because of the way integer math rounds things off. (ie 200/127=1 and 50/127 = 0). The second line is there to make sure that the relay is either in forward or reverse, but not both. If you are using the big Festo single solenoid, you can (and should) get rid of the second line.
With this code, whenever the wheel is at or above the middle, the cylinder will go one way. When it is below, it will go the other. Let me know if you were looking for something different.
--Rob
|