How to fix the " 'i' was not declared in this scope" error


hello,

i'm beginner arduino , i'm having trouble code.

i've got 5 different functions control lights on led strips, , i've got code on processing (another program) plays 1 of 2 audio tracks when keys 'h' or 'r' pressed. processing code returns numbers 1 , 2 respectively when either of these tracks played.

i used inbuilt library named serial connect both these pieces of code, , i'm trying set color of led strips in arduino code red or green depending on whether receive '1' or '2' processing. keep getting error below: 'i' not declared in scope.
 
i'm not sure i'm meant define 'i' in code below error stop.

code: [select]


#include <adafruit_neopixel.h>
#ifdef __avr__
  #include <avr/power.h>
#endif

#define pin 6

adafruit_neopixel strip = adafruit_neopixel(18, pin, neo_grb + neo_khz800);

int setting = 0;
char val; // data received fromt serial port

void setup() {
  serial.begin(9600); // starts serial communication @ 9600 bps
  strip.begin();
  strip.show(); // initialize pixels 'off'
}

void loop() {

  if (serial.available()) // 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);
   }
   else if (val == '2') // if 2 received
   {
     strip.setpixelcolor(i, 15, 224, 67);
   }
    }
   
  simpletest(false, 100);
  contrarychase(false,100);
  littlechase(false,150);
  basicfade(false,10,strip.numpixels(),0);
  rollingfade(false, 10, strip.numpixels());
}
 
}

void simpletest(boolean on, int spd){

  while(on){
   
      (int = 0; <= strip.numpixels(); i++){
   
      strip.setpixelcolor(i,255,0, 0);
      strip.setpixelcolor(i-1, 0, 0, 0);
      strip.show();
      delay(spd);
   
      }
  }
}//end simpletest

void contrarychase(boolean on, int spd){

  while(on){
   
      (int = 0; <= strip.numpixels(); i++){
   
      strip.setpixelcolor(i, random(255),200+random(55),255);
      strip.setpixelcolor(i-1, 0, 0, 0);
      strip.setpixelcolor(strip.numpixels()-i, 255,255,255);
      strip.setpixelcolor(strip.numpixels()-i+1, 0, 0, 0);
      strip.show();
      delay(spd);
   
      }
  }
}//end contrarychase

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,level,level,level);
         
              }//end for
   
              strip.show();
              delay(spd);
   
              if (level < 255) level++;
              else dir = 1;
   
              break;
   
        case 1:
              (int = begpix; <= numpix+begpix; i++){
   
                strip.setpixelcolor(i,level,level,level);
         
              }//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
}


void littlechase(boolean on, int spd){

  (int = 0; i<13; i++){
    if(i<7){
      strip.setpixelcolor(i,255,255,255);
      strip.setpixelcolor(i+6,255,255,255);
      strip.setpixelcolor(i+12,255,255,255);
      strip.show();
      delay(spd);
      strip.setpixelcolor(i,0,0,0);
      strip.setpixelcolor(i+6,0,0,0);
      strip.setpixelcolor(i+12,0,0,0);
      strip.show();
    }
     else{
      strip.setpixelcolor(13-i,255,255,255);
      strip.setpixelcolor(13-i+6,255,255,255);
      strip.setpixelcolor(13-i+12,255,255,255);
      strip.show();
      delay(spd);
      strip.setpixelcolor(13-i,0,0,0);
      strip.setpixelcolor(13-i+6,0,0,0);
      strip.setpixelcolor(13-i+12,0,0,0);
      strip.show();
     
     }
     
  }
}
 
   
   



1.) use while loop instead of loop. this:

code: [select]

int = 0;

while(i < argument)
{
   //do stuff

   i++;
}



2.) add "return;" commands end of every function make (except setup() , loop()).

3.) rid of bracket on line 46


Arduino Forum > Using Arduino > Programming Questions > How to fix the " 'i' was not declared in this scope" error


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