Seems simple, don't get it
Beavis3215
Posts: 229
in Propeller 1
void button_time() { set_directions(13,8,0b111111); int t = 20; while(1) { int advance = input(15); // advance shortens magnet off delay int retard = input(14); // retard lengthens magnet off delay if (retard == 1) { t = t + 1; pause(300); if (t > 64) // Don't allow t to exceed 63 { t = 64; } } if (advance == 1) { t = t - 1; pause(300); if (t < 1) // Keep t 0 or larger { t = 1; } } delay = t; // Pass delay to main function set_outputs(13,8,t); // Put t value on output lights } }
I'm trying to vary t between 0 and 63 using 2 pushbuttons, and displaying them on 6 leds. If I use
If (t > 63)
{
t = 63;
}
and
if (t < 0)
{
t = 0;
}
the program jumps off the deep end on zero, and on 63 goes back to 62 after a half second.
I really seems like this should work, but does not.
The main program in cog 0 uses delay as pause(delay);
button_time runs in another cog
I the present form of the code, I get 1 to 63.
Why are my results different than I expect?
What code should I use?
Comments
doesn't agree with the comment, essentially if "t" is zero, it is changed to 1.
In your wiring are pins 14 and 15 pulled to low, or are they floating?
Tom
using my code above 1 to 63 is all I can attain for now.
looks like it should work, but does not.
pins 14 and 15 are pulled low
This is the main program
You can also do this in one line:
-Phil
Don't think you can do that in C
-Phil
you could do:
in C, if statements are always break at first false it encounter
I'm not sure what the problem is with 63. It seems like that should work fine.