Pages: [1]   Go Down
Author Topic: Wifly LED control delay issues  (Read 1044 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have gotten a wifly to run a simple web server, and it is suppose to have 3 pushbuttons.  Sometimes it loads all 3 and sometimes it only loads the first two, Not sure what is causing that problem.  Im new to everything and self taught, but if anyone can see what is causing that it would be greatly appreciated.

the main thing I am trying to work out is, when I select a pushbutton and hit enter, There is a delay in how long it takes for the shiftbrites to change their pattern, and it also locks up on the last cycle while it processes.  So if i am running a strobe pattern (pattern 3) and when i hit submit, it is currently off, it stays off until it starts the next pattern.  Or if it is on it quits strobing and stays solid for a second, and then changes to the next pattern. I would like this to be instant, I'm hoping someone can see something obvious that is causing the delay and can point me in the right direction.  Here is the code:
Code:


// Set pins to outputs and initial states
void setup() {
  
   Serial.begin(9600);
  SpiSerial.begin();
  //exit CMD mode if not already done
  SpiSerial.println("");
  SpiSerial.println("exit");
  delay(1000);
  
  //set into CMD mode
  SpiSerial.print("$$$");
  delay(1000);

  //set authorization level
  SpiSerial.println("set w a 3");
  delay(1000);

  //set passphrase
  SpiSerial.println("set w p bdeckwifi");
  delay(1000);
  
  //set localport
  SpiSerial.println("set i l 80");
  delay(1000);
  
  //disable *HELLO* default message on connect
  SpiSerial.println("set comm remote 0");
  delay(1000);

  //join wifi network <ssid>
  SpiSerial.println("join testing");  
  delay(5000);
  
  //exit CMD mode
  SpiSerial.println("exit");  
  delay(1000);  

  
  
  
  pinMode(datapin, OUTPUT);
  pinMode(latchpin, OUTPUT);
  pinMode(enablepin, OUTPUT);
  pinMode(clockpin, OUTPUT);
  digitalWrite(latchpin, LOW);
  digitalWrite(enablepin, LOW);
}

void SB_SendPacket() {

  if (SB_CommandMode == B01) {
    SB_RedCommand = 127;
    SB_GreenCommand = 110;
    SB_BlueCommand = 110;
  }

  SB_CommandPacket = SB_CommandMode & B11;
  SB_CommandPacket = (SB_CommandPacket << 10)  | (SB_BlueCommand & 1023);
  SB_CommandPacket = (SB_CommandPacket << 10)  | (SB_RedCommand & 1023);
  SB_CommandPacket = (SB_CommandPacket << 10)  | (SB_GreenCommand & 1023);

  for (int j = 0; j < 32; j++) {
    if ((SB_CommandPacket >> (31 - j)) & 1) {
      DATPORT |= (1 << DATPIN);
    }
    else {
      DATPORT &= ~(1 << DATPIN);
    }
    CLKPORT |= (1 << CLKPIN);
    CLKPORT &= ~(1 << CLKPIN);
  }
}

void SB_Latch() {

  delayMicroseconds(1);
  LATPORT |= (1 << LATPIN);
  ENAPORT |= (1 << ENAPIN);
  delayMicroseconds(1);
  ENAPORT &= ~(1 << ENAPIN);
  LATPORT &= ~(1 << LATPIN);

}

void WriteLEDArray() {

  SB_CommandMode = B00; // Write to PWM control registers

  for (int i = 0; i < NumLEDs; i++) {
    SB_RedCommand = LEDChannels[i][0];
    SB_GreenCommand = LEDChannels[i][1];
    SB_BlueCommand = LEDChannels[i][2];
    SB_SendPacket();
  }
  
  SB_Latch();
  
  SB_CommandMode = B01; // Write to current control registers

  for (int z = 0; z < NumLEDs; z++) SB_SendPacket();  

  SB_Latch();

}
 
void rotate(){
  val=30;    
  //val= analogRead(analogPin);

// Example loop to cycle all LEDs through primary colors
    if (program==1){
    for (int i = 0; i < NumLEDs; i++) {
    LEDChannels[i][0] = 1023;
    LEDChannels[i][1] = 900;
    LEDChannels[i][2] = 750;
 
  WriteLEDArray();
  
       delay(val);}
       for (int i = 0; i < NumLEDs; i++) {
       LEDChannels[i][0] = 0;
       LEDChannels[i][1] = 0;
       LEDChannels[i][2] = 0;
       WriteLEDArray();
       delay(val);}}
 
   else if(program==2){
       val=30;
       for (int k = 0; k <60;k++) {    
       i=k ;
       int a=i+1;
       int b=a+1;
       int c=b+1;
       int d=c+1;
          
       LEDChannels[0][0] = ai[i][0];
       LEDChannels[0][1] = ai[i][1];
       LEDChannels[0][2] = ai[i][2];
       LEDChannels[1][0] = ai[i][0];
       LEDChannels[1][1] = ai[i][1];
       LEDChannels[1][2] = ai[i][2];
       LEDChannels[2][0] = ai[a][0];
       LEDChannels[2][1] = ai[a][1];
       LEDChannels[2][2] = ai[a][2];
       LEDChannels[3][0] = ai[a][0];
       LEDChannels[3][1] = ai[a][1];
       LEDChannels[3][2] = ai[a][2];      
       LEDChannels[4][0] = ai[c][0];
       LEDChannels[4][1] = ai[c][1];
       LEDChannels[4][2] = ai[c][2];      
       LEDChannels[5][0] = ai[c][0];
       LEDChannels[5][1] = ai[c][1];
       LEDChannels[5][2] = ai[c][2];      
       LEDChannels[6][0] = ai[d][0];
       LEDChannels[6][1] = ai[d][1];
       LEDChannels[6][2] = ai[d][2];      
       LEDChannels[7][0] = ai[d][0];
       LEDChannels[7][1] = ai[d][1];
       LEDChannels[7][2] = ai[d][2];
       LEDChannels[8][0] = ai[b][0];
       LEDChannels[8][1] = ai[b][1];
       LEDChannels[8][2] = ai[b][2];      
       LEDChannels[9][0] = ai[b][0];
       LEDChannels[9][1] = ai[b][1];
       LEDChannels[9][2] = ai[b][2];
      
  
    
         WriteLEDArray();
         delay(val);}}
   else if(program==3){

  val = 30;
       //val = analogRead(analogPin);
    for (int j1 = 0; j1 < NumLEDs; j1++) {
       LEDChannels[j1][0] = 1023;
       LEDChannels[j1][1] = 1000;
       LEDChannels[j1][2] = 750;
   }
     WriteLEDArray();
     delay(val);
      
       for (int j1 = 0; j1 < NumLEDs; j1++) {
       LEDChannels[j1][0] = 0;
       LEDChannels[j1][1] = 0;
       LEDChannels[j1][2] = 0;
   }
       WriteLEDArray();
       delay(val);
      
        
  }
}
  



void loop() {
  if (rot==1){
   rotate();
 }
 // Create a client connection
  Client client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 30)
        {
          readString += c; //store characters to string
        }
        //if HTTP request has ended
        if (c == '\n')

        {
          // check if LED should be lighted

          delay(100);
         /* int locateQuestionmark = readString.indexOf('?');
          Serial.println (readString);
          Serial.println ("The index of the ? in the string " + readString + " is " + locateQuestionmark);
          Serial.println(readString.substring(6,9));*/

          
          // now output HTML data starting with standart header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          //set background to yellow
          client.print("<body style=background-color:grey>");

          //send first heading
          client.println("<font color=’red’><h1>  WEB ARDUINO TEST</font></h1>");
          client.println("<hr />");
          client.println("<hr />");

          //controlling led via checkbox
          client.println("<h1>LED control</h1>");
          //address will look like http://192.168.1.110/?L=1 when submited
          //client.println("<form method=get name=LED><input type=checkbox name=L value=1>LED<br><input type=submit value=submit></form>");
          client.println("<form method=get name=LED><input type=checkbox name=L value=1>LED<br><input type=submit value=submit></form>");
          client.println("<form method=get name=LED><input type=checkbox name=L value=2>LED<br><input type=submit value=submit></form>");
          client.println("<form method=get name=LED><input type=checkbox name=L value=3>LED<br><input type=submit value=submit></form>");
          client.println("<br />");
          
          if (readString.substring(6,9) == "L=1")      

          {program=1;
          }
          if (readString.substring(6,9) == "L=2")      
          {
            program=2;
          }
          if (readString.substring(6,9) == "L=3")      

          {
            program=3;
          }
          if (readString.substring(6,9) == "L=3"||"L=1"||"L=2")
          {rot=1;}

         Serial.println(readString.substring(6,9));
        Serial.println("The current program is" + program);
        
          //clearing string for next read
          readString="";
          //stopping client
          client.stop();
        }
      }
    }
  }
}
  


Logged

Pages: [1]   Go Up
Jump to: