Question: Working with PinDetect function ...

13 Apr 2011

Dear all ...

I´m working in a security system for a machine. I need to use two buttoms which can stop the device as soon as posible, independently of the process in progress. I´ve been working with the "PinDetect" library (http://mbed.org/users/AjK/libraries/PinDetect/lkyxpw) succesfully but only with one buttom. Can the proper instructions be used simultaneosly with other buttom connected in other pin?? How could this be done??

Thank you very much in advance.

PD: Anyway, really nice work with this library.

13 Apr 2011

Sure, you can use PinDetect on any number of pins. Can you post some of your code and where you are having difficulties and I wil try and elaborate.

13 Apr 2011

Of course Andy ... The programme core is the following:

  1. include "mbed.h"
  2. include "PinDetect.h"

PinDetect pin (p5); PinDetect pin_2 (p10);

DigitalOut led1( LED1 ); DigitalOut led2( LED2 ); DigitalOut led3( LED3 );

void keyPressed( void ) { led2 = 1; Stop(); }

void keyReleased( void ) { led2 = 0; }

void keyPressed_2( void ) { led3 = 1; Stop(); }

void keyReleased_2( void ) { led3 = 0; }

int main() {

pin.mode( PullDown ); pin.attach_asserted( &keyPressed ); pin.attach_deasserted( &keyReleased );

pin.setSampleFrequency(); Defaults to 20ms.

pin.mode( PullDown ); pin.attach_asserted( &keyPressed_2 ); pin.attach_deasserted( &keyReleased_2 );

pin.setSampleFrequency(); Defaults to 20ms.

while( 1 ) { led1 = !led1; mean_S1 = 3.3*Sensor_3.read(); wait( 0.2 ); } }

13 Apr 2011

Try to wrap you code in <<code>> ... <</code>> to make it a bit eaiser to read.

The first thing I see is :-

    pin.mode( PullDown ); 
    pin.attach_asserted( &keyPressed ); 
    pin.attach_deasserted( &keyReleased );
    pin.setSampleFrequency(); // Defaults to 20ms.

    pin.mode( PullDown ); 
    pin.attach_asserted( &keyPressed_2 ); 
    pin.attach_deasserted( &keyReleased_2 );
    pin.setSampleFrequency(); // Defaults to 20ms.

Shouldn't that be?:-

    pin.mode( PullDown ); 
    pin.attach_asserted( &keyPressed ); 
    pin.attach_deasserted( &keyReleased );
    pin.setSampleFrequency(); // Defaults to 20ms.

    pin_2.mode( PullDown ); 
    pin_2.attach_asserted( &keyPressed_2 ); 
    pin_2.attach_deasserted( &keyReleased_2 );
    pin_2.setSampleFrequency(); // Defaults to 20ms.
13 Apr 2011

It works!! Great Andy ... Thank you very much. And again ... really nice library :)

04 Dec 2013

-I am working on a 5x5x5 3D LED Cube on The LPC1768 Board . In my cube structure I have 5 interrupts set using 5 external push buttons . -The Input Voltage to one end of the push button is coming from the LPC1768 Vout Pin whereas the other end is connected to p5 upto p9 . -4 of those push buttons are used to display a certain pattern while the 5th Push Button is used to rotate the current pattern under display by 90° . -So In the main function I am polling a certain number of "if" conditions and if they returns true a function is called , now these functions are set using the InterruptIn type , but the problem is that sometimes (30%) the button functionality works just fine but on most occasions it fails to detect that an Interrupt has occurred . -How can I incorporate the code given here into my own code as to alleviate my problem ,

Regards, IK

15 Mar 2014

if your buttons are both doing the same thing, (interlock) why not save a pin and program memory/clk cycles and wire the buttons in series. ?