loop and LEDs

Discussion in 'Embedded Systems and Microcontrollers' started by Eric007, Aug 21, 2011.

  1. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    Hi all!

    I just wana know if it is possible to run 2 loops at the same time?:D

    Also, assume you want 2 LEDs to flash at the same time BUT with different frequencies...
    example: LED1 every 1 second and LED2 every 2 second.

    Here's the algorithm i came up with:

    loop

    LED1 on
    LED2 on
    delay 0.5 second
    LED1 off
    delay 0.5 second
    LED2 off
    LED1 on
    delay 0.5 second
    LED1 off
    delay 0.5 second
    goto loop


    Does it make any sense? this is just an algorithm...no need to write proper codes....

    Your replies will be welcome,
     
    Last edited: Aug 21, 2011
  2. praondevou

    AAC Fanatic!

    Jul 9, 2011
    2,936
    488
    2 or more if you want. :cool:
    [​IMG]
     
  3. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    @ praondevou: this is a serious question although im laughing...
    should i be more explicit?
     
  4. praondevou

    AAC Fanatic!

    Jul 9, 2011
    2,936
    488
    Well, you modified your initial post after I posted. Your initial post didn't contain any information someone could respond to.;)

    Now it's clearer I guess.
     
  5. praondevou

    AAC Fanatic!

    Jul 9, 2011
    2,936
    488

    What language are u using? You can do it like this, however unless you use interrupts to get out off the 0.5 second delays, the MC won't do anything else during this time, just waiting, right? Makes only sense if the MC is supposed to do ONLY this.
     
  6. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    Thanx for ur reply...i'm using assembly language and PIC16F690
     
  7. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    Oh to your other question, YES the microcontroller will only do this BUT that will be controlled by one pushbutton.
     
  8. srikanthsamaga

    Member

    Jul 1, 2008
    13
    1
    You can also try using two timers with interrupt.
     
  9. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186
    Yes,use two timers to do that.I think at least two timers are avaliable in PIC16F690 anyway check the datasheet.

    Good luck
     
  10. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    Also if the timing isn´t critical, you could use a 556 to control both LEDs.
     
  11. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,387
    1,605
    Your simple simple algorithm (hey, you can call that pseudo code ya know;)) would work.

    There is no real need to start doing interrupts or using the timers unless you require very accurate times. Depending on how fast you want the button to work (meaning if you want the button the LEDs light as soon as you hit the switch, and as soon as you release the switch the LEDs go dark) you can just check that switch inside any delay routine you write.

    Break it down in steps:
    first get LEDs to light,
    then get them to light in the delay pattern,
    then add the button to turn it all on and off.

    Makes for less craziness when you debug your code in simple stages.
     
Loading...