<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to calculate how much time the button is pressed?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/43444/how-to-calculate-how-much-time-the-button-is-pressed</link><description>I am working on requirement, where if you hold a button for &amp;quot;1 second &amp;quot; it should turn ON LED1 on the DK, likewise when you press button for &amp;quot;5 seconds&amp;quot; it should turn OFF the LED1 and turn ON LED2 . 
 Now I am facing issue how to calculate the amount</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 07 Feb 2019 11:00:09 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/43444/how-to-calculate-how-much-time-the-button-is-pressed" /><item><title>RE: How to calculate how much time the button is pressed?</title><link>https://devzone.nordicsemi.com/thread/169891?ContentTypeID=1</link><pubDate>Thu, 07 Feb 2019 11:00:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6588b550-43c0-4fa2-a2df-ac7f42e1e372</guid><dc:creator>flip-flop</dc:creator><description>&lt;p&gt;I can help you =)&lt;/p&gt;
&lt;p&gt;First of all, there&amp;#39;re many potential solutions for your problem but (in my opinion) the most elegant is to define buttons GPIO pins as interrupts. On button pressed event, call buttonPressedHandler and start timer (you can use RTC or APP timer). On buttonReleased&amp;nbsp;event, stop the timer, subtract two times and you&amp;#39;ll get pressed duration time. And there, a simple switch statement should be enough for your application logic.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>