View Full Version : Repeating sequence
ArmchairAce
14-05-2005, 11:09 AM
Please, Bob or some other expert :)
I need to start a sequence by pressing a button then I need to release the button and leave the sequence to cycle till I press the same button again to stop it
How? :)
The sequence is like this, basic one:
SEQUENCE
WAIT( JS1.B2 ); // Wait for the JS1 button to get pressed
CMS.B5 = TRUE; // Turn on the CMS button
DELAY( 10 ); // Wait about half a second
CMS.B5 = FALSE; // Turn off the CMS button
DELAY( 10 ); // Wait about half a second
CMS.B5 = TRUE; // Turn on the CMS button
DELAY( 10 ); // Wait about half a second
CMS.B5 = FALSE; // Turn off the CMS Button
ENDSEQUENCE
Thanks to any helper in advance :)
Bob Church
14-05-2005, 09:22 PM
Hi ArmchairAce,
That shouldn't be too hard. Set up a bit outside of the the sequence to toggle off and on on each click of the button, then put that into a WHILE statement. With a TOGGLE it should probably looke like this:
// Flip the state of D1 on each js1.b2 press
//
TOGGLE( D1 ) = JS1.B2;
// Then use D1 to control a WHILE rather than
// a WAIT in the SEQUENCE...
//
SEQUENCE
WHILE( D1 ); // While the Toggle is TRUE, run the sequence
CMS.B5 = TRUE; // Turn on the CMS button
DELAY( 10 ); // Wait about half a second
CMS.B5 = FALSE; // Turn off the CMS button
DELAY( 10 ); // Wait about half a second
CMS.B5 = TRUE; // Turn on the CMS button
DELAY( 10 ); // Wait about half a second
CMS.B5 = FALSE; // Turn off the CMS Button
ENDSEQUENCE
I haven't tested that, but I think it should do what you want.
Best regards,
- Bob
The StickWorks
http://www.stickworks.com
ArmchairAce
16-05-2005, 08:05 PM
Hi Bob,
I had D1 as other variable so I changed it for D3 and its working fine. The only problem is that when I switch the sequenc off I have to switch it in the last but one step because it does one last step after switching off...???
Bob Church
16-05-2005, 09:28 PM
Hi ArmchairAce,
It wouldn't run another sequence, but it will always finish on that's begun, and that will usually be the case. You could have it stop in the middle by using an IF/THEN block rather than the WHILE. It would run until it got to a DELAY statement, that would relinquish control while the delay ran, and when it came 'round the next time the IF wouldn't be satisfied so the whole block would get skipped. When the IF came TRUE again, the sequence would pick up where it left off. That could be a problem, too, if CMS.B5 was on since if it was on when the IF went FALSE it would stay on until the loop started up and finishied.
Another option would be to use D3 rather than TRUE:
TOGGLE( D3 ) = JS1.B2;
SEQUENCE
WHILE( D3 ); // While the Toggle is TRUE, run the sequence
CMS.B5 = D3; // Track D3
DELAY( 10 ); // Wait about half a second
CMS.B5 = FALSE; // Turn off the CMS button
DELAY( 10 ); // Wait about half a second
CMS.B5 = D3; // Track D3
DELAY( 10 ); // Wait about half a second
CMS.B5 = FALSE; // Turn off the CMS Button
ENDSEQUENCE
In the above, CMS.B5 doesn't go TRUE, it just goes to whatever state D3 is in. If D3 shuts off, the sequence will still complete but CMS.B5 will get a FALSE from D3 once the toggle is OFF and so won't turn on. That could leave you with an odd number of pulses, though. I'm not sure it matters, but you're doing it twice in the loop which looks like you want it to happen in pairs. Otherwise, you could lose the second bit of ON/OFF logic and that would make it shut off after the current pulse which would be basically the same thing as using D3 rather than TRUE. Like this:
TOGGLE( D3 ) = JS1.B2;
SEQUENCE
WHILE( D3 ); // While the Toggle is TRUE, run the sequence
CMS.B5 = TRUE; // Turn on the CMS button
DELAY( 10 ); // Wait about half a second
CMS.B5 = FALSE; // Turn off the CMS button
DELAY(10); // Wait about half a second
ENDSEQUENCE
Using D3 would still be a little more instantaneous, though, since if you stopped the above while it was on, it still would finish the current delay.
Anyway, those are basically the options. Maybe one of them will be more suitable.
Best regards,
- Bob
The StickWorks
http://www.stickworks.com
ArmchairAce
17-05-2005, 02:09 PM
Hi Bob,
Thank you very much, I think the D3 will help...yes I need it in pairs and when I want to shut the sequence down I need it to finish the last cycle no matter what state it is currently in...that´s what the D3 instead of TRUE should do, right?
However, I got one more challenge for you in this case :) When the sequence is running and I use another script for looking around with the 4way hat...the one you helped me with of course :)...the "viewing" script interferes with the sequence and turns it the other way round...where there was ON there is OFF and vice versa...
I guess maybe using the D3 instead of TRUE could help to fix this as well..?
Thanx alot for your amazing assistance! :)
Regards
AA.
Bob Church
17-05-2005, 10:26 PM
Hi ArmchairAce,
>> Thank you very much, I think the D3 will help...yes I need it in pairs and when I want to shut the sequence down I need it to finish the last cycle no matter what state it is currently in...that´s what the D3 instead of TRUE should do, right? <<
Well, I'm not sure what you're expecting. It's finishing the last sequence as you had it. Using D3 rather than TRUE will just force the outputs to not turn on and if one happens to be on at the time you hit the toggle, it will shut off right then. The sequence will go to the end, but CMS.B5 won't turn on again.
>> However, I got one more challenge for you in this case smile.gif When the sequence is running and I use another script for looking around with the 4way hat...the one you helped me with of course smile.gif...the "viewing" script interferes with the sequence and turns it the other way round...where there was ON there is OFF and vice versa...
I guess maybe using the D3 instead of TRUE could help to fix this as well..? <<
It's going to be hard to keep them synchronized, really. One side doesn't know what the other side is doing and neither of them can tell what the sim has done. You could probably work out a "state machine" setup and combine the two sequences, that could get rather complex though. It's probably not a lot of trouble to have one script disable the other, the view script could kill another bit that was "AND"ed with D3 for instance and so the view script would essentially shut down the second script. Is there a command you can send to force the sim back into a known state at the end? For instance, the view script could issue a "Look Forward" command at the end which would override whatever view position it might have gotten stuck in. I'm not sure what the second script does, but maybe there's some kind of command that could be added at the end of the sequence that would force it back to the "normal" state for that function, too.
Best regards,
- Bob
The StickWorks
http://www.stickworks.com
Thanx alot for your amazing assistance! smile.gif
Regards
vBulletin® v3.7.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.