7 years, 5 months ago.

Can't turn on the LED

Hello,

I have 5 switch and I use the intrruptIn for each switch to turn on the LED on the board but when I use more the 3 IntrruptIn the led turn on only with 3 switch and the others no.

Can anyone tell me why I can't turn on the LED when I use more than 3 interruptIn ?

Thank You

Hi Faris,

Can you post your code here? :)

Regards,

Andrea, team mbed

posted by Andrea Corrado 15 Nov 2016

Hi andrea

here is my code,

  1. include "mbed.h"
  2. include <stdio.h> Serial rn42(D14,D15);

DigitalOut led(LED1);

InterruptIn laser1(A0); InterruptIn laser2(A1); InterruptIn laser3(A2); InterruptIn laser4(A3); InterruptIn laser5(A4);

char C=67; char B=66; char A=65;

int LASER1; int LASER2; int LASER3; int LASER4; int LASER5;

void allume_verrine() { LASER3 = laser1.read(); LASER3 = laser2.read(); LASER3 = laser3.read(); LASER4 = laser4.read(); LASER5 = laser5.read();

if (LASER1 == 1 || LASER2 == 1|| LASER3 == 1 || LASER4 == 1 || LASER5 == 1 ) { rn42.putc(B); led= 1 ; } }

void eteint_verrine() { LASER1 = laser1.read(); LASER2 = laser2.read(); LASER3 = laser3.read(); LASER4 = laser4.read(); LASER5 = laser5.read();

if ( LASER1 == 0 && LASER2 == 0 && LASER3 == 0 && LASER4 == 0 && LASER5 == 0) { rn42.putc(A); led= 0 ;

} }

int main() { rn42.baud(115200); led=0;

laser1.rise(&allume_verrine); laser2.rise(&allume_verrine); laser3.rise(&allume_verrine); laser4.rise(&allume_verrine); laser5.rise(&allume_verrine);

laser1.fall(&eteint_verrine); laser2.fall(&eteint_verrine); laser3.fall(&eteint_verrine); laser4.fall(&eteint_verrine); laser5.fall(&eteint_verrine);

while(1) {

} }

posted by Alexandre JAFFRE 15 Nov 2016

Please post code using <<code>> tags, that way the formatting is preserved. e.g.

<<code>>
#include <stdio.h>
Serial rn42(D14,D15);
DigitalOut led(LED1);

InterruptIn laser1(A0); 
<</code>>
posted by Andy A 15 Nov 2016

#include "mbed.h"
#include <stdio.h>
Serial rn42(D14,D15);

 
DigitalOut led(LED1);

InterruptIn laser_1(A0);
InterruptIn laser_2(A1);
InterruptIn laser_3(A2);
InterruptIn laser_4(A3);
InterruptIn laser_5(A4);

char B=66;
char A=65;

int LASER_1;
int LASER_2;
int LASER_3;
int LASER_4;
int LASER_5;

    
void allume_verrine()
{
    LASER_1 = laser_1.read();
    LASER_2 = laser_2.read();
    LASER_3 = laser_3.read();
    LASER_4 = laser_4.read();
    LASER_5 = laser_5.read();
    
    
    if (LASER_1 == 1 || LASER_2 == 1|| LASER_3 == 1 || LASER_4 == 1 || LASER_5 == 1 )
    {        
        rn42.putc(B);
        led= 1 ;
    }
}

/***************************************/   
void eteint_verrine()
{
    LASER_1 = laser_1.read();
    LASER_2 = laser_2.read();
    LASER_3 = laser_3.read();
    LASER_4 = laser_4.read();
    LASER_5 = laser_5.read();
    
    if ( LASER_1 == 0 && LASER_2 == 0 && LASER_3 == 0 && LASER_4 == 0 && LASER_5 == 0)
    {
    rn42.putc(A);
    led= 0 ;
    
    }
}


int main() 
{
    rn42.baud(115200);
    led=0; 
    
    
        laser_1.rise(&allume_verrine);
        laser_2.rise(&allume_verrine);
        laser_3.rise(&allume_verrine);
        laser_4.rise(&allume_verrine);
        laser_5.rise(&allume_verrine);
                 
        laser_1.fall(&eteint_verrine);  
        laser_2.fall(&eteint_verrine);
        laser_3.fall(&eteint_verrine);  
        laser_4.fall(&eteint_verrine);
        laser_5.fall(&eteint_verrine);  
        
     
     while(1)
    {
        
    }
}

posted by Alexandre JAFFRE 15 Nov 2016

1 Answer

7 years, 5 months ago.

STM devices can only use one InterruptIn per pin number, so if you have an InterruptIn on PA_0, you can also have one at PA_2, and PA_3, and PB_2, PD_5, etc, but you cannot have an InterruptIn on PB_0, or PC_0, etc. See the pinout for which actual ports/pins you are using. For the A0-A5's (which are Arduino names and not their actual name):

/media/uploads/adustm/nucleo_f334r8_arduino_left_2016_7_22.png

Accepted Answer

Hi Eric,

Thank you so much, it works now.

posted by Alexandre JAFFRE 15 Nov 2016