Forum

Using a Slide Switch as Flow Control

More
- #585 by ericleven
ericleven created the topic: Using a Slide Switch as Flow Control
I'd like to use a slide switch (or similar) to control the flow of an EZ Script program.

Using simple_SFX_trigger as an example, instead of using two buttons (one for interruptible sounds and one for non-interruptible), I'd like to use one button to trigger the sound, but use a slide switch to determine if it's interruptible or not. As I understand it, Foxonix needs inputs that rise from low to high, and I don't think a slide switch does this. Is what I'm trying to do possible with a Fox board alone?

The input_states portion of the code is still a bit of a mystery to me, so bear with me if this question is obvious...

-eric
Last Edit: by ericleven.

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

More
#587 by foxonix
foxonix replied the topic: Using a Slide Switch as Flow Control
Hi Eric:

Yes, you can absolutely use a switch to select between modes or input states. You would connect the switch to an input pin, and when a button is pressed you would read that switch to determine how to respond. We just updated the reference section to include these types of commands but (strangely) this one didn't make it in (we'll add it soon). The command looks like this: Pn?[x x x x]:label1

So if your switch was connected to Pin P2.2, your code would look like this:
& P2?[x 1 x x]:this_label
& P2?[x 0 x x]:that_label

One terminal of the switch should be connected to Vcc and the other terminal to the input pin. Basically, you're looking at that one pin and making a decision. The 'x' is used to ignore a pin that you don't want to include.

As for your other question, we tend to think of Foxonix using a low-to-high transition, but it can also trigger on a high-to-low transition, or both. Using the simple_SFX_trigger example that you mentioned, the "enabled" input state is set up so that the inputs will trigger on a low-to-high transition:
enabled:	button1  button2

If you want to change this so that button1 triggers on a high-to-low transition, then you put a "/" in front, like so:
enabled:	/button1  button2

If you want button1 to trigger on BOTH a low-to-high and a high-to-low transition, then you set it up like this:
enabled:	button1/button1  button2

Foxonix - make your ideas heard.
@foxonixdev
The following user(s) said Thank You: ericleven

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

More
#610 by ericleven
ericleven replied the topic: Using a Slide Switch as Flow Control
I think I'm missing a key part of the puzzle on this one; I can't seem to get it to work. In the absence of an actual switch, I'm running Vcc directly into the P1.1 input pin; that should be the same as a switch, right?

My code looks like this:
[input_states]
; PIN		P1.0 	1.1
lock_button:	x	x
enable_button:	button	x
with and normal [init] and the following paths:

button:
	& P1?[x 1 x x]:play1
	& P1?[x 0 x x]:play2
	
play1:
	& one.wav
	& end

play2:
	& two.wav
	& end

No matter what I do, the program only plays "2", never "1"; it doesn't ever read P1.1 as high.

I have a feeling the answer will make me feel silly...but I'm stumped!

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

More
#612 by foxonix
foxonix replied the topic: Using a Slide Switch as Flow Control
Hey, Eric:

Your code is pretty much right, but the bit you're trying to read is in the wrong location. When reading and writing ports, the standard notation is that the most significant bit (MSB) is on the left and the least significant bit (LSB) is on the right. This is true for Foxonix as well as Arduino and other microcontrollers. So the bits are ordered as [bit3 bit2 bit1 bit0].

If you're trying to read pin P1.1 (bit1 on port P1), then your code should be:

button:
	& P1?[x x 1 x]:play1
	& P1?[x x 0 x]:play2

There are some examples in the reference section. Let us know if this fixes the problem.

Foxonix - make your ideas heard.
@foxonixdev

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

More
#614 by ericleven
ericleven replied the topic: Using a Slide Switch as Flow Control
Ha! Well, I do feel silly. But I think that having the LSB on the right when reading ports, but having it on the left when declaring input states is also silly. :)

As always, thanks for the info!

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

Time to create page: 0.023 seconds