Simultaneously flashing LEDs

14 Sep 2012

Hi, I just bought my mbed a few days ago and would like to know all the basics as I am just starting to learn how to use it... I would also like to know how you can get all four LEDs flash after one another like at the end of this video https://www.youtube.com/watch?v=7LPDRcahhUE&feature=player_embedded

Someone help! Thankyou!

14 Sep 2012

Hi Robert,

You can try something like:

#include "mbed.h"

BusOut leds(LED1, LED2, LED3, LED4);

int main() {
    int i = 0;
    while(1) {
        wait(0.1);
        leds = 1 << (i++ % 4);
    }
}

Cheers, Sam

14 Sep 2012

Have you got a file to "import" onto the mbed? Or could you talk me through how to code this onto it, only a beginner you see haha!

Cheers, Rob

14 Sep 2012

Or has anyone got a code that will make the leds go back and forth like a "night rider" effect?

Thankyou!

14 Sep 2012

I would first have a look at the getting started articles, specifically: http://mbed.org/handbook/Creating-a-program

14 Sep 2012

Already done this, I have created a code for the "Knight rider" effect nicely. Feel free to use it!

/media/uploads/labmanrscott/knightriderled_lpc1768.v1.bin

24 Sep 2013

could you post the code to the knight rider effect please?

24 Sep 2013

I'm trying to learn how to make more then one flash on the mbed can anyone point me in the right direction I just don't know where to look for writing code or do it right this is frustrating

  1. include "mbed.h"

DigitalOut myled(LED1);(LED2);

int main() { while(1) { myled = 1; wait(0.2); myled = 0; wait(0.2); } }

24 Sep 2013

Hi Shawn,

Welcome to mbed...

a simple program like this should do it. You need to create a DigitalOut object for each LED you want to use.

#include "mbed.h"

DigitalOut myled1(LED1), myled2(LED2);

int main() { 
    while(1) { 
        myled1 = 1; 
        myled2 = 1;
        wait(0.2); 
        myled1 = 0; 
        myled2 = 0;
        wait(0.2); 
    }
}

There are several different ways you could code this BTW.

Regards Martin

24 Sep 2013

Hi Shawn,

Here is an example of a knightrider type display using the PWMs to achieve a fading effect.

https://mbed.org/users/wim/code/mbed_kitt/

25 Sep 2013

Thanks guys, I have the m3pi and I've been looking through the codes for getting it to go but I haven't found what I could go off of for the right commands and how to write the code for just learning the right programming to move the motors, then line reading, what I'm trying to say is like a chart I could follow or something for a new beginner of making and learning and writing my own codes for this bot. I've seen others but looking at what others have done doesn't teach me how to make my own and see little bits as I go. Also (whew) is there a way to have the LEDS on the mbed do the knight rider effect as the m3pi is moving around, for example I've seen code that moves just the motors the HELLO world program, and I've also seen the code for the knight rider LEDS how could I bring these two to work together? sorry I just feel dumb when trying to do something and cant get it to work :(

26 Sep 2013

I've seen code that moves just the motors the HELLO world program, and I've also seen the code for the knight rider LEDS how could I bring these two to work together? How would that code be written?

26 Sep 2013

Basically computers can do only one thing at a time. However, since they are so fast it may look like a computer does many things at the same time where in fact it gives its attention sequentially to all tasks at hand. You can write the code for that behaviour yourself by using an eternal loop that sequentially and briefly checks all tasks and takes action. You can also use timers that trigger tasks at regular intervals. Another option is to use external interrupts that activate the cpu when needed, eg when pressing at button. Switching between many tasks can also be done through an operating system like RTOS which is supported by mbed. In addition you get help from all kinds of hardware on the chip that reduces cpu load. The PWM hardware for example only needs to be set once and will then generate the control signal for a motor running at a certain speed. You dont need to touch it again until you want to set another speed.

26 Sep 2013

okay is there a place on the site here that would show me code to learn how to right things to the m3pi to learn in steps for someone like me that doesn't know how to write code? Such as command and how to write them?

01 Oct 2013

anyone want to buy a m3pi I give up on this

02 Oct 2013

You give up after about 8 days? How much programming experience do you have? Maybe you are try to do something that is a bit above your abilities which might be causing you unneeded frustration?

Perhaps you should pick a simpler project to learn from?