Only loops once when I send a command wirelessly.


i have arduino xbee receiver , i'm sending commands using hyperterminal run rgb leds. basically, press 'a' button on keyboard toggle through if statements.  problem is, want loop run continuously until press 'a' button again, runs loop once. when press 'a' again, runs next loop once, , forth. thought using state change run loop until state changed. suggestions? here's of code after void loop()
code: [select]
if (serial.available()){
  int characterread = serial.read();
 
  if (characterread == 'a') {
    state++; }
   
    if (state==14) {
      state=0;
    }
   
   
if (state==1) {
                                     //fadeinfadeout
   for (int i=0;i<31;i+=5) {
     for (int j=0;j<num_leds;j++) {
  bl.setpixel(j,i,0,0);
  bl.show();
  delay(5);}

}
 
  (int i=31;i>0;i-=5) {
     for (int j=0;j<num_leds;j++) {
  bl.setpixel(j,i,0,0);
  bl.show();
  delay(5);}
 
  }
  blank();
 
 
   
  }
  else if (state==2){
  for(int i=0;i<20;i++)                                                      // strobe effect
   strobe(30);
   blank();
  }else if (state==3){
   
 
    (int i=0;i<150;i++){
    bl.setpixel(random(0,num_leds),0,31,0);
    bl.show();
    delay(15);
    blank();}
bl.setrange(0,num_leds,bl.color(0,0,0));
  bl.show();
  }
else if (state==4){

   
  for(counter=0;counter < 5;counter++)                                      // color wipe effect
  {
    colorup(bl.color(random(0,32),random(0,32),random(0,32)));
    delay(100);
  }blank();
 
 
}

you need use autoformat tool in ide , need post whole sketch.

autoformat in tools menu, shortcut ctrl-t.


Arduino Forum > Using Arduino > Programming Questions > Only loops once when I send a command wirelessly.


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support