Yun client loop for neopixels

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
j3r
 
Posts: 1
Joined: Thu Dec 04, 2014 11:50 am

Yun client loop for neopixels

Post by j3r »

Hi guys, I am trying to control neopixels through the Yun. I can turn lights on and off, but anything that relies on the loop to iterate through the steps (ie: rainbow) only hits the first step then terminates. I am sure this is due to a lack of coding knowledge on my part, but I was wondering if anyone knows a way to get around this.

I can of course loop the rainbow function itself, but then I can't get input from bridge to change the lighting program.

My loop is from the documentation

Code: Select all

void loop() {
  // Get clients coming from server
  YunClient client = server.accept();
  if (client) {
    process(client);
    client.stop();
  }
  delay(50);
}
then I just process the command and light settings

Code: Select all

void process(YunClient client) {
  String command = client.readStringUntil('/');

  if (command == "light") {
    lightCommand(client);
  }
}

void lightCommand(YunClient client) {
  int programMode = client.parseInt();
  int redRaw = client.parseInt();
  int redVal = constrain(redRaw, 0, 255);

  int BANNED = client.parseInt();
  int greenVal = constrain(BANNED, 0, 255);

  int blueRaw = client.parseInt();
  int blueVal = constrain(blueRaw, 0, 255);
      switch (programMode) {
        case 0:
          allColor(strip.Color(0, 0, 0)); //off
          break;
        case 1:
          allColor(strip.Color(redVal, greenVal, blueVal)); //off
          break;
        case 2:
          rainbow(100);
          break;
        case 3:
          rainbowCycle(10);
          break;
        default:
          allColor(strip.Color(0, 0, 0)); //off
      }
}
What I want is for loop to continue passing the command until a new command is received. This has to be easier than the many convoluted ways I have tried. Thanks in advance for any ideas.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Yun client loop for neopixels

Post by adafruit_support_mike »

You'll need to rewrite the pixel control routines so they take the loop variables (usually i & j) as parameters. That moves the control loop out of the function, so you can interleave it with calls to the Bridge library.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”