Flex sensor control

Hello,

Have a Maestro 6ch hooked up to a flex sensor, servo & some leds. Want to have the leds off when sensor is straight and servo at position 1 then when bent leds on and servo position 2. Everything is great except for my leds which are backwards (on when straight off when bent). Button is on ch 1 servo on ch 0 and the leds on ch 5. Is there a way to reverse them in my code?

Thanks

[code] begin
2250 0 300 servo_range
9000 300 600 servo_range

repeat

sub servo_range
pot 2 pick less_than logical_not
pot 2 pick greater_than logical_not
logical_and
if
begin
pot 2 pick 10 minus less_than logical_not
pot 2 pick 10 plus greater_than logical_not
logical_and
while
2 pick 0 servo
2 pick 5 servo
repeat

endif
drop drop drop
return

sub pot
1 get_position
return[/code]

Hello.

The only place in the code where you are setting the LEDs is the line that contains “5 servo”. To invert the behavior of the LEDs, you could just replace “5 servo” with “12000 swap minus 5 servo”. This implements the formula “x = 12000 - x”, so any values above the threshold of 6000 would then be below it, and any values below 6000 would then be above it. I have not looked at your code carefully enough to know if this is the best way. I am also assuming that the case where x equals 6000 is not particularly important.

–David

DavidEGrayson you are the man my friend! It works perfect now! Thank You as soon as I get all done I will post a vid of what you helped me with!

Thanks again

Great! I am looking forward to that video. --David