Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
Hi Guys,
I've used the PinDetect (and InterruptIn) lib to attach 14 key's to debounce, and even though the MBED compiler accepts this setup; It hangs during runtime. If i fiddle with setSampleFrequency en SampleCounts, it sort of works. But if i set all setSampleFrequency to 20.... the MBED dies @ runtime.
Is there a limit to how many Interrups i can setup? Or is it related to some limit in the MBED?
I just want to be able to read 14 Digital (debounced) inputs, and transmit a change event (key up and key down) using UDP.... How hard can that be???
Snifff.... and i was so close to get my mbed project working.
Theo :)
#include "mbed.h" #include "PinDetect.h" #define ON 1 #define OFF 0 long LoopCount = 0, PollCount = 0; PinDetect buttonA1(p11); PinDetect buttonA2(p12); PinDetect buttonA3(p13); PinDetect buttonA4(p14); PinDetect buttonB1(p15); PinDetect buttonB2(p16); PinDetect buttonB3(p17); PinDetect buttonB4(p18); PinDetect buttonC1(p21); PinDetect buttonC2(p22); PinDetect buttonC3(p23); PinDetect buttonC4(p24); PinDetect buttonD1(p19); PinDetect buttonD2(p20); DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); Serial lcd(p9, p10); // tx, rx Serial usbUART ( USBTX, USBRX ); void keyPressedA1( void ) { usbUART.printf("F");lcd.printf("F");} void keyPressedA2( void ) { usbUART.printf("G");lcd.printf("G");} void keyPressedA3( void ) { usbUART.printf("H");lcd.printf("H");} void keyPressedA4( void ) { usbUART.printf("I");lcd.printf("I");} void keyPressedB1( void ) { usbUART.printf("A");lcd.printf("A");} void keyPressedB2( void ) { usbUART.printf("B");lcd.printf("B");} void keyPressedB3( void ) { usbUART.printf("C");lcd.printf("C");} void keyPressedB4( void ) { usbUART.printf("D");lcd.printf("D");} void keyReleasedB1( void ) { usbUART.printf("a");lcd.printf("a");} void keyReleasedB2( void ) { usbUART.printf("b");lcd.printf("b");} void keyReleasedB3( void ) { usbUART.printf("c");lcd.printf("c");} void keyReleasedB4( void ) { usbUART.printf("d");lcd.printf("d");} void keyPressedC1( void ) { usbUART.printf("L");lcd.printf("L");} void keyPressedC2( void ) { usbUART.printf("M");lcd.printf("M");} void keyPressedC3( void ) { usbUART.printf("N");lcd.printf("O");} void keyPressedC4( void ) { usbUART.printf("K");lcd.printf("P");} void keyPressedD1( void ) { usbUART.printf("Q");lcd.printf("Q");} void keyPressedD2( void ) { usbUART.printf("P");lcd.printf("R");} void InitButtons(void) { //Examples //button30.mode( PullDown ); //Button is attached to Vin //button30.attach_asserted( &keyPressed30 ); //Key pressed //button30.attach_deasserted( &keyReleased30 ); //Key released //button30.setSampleFrequency(); // Defaults to 20ms, starts the actual sampling //button30.setSamplesTillAssert( 10 ); // This would mean 10 * 20ms debounce time = 200ms. //button30.setSamplesTillHeld( 200 ); // This would mean 200 * 20ms debounce time = 2seconds. //button30.attach_asserted_held( &keyPressedHeld ); //button30.attach_deasserted_held( &keyReleasedHeld ); led1 = ON; wait(0.5); buttonA1.mode(PullDown); //Button is attached to Vin buttonA1.attach_asserted(&keyPressedA1); //Key pressed buttonA1.setSamplesTillAssert( 5 ); buttonA1.setSampleFrequency(55); //Starts the actual sampling buttonA2.mode(PullDown); //Button is attached to Vin buttonA2.attach_asserted(&keyPressedA2); //Key pressed buttonA2.setSamplesTillAssert( 5 ); buttonA2.setSampleFrequency(55); //Starts the actual sampling buttonA3.mode(PullDown); //Button is attached to Vin buttonA3.attach_asserted(&keyPressedA3); //Key pressed buttonA3.setSamplesTillAssert( 5 ); buttonA3.setSampleFrequency(55); //Starts the actual sampling buttonA4.mode(PullDown); //Button is attached to Vin buttonA4.attach_asserted(&keyPressedA4); //Key pressed buttonA4.setSamplesTillAssert( 5 ); buttonA4.setSampleFrequency(55); //Starts the actual sampling led2 = ON; wait(0.5); buttonB1.mode(PullDown); //Button is attached to Vin buttonB1.attach_asserted(&keyPressedB1); //Key pressed buttonB1.attach_deasserted(&keyReleasedB1); //Key released buttonB1.setSamplesTillAssert( 5 ); buttonB1.setSampleFrequency(55); //Starts the actual sampling buttonB2.mode(PullDown); //Button is attached to Vin buttonB2.attach_asserted(&keyPressedB2); //Key pressed buttonB2.attach_deasserted(&keyReleasedB2); //Key released buttonB2.setSamplesTillAssert( 5 ); buttonB2.setSampleFrequency(55); //Starts the actual sampling buttonB3.mode(PullDown); //Button is attached to Vin buttonB3.attach_asserted(&keyPressedB3); //Key pressed buttonB3.attach_deasserted(&keyReleasedB3); //Key released buttonB3.setSamplesTillAssert( 5 ); buttonB3.setSampleFrequency(55); //Starts the actual sampling buttonB4.mode(PullDown); //Button is attached to Vin buttonB4.attach_asserted(&keyPressedB4); //Key pressed buttonB4.attach_deasserted(&keyReleasedB4); //Key released buttonB4.setSamplesTillAssert( 5 ); buttonB4.setSampleFrequency(55); //Starts the actual sampling led3 = ON; wait(0.5); buttonC1.mode(PullDown); //Button is attached to Vin buttonC1.attach_asserted(&keyPressedC1); //Key pressed buttonC1.setSamplesTillAssert( 5 ); buttonC1.setSampleFrequency(55); //Starts the actual sampling buttonC2.mode(PullDown); //Button is attached to Vin buttonC2.attach_asserted(&keyPressedC2); //Key pressed buttonC2.setSamplesTillAssert( 5 ); buttonC2.setSampleFrequency(55); //Starts the actual sampling buttonC3.mode(PullDown); //Button is attached to Vin buttonC3.attach_asserted(&keyPressedC3); //Key pressed buttonC3.setSamplesTillAssert( 5 ); buttonC3.setSampleFrequency(55); //Starts the actual sampling buttonC4.mode(PullDown); //Button is attached to Vin buttonC4.attach_asserted(&keyPressedC4); //Key pressed buttonC4.setSamplesTillAssert( 5 ); buttonC4.setSampleFrequency(55); //Starts the actual sampling led4 = ON; wait(0.5); buttonD1.mode(PullDown); //Button is attached to Vin buttonD1.attach_asserted(&keyPressedD1); //Key pressed buttonD1.setSamplesTillAssert( 5 ); buttonD1.setSampleFrequency(55); //Starts the actual sampling buttonD2.mode(PullDown); //Button is attached to Vin buttonD2.attach_asserted(&keyPressedD2); //Key pressed buttonD2.setSamplesTillAssert( 5 ); buttonD2.setSampleFrequency(55); //Starts the actual sampling //Wait timers below stop working wait(0.5); led4 = OFF; wait(0.2); led3 = OFF; wait(0.2); led2 = OFF; wait(0.2); led1 = OFF; } int main() { lcd.baud(19200); usbUART.baud( 115200 ); usbUART.printf("UDP Tester starting...\r\n"); LoopCount = 0; PollCount = 0; InitButtons(); PollCount = 0; while (1) { PollCount ++; if ( PollCount % 25000 == 0 ) {led1 = !led1;} if ( PollCount % 50000 == 0 ) {led2 = !led2;} if ( PollCount % 75000 == 0 ) {led3 = !led3;} if ( PollCount % 100000 == 0 ) {led4 = !led4;} if ( PollCount % 1000000 == 0 ) { PollCount = 0; LoopCount ++; lcd.printf("LoopCount= %dM\n",LoopCount); } } }