If it is, call the function to update the screen. Then you just subtract the time elapsed since the last update from the current millis() value and see if it's greater than your update interval constant. Then, create a variable for time elapsed since last update. So please show your complete code, then perhaps somebody on this forum can find out whats going on with your sketch. In your declarations, create a constant for LCD update interval and give it some reasonable value in milliseconds. As far as I can remember, only delayMicroseconds () has a problem with a parameter of 0, but delay () has not. Instead of having the LCD update in every run through void loop() use millis() to create a timer. So, what you do is put the input and output tasks in different subroutines. Do I care that the Arduino is non-responsive in those 2 seconds during my startup and that the startup takes a bit longer? Not really, so delay is a convenient mechanism to allow this "test pattern" to be rendered and verify that the led module is working.īut again, I do agree with you that avoiding delay is usually the best policy. Through the use of delay() it generates a "swipe" style animation that lasts in total for about 2 seconds. So now I've dropped this code into my setup () note the delay()s:ĭigitalWrite(barGraphLed, LOW) // Turn each LED off one by one and pase after each one. In the end, I founnd that it was the actual 10 segment led bar module that was faulty (I f#$&*~#ng spent a full day on trying to figure out what was wrong that stupid thing before I saw the true problem - faulty hardware). my code) to try to understand why a display I was trying to make on a 10 segment bar graph wasn't working properly. The amplitude of the jitter is the maximum time taken by a loop iteration. In my covid clock (mentioned in the video), where I do some setup, I run a test pattern on an LED bar just to verify upon startup that it was working.īecause I spent quite a bit of time trying to debug a program (i.e. The jitter comes from the fact that the clock is checked only once per loop iteration, and your periodic task can then be delayed by the other tasks. I also have another video in the pipeline that leverages delay - albeit temporarily to resolve a challenge that arises from a change in another part of the project that is unrelated to but required to continue working on the topic I was currently talking about. Indeed I did a whole video that agrees with you just now. Also, I note that you specify "interactive project" so probably I should up my percentage to 99.99%. While I 99.9% agree, there are times when it is convenient and helpful. I'd argue it is never the right way to code things in an interactive project.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |