Code in my for loop isn't running. (Uses Serial to connect Arduino & Processing)


hello!

so i'm trying use processing , arduino managing flow of data serial.
the code below supposed led strip turn red , carry out 'basicfade' when number '1' received, , turn green , carry out 'rollingfade' if number '2' received. of now, led's turn green, , not red, , first function carry out stays same though value of 'val' changes. there no errors. ideas i'm going wrong?

note: i've edited out lot of other code keep things simple, if needed, can post of it.

thanks in advance!

code: [select]


void loop() {

  if (serial.available() > 0) { // if data available read,
     val = serial.read(); // read , store in val   
     for (int = 0; <= strip.numpixels(); i++) {
      if (val == '1') { // if 1 received 
       strip.setpixelcolor(i, 255, 0, 0);
       basicfade(false,10,strip.numpixels(),0);
       rollingfade(true, 10, strip.numpixels());
     }
      if (val == '2') { // if 2 received
       strip.setpixelcolor(i, 15, 224, 67);
       basicfade(true,10,strip.numpixels(),0);
       rollingfade(false, 10, strip.numpixels());         
       }
      }
  }
 

void basicfade(boolean on, int spd, int numpix, int begpix){

  int level = 0;
  int dir = 0;

  while(on){

      switch(dir){
   
        case 0:
              (int = begpix; <= numpix+begpix; i++){
   
                strip.setpixelcolor(i, 15, 224, 67);
         
              }//end for
   
              strip.show();
              delay(spd);
   
              if (level < 255) level++;
              else dir = 1;
   
              break;
   
        case 1:
              (int = begpix; <= numpix+begpix; i++){
   
                strip.setpixelcolor(i, 15, 224, 67);
         
              }//end for
   
              strip.show();
              delay(spd);
   
              if (level > 0) level--;
              else dir = 0;
   
              break;
       
      }//end switch
   
  }//end big while

}// end basic fade

void rollingfade(boolean on, int spd, int numpix){

  int lvl1=0;
  int lvl2=0;
  int lvl3=0;
  int state = 0;

  while(on){
serial.println(state);
    switch(state){

      case 0:
              striputility(lvl1,lvl2,lvl3);   
              strip.show();
              delay(spd);
   
              if (lvl1 < 85) lvl1++;
              else state = 1;
   
              break;
   
        case 1:
              striputility(lvl1,lvl2,lvl3);
              strip.show();
              delay(spd);
   
              if (lvl1 < 170){
                lvl1++;
                lvl2++;
              }
              else state = 2;
   
              break;

        case 2:
              striputility(lvl1,lvl2,lvl3); 
              strip.show();
              delay(spd);
   
              if (lvl2 < 170 ){
                lvl1--;
                lvl2++;
                lvl3++;
              }
              else state = 3;
   
              break;

       case 3:
              striputility(lvl1,lvl2,lvl3);   
              strip.show();
              delay(spd);
   
              if (lvl3 < 170 ){
                lvl1--;
                lvl2--;
                lvl3++;
              }
              else state = 4;
   
              break;

        case 4:
              striputility(lvl1,lvl2,lvl3);
              strip.show();
              delay(spd);
   
              if (lvl1 > 0 ){
                lvl1--;
                lvl2--;
                lvl3--;
              }
              else state = 5;
   
              break;

        case 5:
              striputility(lvl1,lvl2,lvl3);
              strip.show();
              delay(spd);
   
              if (lvl2 > 0 ){
                lvl1++;
                lvl2--;
                lvl3--;
              }
              else state = 6;
   
              break;

       case 6:
              striputility(lvl1,lvl2,lvl3);
              strip.show();
              delay(spd);
   
              if (lvl3 > 0 ){
                lvl1++;
                lvl2++;
                lvl3--;
              }
              else state = 1;
   
              break;

         }//end switch   
  }//end big while 
}//end rollingfade

void striputility(int lvl1, int lvl2, int lvl3){
  (int = 0; <= 5; i++){
   
                strip.setpixelcolor(i,lvl1,lvl1,lvl1);
                strip.setpixelcolor(i+6,lvl2,lvl2,lvl2);
                strip.setpixelcolor(i+12,lvl3,lvl3,lvl3);
         
              }//end for
}


code: [select]
for (int = 0; <= strip.numpixels();
you said there no errors.


Arduino Forum > Using Arduino > Programming Questions > Code in my for loop isn't running. (Uses Serial to connect Arduino & Processing)


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor