Just a quick one,

Just a quick one, my http://tpm2.net sketch relies on data being recieved in a UDP buffer, is there a way I can default to a set of basic patterns when no data is being recieved?

This is the current loop that displays the TPM2 data

void loop()
{

//---------------------------read packet size-------------------------------//
int packetSize = Udp.parsePacket();
//--------------------------------------------------------------------------//
//-----------------------------read udp in too buffer---------------------------//
Udp.read(packetBuffer,2000);
//------------------------------------------------------------------------------//

//------------------------check universe and write out too outputs-----------------//
if (packetBuffer[0]!=TPM2NET_HEADER_IDENT)

 {
    for(int i=start_address;i< number_of_channels;i++) {
    channel_buffer[i-start_address]= byte(packetBuffer[i+art_net_header_size+1]);
 }
 
  FastLED.show();

}
//--------------------------------------------------------------------------------//
}

packetSize will be 0 if no data is received. You then probably want a timeout …so if no data is received within x seconds you want to do your basic pattern

#define TIMEOUT 10 // timeout after 10 seconds

void loop(){
uint32_t lastData;
int packetSize = Udp.parsePacket();

if(packetSize){
lastData = millis();
//----------------------------------------------------------------------------//

//-----------------------check universe and write out too outputs----------------//
if (packetBuffer[0]!=TPM2NET_HEADER_IDENT)

{
for(int i=start_address;i< number_of_channels;i++) {
channel_buffer[i-start_address]= byte(packetBuffer[i+art_net_header_size+1]);
}

else{
if (millis()-lastData > TIMEOUT*1000){ // no data the last 10 seconds
drawBasicPattern();
}
FastLED.show

This is what I’d come up with, the box is on it’s way back for reprogramming so I cant test it just yet, does this look sane?

void loop()
{

//----------------------------read packet size--------------------------------//
int packetSize = Udp.parsePacket();
//----------------------------------------------------------------------------//
//------------------------------read udp in too buffer----------------------------//
Udp.read(packetBuffer,2000);
//--------------------------------------------------------------------------------//

//-------------------------check universe and write out too outputs------------------//
if (packetBuffer[0]!=TPM2NET_HEADER_IDENT)
{
for(int i=start_address;i< number_of_channels;i++) {
channel_buffer[i-start_address]= byte(packetBuffer[i+art_net_header_size+1]);
}
FastLED.show();
}
else
{
// Call the current pattern function once, updating the ‘leds’ array
gPatternsgCurrentPatternNumber;

    // send the 'leds' array out to the actual LED strip
      FastLED.show();  
    // insert a delay to keep the framerate modest
      FastLED.delay(1000/FRAMES_PER_SECOND); 

    // do some periodic updates
      EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
      EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
}

Something like that should work (and for the love of the gods above and below people - use gist!) – unless Udp.read is likely to put unexpected data in packetBuffer when data is slow to come in after you get your first packet, you might find your code suddenly switching from the data that came in over UDP to the ‘default’ patterns.

https://gist.github.com or http://pastebin.com are much better for sharing code snippets.

Ahhhh cool, thanks :wink: