![]() Make it obvious that you are using one, and make the reasoning obvious, too. Ternaries need to be kept simple or bugs can creep in and readability can be degraded. The only proviso is that we don’t see this as better code, only a different take on this particular logic. Where "sequenceChooser() " references a switch case that chooses which lighting function to call, and "MIDI.read()" assigns the incoming note number to the variable "whatToDo".Case x 50 ? 'greater than' : x < 50 ? 'less than' : 'equal to'} 50` SequenceChooser() //choose light sequence MIDI.read() // Continuously check if MIDI data has been received. Right now the code in the loop looks like this: void loop() Is there any other way to have a function run on a loop until another case is called? I have eliminated all uses of "delay" and am still having the problem. Now that I have something other than "MIDI.read() " in the void loop, my arduino is missing some of the incoming MIDI messages, particularly while another function is running. Void MyNoteOnFunction(byte channel, byte number, byte value)įill_solid(leds, NUM_LEDS, CRGB::Orange) įill_solid(leds, NUM_LEDS, CRGB::Purple) įill_solid(leds, NUM_LEDS, CHSV(20, 200, 255)) įtBrightness(150) //use to dim existing sceneįill_solid(leds, NUM_LEDS, CRGB(100, 0, 255)) MIDI.read() // Continuously check if Midi data has been received. above is palette for redGreenWhiteChaser the function you want to call when a NoteOn command is received.įastLED.addLeds(leds, 0, NUM_LEDS_DOWNSTAIRS) //for correct LED stripsįastLED.addLeds(leds, NUM_LEDS_DOWNSTAIRS, NUM_LEDS_UPSTAIRS) I alredy can turn the light on and off and also make blink, but just when I press the button. I just used the switch/case to read the inputs and make the decisions. 0 - red 1 - red & amber 2 to 4 - amber 5 to 14 - green and 15 - green & amber. switch. Hello, Im doing a simple project for my university where I turn on/off a lamp with a IR Remote control. Now we will use some LEDs to show the state of the value. The best way to understand it is using an example first coded using Arduino if else statements and then translated into Arduino switch case statements. We will start by dividing it by 64 to get a value 'reading' holding a number in the range 0 - 15. ![]() ![]() tHandleNoteOn(MyNoteOnFunction) // This command tells the MIDI Library Example 1: Suppose you've read in a value from a potentiometer using the ADC. MIDI.begin(1) //initialize the MIDI library #define NUM_LEDS NUM_LEDS_UPSTAIRS+NUM_LEDS_DOWNSTAIRS Here's the important part: #include // Add Midi Library (I tried using a for loop to list the cases and whatToDo variables in the MyNoteOnFunction but couldn't get it to work, so for now they're just listed out) I'm relatively new to Arduino so please excuse me if this is too simple a question.Īttached is my code, I can simplify it if it will make the problem easier to see/solve. ![]() Is there a way to loop the code inside each case until another case is called? Instead, they use a continuous string of characters. I would prefer to not have to rewrite all of the light functions to accommodate this. f forward b backward l left r right s stop Character arrays use do not use lists of comma-separated elements. The problem is that with the MIDI Library, the switch-case statement is not in the void loop() function, so the light functions requiring loop behavior (sparkle, chase, etc) do not behave properly. The Arduino programming language Reference, organized into Functions, Variable and Constant. I'm using an Arduino Mega to control a set of WS2812 LEDs (similar to Adafruit's Neopixels) via MIDI messages using a SparkFun MIDI Shield.ĭepending on which MIDI NoteOn message the arduino receives, a different case is called which in turn either sets the LEDs to a certain color OR calls a function. I recognize that other people have asked similar questions to this, but have been unable to find help closely related enough to my particular issue.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |