Yep. Note that the waveform doesn't change between the working example and 
the non-working example. The only difference in the code is in when the 
if-then statement triggers the motor: In the working example, it triggers 
off the button being toggled. In the non-working example, the if clause is 
set to false, so the motor should run always. (Yet doesn't run at all.)

To be sure this was the line that killed it, I've toggled that single line 
of code back and forth. When I start with:
if(button_.isChecked()) ...
...it works. But when I change that to
if(false) ...
...it won't run the motor.

I've swapped it back and forth repeatedly, making just that one change, to 
be sure that was the key.

One thought that occurred to me, is maybe keying it off the button forces 
it to only send the pwm command when the IOIO is plugged in. Since the 
if(false) triggers all the time, I can imagine that it's sending the 
command to the non-existent IOIO, when the program first runs (while it's 
being loaded from Eclipse) and then doesn't send the command again, when 
the android phone hosting the program is unplugged from the computer and 
then plugged into the IOIO.





On Thursday, September 25, 2014 10:58:01 AM UTC-7, Ytai wrote:
>
> Are you sure this is the waveform that the servo expects? Typical hobby 
> servos require a 50Hz PWM input, where the pulse width varies between 
> 1-2ms. See IOIOSimpleApp as an example.
>  On Sep 25, 2014 10:48 AM, "Sam Brown" <[email protected] <javascript:>> 
> wrote:
>
>> I started an IOIO app from the HelloIOIO sample, and converted the "turn 
>> the light on or off" button to a "send a PWM signal" button so it could 
>> drive a servomotor.
>>
>> With minimal changes, the code works beautifully: (Excerpt from void 
>> loop())
>>
>>             if (button_.isChecked()) {
>>                 pwm.setDutyCycle(0.5f); // Don't spin.
>>             } else {
>>                 pwm.setDutyCycle(1.0f); // Do spin.
>>             }
>>
>> But once I no longer key the pwm off the button, it fails. Making this 
>> trivial change, which I would expect to spin the motor always, prevents the 
>> motor from spinning ever:
>>
>>             if (false) {
>>                 pwm.setDutyCycle(0.5f); // Never reach here. Never stop.
>>             } else {
>>                 pwm.setDutyCycle(1.0f); // Always choose this. Always spin.
>>             }
>>
>> Can anyone point out what I'm missing?
>>
>> - - - - - - - - - - - - 
>>
>> Originally posted on StackOverflow, here 
>> <http://stackoverflow.com/questions/26032111/pwm-on-ioio-works-when-tied-to-a-button-fails-always-when-independent-of-button>
>> .
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "ioio-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at http://groups.google.com/group/ioio-users.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to