array problem

Thread Starter

namratha_r

Joined Jan 27, 2015
23
Code:
unsigned int array[] ={1,2,3,4,5,6,7,8,9,10}
.
.
.
for(i=0; i<10; i+)
{
     led = 1                      // led on
     delay(1);                 / /array num 1
     led = 0                    // led off
     delay(2);               // array num 2
}
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..
 

MrChips

Joined Oct 2, 2009
34,829
Before writing code, define what you want to do.
Draw a flow chart or use pseudo-code.
Make sure it makes sense.
 

Art

Joined Sep 10, 2007
806
The intention is roughly there.

Code:
int i
unsigned int array[] ={1,2,3,4,5,6,7,8,9,10}


for(i=0; i<9; i+)
{
     led = 1                      // led on
     delay(array[i]);                 / /array num 1
     led = 0                    // led off
     delay(array[i]);               // array num 2
}
 

Art

Joined Sep 10, 2007
806
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:
int i
unsigned int array[] ={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}

index = 0;
for(i=0; i<19; i+) {
     led = led + 1;                     // led on
     delay(array[i]);                 //array num 1
}
 
Top