<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>millis cookbook on Bald Engineer</title><link>https://www.baldengineer.com/tag/millis-cookbook</link><description>Recent content in millis cookbook on Bald Engineer</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Sun, 03 Apr 2022 00:05:55 +0000</lastBuildDate><atom:link href="https://www.baldengineer.com/tag/millis-cookbook/index.xml" rel="self" type="application/rss+xml"/><item><title>Detect short and long button press using millis</title><link>https://www.baldengineer.com/detect-short-long-button-press.html</link><pubDate>Wed, 19 Apr 2017 12:00:48 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=6440</guid><description>To detect a short and long button press using millis can give your project more functionality without adding more buttons. In this line-by-line example, I show how to react to a user pressing a button for a short period (100ms) or a long period (over 500ms). My example changes the blink rate of an LED on short presses. A long button press turns off the LED.&#10;In the code, I make use of a struct so that a single variable can be used to track multiple parameters. The benefit of this method is that adding multiple buttons is easy. You could create an array of these tyepdef’d variables.<p><img src="https://www.baldengineer.com/wp-content/uploads/2017/04/lbl-short-and-long-button-press.jpg" alt="Detect short and long button press using millis"/></p></description></item><item><title>Use Arduino millis() with buttons to delay events</title><link>https://www.baldengineer.com/use-millis-with-buttons-to-delay-events.html</link><pubDate>Wed, 27 Jan 2016 16:00:16 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=5720</guid><description>One of the common questions related to using the millis() function in Arduino, is around timed events. After an event occurs, you want the code to wait for some time before doing the next step. But you don’t want to stop the program with delay().&#10;In this example, we will use millis() to wait a few seconds after a pushbutton press to turn on an LED. Then a few seconds later, we will turn it off. All without using delay().<p><img src="https://www.baldengineer.com/wp-content/uploads/2016/01/lbl-delayedMillisActions.png" alt="Use Arduino millis() with buttons to delay events"/></p></description></item><item><title>Arduino: De-Bounce a Button with micros() or millis()</title><link>https://www.baldengineer.com/arduino-de-bounce-a-button-with-micros.html</link><pubDate>Fri, 13 Dec 2013 12:25:45 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=2095</guid><description>The Arduino is fast, humans are slow. When you push down a button, what seems like a single change to slow humans is really multiple presses to an Arduino. This is known as “bouncing.” Figure 1 is an oscilloscope screenshot showing what could happen when a button is pressed.&#10;Figure 1 - All the bouncing!&#10;The top trace shows the high-low-high transition of the button press. But notice all of the activity at the start of the high-to-low transition. The bottom trace is a “zoomed-in” view of that area. The button is actually transitioning multiple times before staying low. Internally the contacts are “bouncing.” This could result in false reads. In software, we can ignore these bounces by waiting some period of time after the first transition.<p><img src="https://www.baldengineer.com/wp-content/uploads/2013/12/MG_1763.jpg" alt="Arduino:  De-Bounce a Button with micros() or millis()"/></p></description></item><item><title>Arduino: Chasing LEDs with millis()</title><link>https://www.baldengineer.com/arduino-chasing-leds-with-millis.html</link><pubDate>Thu, 12 Dec 2013 12:00:34 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=2117</guid><description>A popular LED project is the “Larson Scanner.” This scanner emulates the effect seen on KIT from Knight Rider and the Cylons in Battlestar Galactica. The code is usually written using “delay()” which means you can’t combine it with anything else. The following code could be put into a function, called periodically and allow your code to scan while doing other things.&#10;One thing to note, a proper Larson Scanner has some persistence to the next and previous LEDs, this code does not. Maybe that would be a good exercise for the reader?<p><img src="https://www.baldengineer.com/wp-content/uploads/2012/09/millis-chasing-led-larson-scanner-banner.png" alt="Arduino:  Chasing LEDs with millis()"/></p></description></item><item><title>Arduino: Independent On-Off Times with Millis()</title><link>https://www.baldengineer.com/millis-ind-on-off-times.html</link><pubDate>Tue, 10 Dec 2013 12:25:29 +0000</pubDate><guid isPermaLink="false">https://www.baldengineer.com/?p=2059</guid><description>When using delay() to flash a LED there is a time for the LED to be on and then off. This makes it easy to have independent control of the “on” and “off” times. The standard blink without delay example doesn’t give you this flexibility.&#10;millis-cookbook-two-duty-cycles&#10;This example code gives you complete independent control of how long a LED (or any OUTPUT pin) stays “ON” or “OFF”. This also demonstrates a very simple two-state state machine.<p><img src="https://www.baldengineer.com/wp-content/uploads/2012/09/millis-ind-on-off-banner.png" alt="Arduino:  Independent On-Off Times with Millis()"/></p></description></item></channel></rss>