for loop - Can I send simultaneous (instead of sequential) Arduino outputs? -


i have 8 leds i'm fading in , out arduino. i'm controlling each individually following code.

  for(int fade1=0;fade1<=255;fade1+=1){    analogwrite(8,fade1);     delay(10);   }   for(int fade1=255;fade1>=0;fade1-=1){     analogwrite(8,fade1);     delay(10);   } 

i want able assign separate fade time , delay each of 8 separate pins, 8 lights fading in , out simultaneously, , loop infinitely. however, can them kick off sequentially program.

i've been playing different placement of loops, loops within loops, etc., can't seem make want. ideas or examples can refer me?

instead of having 16 loops, reduce them two:

  for(int fade1=0;fade1<=255;fade1+=1){    analogwrite(8,fade1);    analogwrite(9,fade1);     // etc.    delay(10);   }   for(int fade1=255;fade1>=0;fade1-=1){     analogwrite(8,fade1);     analogwrite(9,fade1);     // etc.     delay(10);   } 

you won't able observe difference in time when port 8 written when port 9 written. code cause leds fade in , out simultaneously, might want them fade individually?

in case need set fade value each led separately, define vector of fade values, initial values:

  int fade[8] = {2, 0, 4,200,20,47,45,150};   int dir[8]  = {1,-1, 1, -1, 1,-1, 1, -1};    loop() {       (i = 0; < 8, i++)       {          if ((fade[i] <= 0) || (fade[i] >= 255))          {             dir[i] *= -1;          } else            fade[i] += dir[i];          }          // + 8 leds @ ports 8 thru 15          analogwrite(i+8, fade[i]);       }       delay(10);     } 

caution, haven't tried code start on leds appearing run independently of each other.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -