So, I've been working on this project for a few days now. I've bought a NeoPixel ring, hooked an IR reciever and IR controller to function as controller for the ring. If I press the button UP for example, the NeoPixel Ring displays a rainbow function for a set amount of times. I've gotten so far as to program in a few different functions for the NeoPR to display on the press of different buttons. HOWEVER, these functions go on for a minute or more and I need a way to force quit them. A power down button. I've tried several ways to program in a quit button but to no avail. Nothing budges the Loop that the functions are in. So my question is 1. How do I write a function that stops my Loop completely, turning the NeoPixel off at least. 2. Can I write my functions outside a Loop, what other ways do I have?
My knowledge of programming is slim, not hopeless but slim.
I might have phrased this wrong, perhaps. If so, please ask me more questions specifically that I can answer to provide some light in the matter.
You have not posted any code but I assume that you are using delay() in a for loop, perhaps nested for loops. If you were to abandon the use of delay() and use millis() for timing then you could read a switch much more often (each time through loop()) which will make the system more responsive.
So, UKHeliBob what you're suggesting is that I limit my Ring function to be a short loop, so the stop will be more responsive. So if my loop takes 10 seconds, if I then press my "stop" button after 5 seconds it will make the loop stop 5 seconds later? When the loop makes a loop (ha)?
The value member of the results struct is NOT an unsigned int.
You need to separate the reading of the IR device from acting on the value last read.
You need to completely rewrite what happens in the code1 case. On every pass through loop(), not in a for loop, it may, or may not, be time to change state. If it is, you need to record when that happens, and make the appropriate changes.
Robin2 has some good examples of doing more than one thing at a time. The blink without delay example does, too. Read, understand, and embrace the blink without delay philosophy, and you'll never use delay() again (or a for loop that way, either).