Think of the algorithm as our plan of action. Event 2: Read/Display Temp Value (every 5 sec).Event 1: Read/Display LDR Value (every 1 sec).Event 2 will read the temperature sensor and display it’s value every five seconds. We want Event 1 to read the LDR and then display that value every 1 second. We want the light-dependent resistor to read and display every second and the temperature sensor to read and display every five seconds. What we want to do is read these values and display them to the Serial Monitor window but we don’t want constant readings. We’ve got two sensors, a light-dependent resistor (or LDR) and a temperature sensor. This is more or less what we’re trying to accomplish. Drink Kool-Aid and watch a beautiful sunsetĮvery good program has an even better algorithm to go along with it, so before we start typing away at the Arduino IDE, first we want to write out our plan of action.Code from scratch a program using millis() to time 2 repetitive events.Map out a program with 2 INDEPENDENT timed events. Here’s a quick rundown: In part 1 we described the basics of the millis function in general, in part 2 we talked about tight loops and blocking code, in part 3 and part 4 we discussed some issues that arise when using the delay function, and in part 5 we showed how to create “once-off” events and repetitive timed events using the millis function. If you haven’t seen the previous lessons in this series, we highly recommend that you go back and check them out either now or after this lesson. For example, you may want a servo to move every 3 seconds, or to send a status update to a web server every 3 minutes. This is part of a mini-series we’ve been publishing that’s all about using the Arduino millis function to create timed events. Have you ever wanted to do MULTIPLE timed events with Arduino? What about multiple CONCURRENT timed events? We’re “upping” our game with this lesson, so buckle in and hold on tight!
0 Comments
Leave a Reply. |