2 years, 4 months ago.

How do I change the LED blinking pattern in Blinky?

How do I change the LED to blink for 2 long flashes and then a short flash and then a pause of 2 seconds? What is the C++ code? This is what I have so far:

  1. include "mbed.h"

DigitalOut led1(LED1);

main() runs in its own thread in the OS int main() { while (true) { led1 = !led1; wait(2); } }

1 Answer

2 years, 4 months ago.

Your code

#include "mbed.h"
DigitalOut led1(LED1);

main()
{
  while (true)
  {
    led1 = !led1;
    wait(2);
 }
}

What you wanted....

#include "mbed.h"
DigitalOut led1(LED1);

main()
{
  while (true)
  {
//First long flash
    led1 = 1;  //ON (assuming '1' = ON)
    wait(2);  //Long time (stay on for 2 seconds)
    led1 = 0; //Off
    wait(0.5);//Short time

//Second long flash
    led1 = 1;  //ON (assuming '1' = ON)
    wait(2);  //Long time
    led1 = 0; //Off
    wait(0.5);//Short time

//Short flash
    led1 = 1;  //ON (assuming '1' = ON)
    wait(0.5);  //Short time
    led1 = 0; //Off
    wait(0.5);//Short time

//Now wait 2 seconds
  wait(2);

 }
}

"What is the C++ code? " - hmmm....hope this C code above can help

Bill

Accepted Answer

Thank you, your answer worked.

posted by Henry James 26 May 2018

how can you print "goodbye" everytime LED turns off on your terminal window?

posted by moe alhawwari 28 May 2018