Pin functions

26 Oct 2010

Is it possible for a pin to be able to assigned to interruptin and digitalin fuctions together? It compiles but will it affect it in any way? Also is there any way I can disable the interrupt?

I have an IR detector (TSOP1738) attached to pin number 21. Idea is that it will generate an interrupt on reception of the command and then using the digitalIn api I will be able to read the rest of the command bits.

26 Oct 2010

You can assign both DigitalIn and InterruptIn on the same pin, yes.

I use this as buttons software debounce.

Lerche

26 Oct 2010

Christian, Can you give an example of how you would debounce a switch using this method? I'm looking to do some work with switches and am looking for ways of debouncing

p.s. sorry if this is a bit off topic!

26 Oct 2010

Of course:

InterruptIn but(p5);
DigitalIn button1(p5);

void button() {
    wait(0.001);
    if (button1==1) {
        wait(0.001);
        if (button1==1) {
            // Do something
        }
    }
}

int main () {
    but.mode(PullUp);
    but.rise(&button);
}


That's the easy way I think.
Maybe you have to adjust the timing a little :-)

Lerche

26 Oct 2010

Hi,

You can always read the value of an InterruptIn pin, so no need for the additional DigitalIn object:

Simon

26 Oct 2010

Great, that's new to me!

Thanks Simon.

Lerche

26 Oct 2010

Thanks for that, it works great. But what is the purpose of the second nested if statement on line 8?

26 Oct 2010

It's just to make sure that the input hasn't changed.
Double-checking the input if you will ;-)

Lerche

26 Oct 2010 . Edited: 26 Oct 2010

Thanks,

Just 1 more question...

I am using pull down resitors on the switch, does the interrupt.mode mean these are not needed (i.e. switch.mode(PullDown))

Martin

26 Oct 2010

Hi Martin,

That is my fault. I seem to have not documented it. It is just the same as DigitalIn i.e. just assign something using =, or call .read().

Simon

26 Oct 2010

You are correct, the pullup/pulldown mode selects wether you would like a pullup or pulldown resistor internal in the LPC1768.

I don't see the read function in the class either, but I think i should be something like: i = switch.read();

Just like if you would read the DigitalIn.

Lerche

26 Oct 2010 . Edited: 27 Oct 2010

I created the following extnsion to DigitalIn to add simple deboucing of an input if anyones interested.

DebounceIn

27 Oct 2010

Great discussion and yeah, clears every Question I had. Many thanks. Loving my mbed.

27 Oct 2010

Great discussion and yeah, clears every Question I had. Many thanks. Loving my mbed.

27 Oct 2010

Great discussion and yeah, clears every Question I had. Many thanks. Loving my mbed.

27 Oct 2010

I think we get the point ;-)

Lerche

27 Oct 2010

Whoops, Sorry, I think the mouse buttons need a little debouncing themselves!!

27 Oct 2010

Now that's funny! :P

27 Oct 2010

Hello Guys ,

I am a new mbed's user.I am try to buy a new encoder(cyntron RE08A) in order to control a servo. The problem its output is 5.0V(sin). Do you know if this encoder is worth to buy?I saw people that only use between 0-3.3V (is there any risk that I will fry the mbed)?

27 Oct 2010

Hi Josue.

This is quite off topic, so why not start a new one?

Lerche