1. namratha_r

    Thread Starter New Member

    Jan 27, 2015
    23
    0
    Code (Text):
    1. unsigned int array[] ={1,2,3,4,5,6,7,8,9,10}
    2. .
    3. .
    4. .
    5. for(i=0; i<10; i+)
    6. {
    7.      led = 1                      // led on
    8.      delay(1);                 / /array num 1
    9.      led = 0                    // led off
    10.      delay(2);               // array num 2
    11. }
    have struck in this... actually i want to control led on/off by giving delays initialized in array. It should take alternately i mean 1 for ON , 2 for OFF again 3 for ON ...... so how to minimize the code by using conditions have struck ... please help me out..
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,435
    3,360
    Before writing code, define what you want to do.
    Draw a flow chart or use pseudo-code.
    Make sure it makes sense.
     
  3. Art

    Distinguished Member

    Sep 10, 2007
    785
    61
    The intention is roughly there.

    Code (Text):
    1.  
    2.  
    3. int i
    4. unsigned int array[] ={1,2,3,4,5,6,7,8,9,10}
    5.  
    6.  
    7. for(i=0; i<9; i+)
    8. {
    9.      led = 1                      // led on
    10.      delay(array[i]);                 / /array num 1
    11.      led = 0                    // led off
    12.      delay(array[i]);               // array num 2
    13. }
    14.  
    15.  
     
  4. Art

    Distinguished Member

    Sep 10, 2007
    785
    61
    Ok I get it, your array wasn’t long enough for 10 flashes for two values for each on/off cycle
    This assumes led is a bit variable and cycles from 1 to 0 and back again as you increment it.

    Code (Text):
    1.  
    2. int i
    3. unsigned int array[] ={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}
    4.  
    5. index = 0;
    6. for(i=0; i<19; i+) {
    7.      led = led + 1;                     // led on
    8.      delay(array[i]);                 //array num 1
    9. }
    10.  
    11.  
     
  5. MrChips

    Moderator

    Oct 2, 2009
    12,435
    3,360
    You get it. I don't.
     
  6. namratha_r

    Thread Starter New Member

    Jan 27, 2015
    23
    0
    thanks ... I got it
     
Loading...