Quantcast
Channel: Tweaking4All.com » All Posts
Viewing all articles
Browse latest Browse all 142

Reply To: Two ESP8266 P2P with WS2812b

$
0
0

It’s a little much for me to try – especially since I still have “play with ESP8266” on my “To Do” list.

Some basics I can think of though;

From the the 3rd sketch, I’d make a separate function of the void loop code and create a global variable and bring it to the receiver code.

So

void loop() {
  ...
}

To something like (the global variable defined somewhere in the top of your code).

...
bool DoBlink = false;
...
void checkReceivedValue() {
  // remove: buttonState=digitalRead(button); // put your main code here, to run repeatedly:
  if (DoBlink == TRUE) { DoBlink = false; // reset the value
    for(int blink=0; blink<blinkcount; blink++) {
      for(int i=0; i<NUM_LEDS; i++) {
        leds[i].setRGB(255,0,0);
        FastLED.show();
        delay(10);
      }
      delay(100);
      //setAll(0,0,0);
      for(int i=0; i<NUM_LEDS; i++) {
        leds[i].setRGB(0,0,0);
        FastLED.show();
        delay(10);
      }
      delay(100);
    }
    setAll(0,0,0);
  }
  else {
    setAll(0,0,0);
  }
}

Next step would be in the receiver code: 

– if a message was received, set “DoBlink = TRUE”.

– In the void loop(): add a call to the new function checkReceivedValue(), so in each loop we check network messages and handle the LEDs if DoBlink==TRUE.


Viewing all articles
Browse latest Browse all 142

Trending Articles