Lighting an LED on/off every second for 10 seconds

Hi. I’m trying to write a code to get a particular LED on the mbed lpc368, flashing on/off every second for 10 seconds. Any help would be greatly appreciated.

Hello.

I do not know what is the lpc368 - Development boards | Mbed

What did you tried, where did you stuck?
Anyway, from my point of view, the solution depends on the context of use in the context of whole program.

BR, Jan

Sorry about that, I made a mistake in the name. I do have another question if you don’t mind sorry. I want to run two sets of programs run forever in the same code I.e I want my compiler to run the first program and then run the second one too… Both of them forever. How do I go about this. I tried using while 1 loop but the compiler isn’t reaching the last code for the second program

  • The compiler does not run anything, the compiler translates the code you write into an understandable format for the MCU.
  • Let’s say a program = one .bin file and a MCU can not execute more then one program at time. So you probably mean some Tasks.

Of course it not reach the last code. The code is executed line by line but while loop change the game. The code below the while is unreachable because the while loop above is infinite.

while(1){
  // do something magic in loop
  led1 = !led1;
  thread_sleep_for(500);
}
// do something magic after loop
led2 =!led2; // wrong, unreachable

So you need to break the while loop before it will continue.

while(1){
  // do something magic in loop
  led1 = !led1;
  thread_sleep_for(500);
  if(buttonPressed) break; // it will break the while loop after the button will be pressed
}
// do something magic after loop
led2 =!led2; // it will be executed after the button will be pressed

If you want to execute more tasks then it depends on what are your requirements. But you can use threads - Thread - API references and tutorials | Mbed OS 6 Documentation look at the samples at the bottom of the page.

BR, Jan

OK I have to implement the program in the picture attached to this email. I used a bunch of while ifs for the first part and it worked fine but for the second part, the code only runs for the very first section of the truth table. I used a bunch of if statements for the truth table. How would you go about this please?