how to control two event instantaneously...may be without interruputs

Discussion in 'Embedded Systems and Microcontrollers' started by nepdeep, Mar 27, 2013.

  1. nepdeep

    Thread Starter Active Member

    Sep 14, 2011
    Okey this is, for me , bit tricky even to ask the question:

    firstly, I am using arduino to blink the led....
    it blinks LED in certain pattern so there has to delay between certain patterns of blink in the program....

    no problem... i thought of adding a small tweak ...

    add another led and control the brightness according to the ADC value obtained on on of the pins....

    okey....I did implement this...but what i noticed is ....the led controlled by ADC input too some time to respond....which of course is because of the delay....
    Hey people how can i solve the ADC instantly...and also blink the led

    I thought about using interrupts....but just a thought...any other clever solutions ???

  2. tshuck

    Well-Known Member

    Oct 18, 2012
    First off, there is no such thing add instantaneous while referring to a physical system. Reading the analog value takes time, albeit a much sorter amount of time than you can perceive.

    Second, and to the point, you can use interrupts, but it just sounds like you are being very inefficient in your code. you could, for instance, continuously sample your ADC, put that into memory, and use that add your delay. You can use timers, or terror the program for a certain time. Your processor is spending probably ~98% of its time in a delay. Rearrange your code and you can do this without interrupts. Once you are well versed inhow it works, interrupts are a good tool to learn about and use...
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    The basic problem is your blink timer is blocking your dimmer. So break up the timer into smaller pieces.

    I dunno how fast you blink, but say for example you blink on a sec, off for 5 secs. Instead of setting up delays of 1 second and 5 seconds, set up a delay for 0.1 second (or faster!) and then count 10 of those for 1 second, or 50 for 5 seconds. So the blink stays the same to the outside world.

    Now having a set fast pulse of 0.1 sec allows you to read the A2D at the fast rate and adjust the dimmer without a long delay.

    There's lots of ways to do this. That's a simple way that works I suggest as I believe as soon as you get that to work you'll be adding some other task into the mix.
  4. nepdeep

    Thread Starter Active Member

    Sep 14, 2011

    Wow this seems clever. I have an idea in my head now but thinking the way to implement it. Thank you for your help