The problem is probably in your sketch or Python script, but we don't know your sketch or your script. The functions blocks the execution of any other code, except for interrupt service routines. In the Leonardo, the 'Serial' could be zero, if the serial monitor has not been opened yet. The problem with the delay() function is that it is blocking. This number is quite large but is well within the scope of an unsigned long: 32 bits (232. delay (x) will delay for x number of milliseconds. Serial. The 'Serial' is always valid for an Arduino Uno, therefor that piece of code does not wait. Yes you can write delay (25200000UL) and it will delay for 7 hours. You can delay() the execution, but waiting can at best be achieved by using some of the above mentioned sleep modes. (I know I could probably code the colours far more efficiently but i'm only just beginning so go easy on me ) int rPin = 6 The code for the 'while' loop waiting in serial input is lines 28 to 70 When you use millis () to time events instead of delay (), your code keeps on looping and allows it. The Arduino Reference for millis () says it: Returns the number of milliseconds passed since the Arduino board began running the current program. It helps us time events without pausing the code. I have the code working to constantly cycle the colours on it's own, but when I paste it into a 'while' function that is waiting for serial input (Serial.available() = 0) it runs once and then waits for input but doesn't cycle again. The problem is that delay () is a 'busy wait' that monopolizes the processor. The millis () function is nothing like delay (). I have the bulk of the code working, the only thing stumping me is how to get the LED to cycle through the spectrum whilst waiting on a serial input. Certain things do go on while the delay () function is controlling the Atmega chip however, because the delay function does not disable interrupts. It's basically an RGB LED that will change colour to match an input on the serial monitor. More knowledgeable programmers usually avoid the use of delay () for timing of events longer than 10’s of milliseconds unless the Arduino sketch is very simple. I'm currently trying to do my first simple project written & designed by myself from the ground up.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |