Help for "standby" fadings till serial / MIDI Data is available

Hey Guys ,

im stuck on a problem with my Neopixel Wireless MIDI Code and hope you`ve a hint for me.

The Problem is simple :

If there is NO Serial Data / MIDI Data on RX of Arduino , do a thing ( Neopixel fading etc ) ,

if there`s Data use the MIDI Callbacks.

  1. Tried everything with “If” or “while” statements but im confused now.
  2. Do I need a time counter if there is NO serial for lets say 20 seconds?

Here`s my Code in Attachement and thank you :slight_smile:

_191117_Keplermaske_MIDI_18.ino (10.9 KB)

Do I need a time counter if there is NO serial for lets say 20 seconds?

This sounds like a job for millis() timing so that the input can be checked for a period.

Have a look at url=http://forum.arduino.cc/index.php?topic=503368.0]Using millis() for timing. A beginners guide[/url], Several things at the same time and look at the BlinkWithoutDelay example in the IDE.

Thank you ,

the millis() is a good idea , i`ll give it a try :slight_smile:

but i dont know how to get the “serial” data check to work.

i tried “if serial read” , but this wont work.

possibly i should check IF THERE´s a MIDI byte available rather then if there`s pure serial data.

but how ? :o
here is my code in the void loop…

  Serial.begin(9600); //XBEE

    if (Serial.read == 0){ 
 rainbowCycle(20);            /NEOPIXEL
}

if(Serial.read > 0 ){
   MIDI.setHandleControlChange(HandleControlChange);
    MIDI.setHandleNoteOn(HandleNoteOn);
    MIDI.setHandleNoteOff(HandleNoteOff);
    MIDI.setHandleProgramChange(handleProgramChange);
    PIXSTRIP.show();
      RING.show();
}
}

Have a look at the Serial.available() function. If no data is available then do thing 1 else do thing 2

tried several times, but nothing worked..

if (Serial.available == 0){
rainbowCycle(20); /NEOPIXEL
}

is correct ? :frowning:

circat:
tried several times, but nothing worked..

if (Serial.available == 0){
rainbowCycle(20); /NEOPIXEL
}

is correct ? :frowning:

No
That is not how you call a function