Forum

Lightsaber sensor priority

More
1 month 1 week ago #634 by lornetw
lornetw created the topic: Lightsaber sensor priority
Hi everyone.

I bought a developer board and a project board with the idea of making a lightsaber project with my students (following the Instructables article) because I am a teacher in a trade school for CNC machinists.

The question I wanted to ask the forum : I wanted to know if were possible to assign a priority to one button over another (i.e. if 2 buttons are activated at the same time). Example : let's say I'm waving the lightsaber around which would be activated by a "swing" sensor (therefore playing the "swing" sound), and the "clash" (collision) sensor is activated. Ideally, it would temporarily stop playing the "swing" sound, play the "clash" sound and then go back to playing the "swing" sound (if the "swing" sensor is still activated). Or, if 2 sensors are activated at around the same time, be able give one switch priority (the "clash" sensor) and give it override priority over any other sensor switch.

I would appreciate any ideas.

If I can get this to work, I will submit my project to the forum.

Have a nice day.

Please Log in or Create an account to join the conversation.

More
1 month 1 week ago #635 by foxonix
foxonix replied the topic: Lightsaber sensor priority
Hey lornetw:

There are a couple things you can do in the program to get the kind of response you're looking for. To make the clash sound effect the priority, you will want to lock out all the other inputs once the clash input is triggered. To see how this is done you can look at the sample program at this link:
foxonix.com/learn/sample-programs/99-simple-sfx-trigger

In this sample program, you'll see that the button connected to pin P1.0 is interruptible. That is, it can be pressed repeatedly, and each time it is pressed it will interrupt the current audio and cause the sound effect to be played from the beginning. In this same program, you'll also see that the button connected to pin 1.1 is NOT interruptible. That is, when this button is pressed, the sound effect must play all the way through to the end before this button can be triggered again. This is accomplished by setting different input states; one input state is called "enabled" and the other input state is called "locked_out." When the button connected to P1.1 is pressed, the button2: label is called. The first this that happens in this program path is that the locked_out input state gets set. This means all of the buttons are ignored. Then the sound effect plays. After the sound effect is done playing, the enabled input state gets set so that all the buttons become active again.

You will want to do something similar in the lightsaber program. When the clash sensor is triggered, the clash: label is called. Right after this label, you can lock out all of the inputs to guarantee that the clash sound effect does not get interrupted. Then when the clash sound effect is done playing, you can re-enable the inputs. In the case of the lightsaber program, it looks like you would want to set the "active" input state after the clash sound effect.

To see if the swing sensor is still active, you can read the state of the input port, which is described here:
foxonix.com/learn/programming-reference/...-on-input-port-value

In the lightsaber program, you would read the state of the swing switch and if it's active you would jump to the swing: label. The code for that might looks something like this:
& P1?[0 0 1 0]:swing

Give this a try and let us know how it works.

- Will @ foxonix

Foxonix - make your ideas heard.
@foxonixdev

Please Log in or Create an account to join the conversation.

More
1 month 1 week ago #636 by lornetw
lornetw replied the topic: Lightsaber sensor priority
Thanks very much for your response. I'll give your suggestions a try and I'll let you know how it goes.

Lorne Wilkins

Please Log in or Create an account to join the conversation.

Time to create page: 0.201 seconds