<?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>Add  a supplemetnary button and led on Blinky exemple</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/26245/add-a-supplemetnary-button-and-led-on-blinky-exemple</link><description>Hello,
we have a project on:
Periperal: experimental ble_app_blinky / and
Central: experimental ble_app_blinky c
We have add suplementary: 
LEDBUTTON_LED4 ( BSP_BOARD_LED_3)
LEDBUTTON_BUTTON2_PIN&amp;quot; (BSP_BUTTON_1)
For the moment when we push &amp;quot;button2</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 07 Sep 2020 09:03:47 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/26245/add-a-supplemetnary-button-and-led-on-blinky-exemple" /><item><title>RE: Add  a supplemetnary button and led on Blinky exemple</title><link>https://devzone.nordicsemi.com/thread/268226?ContentTypeID=1</link><pubDate>Mon, 07 Sep 2020 09:03:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:433e6897-5fa9-41f9-a7b0-d592d7eec631</guid><dc:creator>Saagar</dc:creator><description>&lt;p&gt;Hi Jorn&lt;/p&gt;
&lt;p&gt;After making above changes, If i press button_1 led_1 will glow and if i press button_2 then both leds led1 and led2 will glow&lt;/p&gt;
&lt;p&gt;i am not getting why led1 is glowing after pressing button2. please help&lt;/p&gt;
&lt;p&gt;board used :- nrf52_pca10040&lt;/p&gt;
&lt;p&gt;sdk :- 11.0&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Add  a supplemetnary button and led on Blinky exemple</title><link>https://devzone.nordicsemi.com/thread/124929?ContentTypeID=1</link><pubDate>Mon, 19 Mar 2018 09:21:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:725cd6c4-5ece-41c0-976d-fc790a3cb227</guid><dc:creator>run_ar</dc:creator><description>&lt;p&gt;Handling in:129094&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Add  a supplemetnary button and led on Blinky exemple</title><link>https://devzone.nordicsemi.com/thread/103339?ContentTypeID=1</link><pubDate>Wed, 25 Oct 2017 16:32:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4c75c3ee-aa98-42c8-8ba8-9a71fd82a775</guid><dc:creator>mc</dc:creator><description>&lt;p&gt;Hello Jorn Froysa&lt;/p&gt;
&lt;p&gt;Thank you very much!!!
Now we can push the button on the peripheral and the  correct leds toggel on the central!&lt;/p&gt;
&lt;p&gt;To do it from central to the peripheral we have a problem:
We not see the &amp;quot;case BLE_LBS_C_EVT_BUTTON_NOTIFICATION&amp;quot; in the peripheral.
We see only the &amp;quot;led write handler&amp;quot; What we have to change there?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/**@brief Function for handling write events to the LED characteristic.
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;@param[in] p_lbs     Instance of LED Button Service to which the write applies.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;@param[in] led_state Written/desired state of the LED.
*/
static void led_write_handler(ble_lbs_t * p_lbs, uint8_t led_state)
{
if (led_state)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; bsp_board_led_on(LEDBUTTON_LED_PIN);
 	  NRF_LOG_INFO(&amp;quot;Received LED ON!\r\n&amp;quot;);
 	
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}
else
{
bsp_board_led_off(LEDBUTTON_LED_PIN);
NRF_LOG_INFO(&amp;quot;Received LED OFF!\r\n&amp;quot;);
}&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;Can you plase send us the modification?
We would very apppreciate!
Best regards MC&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Add  a supplemetnary button and led on Blinky exemple</title><link>https://devzone.nordicsemi.com/thread/103338?ContentTypeID=1</link><pubDate>Wed, 25 Oct 2017 12:42:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:65fd6e32-e0d6-443f-a68c-c2b779d041f8</guid><dc:creator>J&amp;#248;rn</dc:creator><description>&lt;p&gt;Hello mc&lt;/p&gt;
&lt;p&gt;There are a few ways you can achieve this. You could create a new characteristic for the second button, or you could use the one already there.
I threw together a quick solution using the characteristic already present. Do note this solution may not be the optimal way of doing it, it&amp;#39;s just for guidance.&lt;/p&gt;
&lt;p&gt;The way the blinky example works at the peripheral is that GPIOTE  generates an interrupt, this identifies it as a port event, then calls the button handler in the app_buttons module, which creates a variable called transition, which is passed on to the button_event_handler in main.c. The transition variable is set to 1 if the button transition led to the pins &amp;quot;active state&amp;quot;, and zero otherwise. The active state is defined when calling app_buttons_init, in the buttons_init function in main. In the example the active state attribute is set to &amp;quot;false&amp;quot; which corresponds to 0.&lt;/p&gt;
&lt;p&gt;The button_event_handler then calls the ble_lbs_on_button_change function which sends the transition value to the client.&lt;/p&gt;
&lt;p&gt;The changes I made here defines a new button, LEDBUTTON_BUTTON_PIN2, and registers this with the app_button module in buttons_init. The button config now looks like this&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static app_button_cfg_t buttons[] =
{
    {LEDBUTTON_BUTTON_PIN, false, BUTTON_PULL, button_event_handler},
    {LEDBUTTON_BUTTON_PIN2, false, BUTTON_PULL, button_event_handler}
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I then altered the switch in button_event_handler&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;switch (pin_no)
{
    case LEDBUTTON_BUTTON_PIN:
        NRF_LOG_INFO(&amp;quot;Send button1 state change.\r\n&amp;quot;);            
        err_code = button_action ? ble_lbs_on_button_change(&amp;amp;m_lbs, 1) : ble_lbs_on_button_change(&amp;amp;m_lbs, 0);
        if (err_code != NRF_SUCCESS &amp;amp;&amp;amp;
            err_code != BLE_ERROR_INVALID_CONN_HANDLE &amp;amp;&amp;amp;
            err_code != NRF_ERROR_INVALID_STATE)
        {
            APP_ERROR_CHECK(err_code);
        }
        break;
					
	case LEDBUTTON_BUTTON_PIN2:
		NRF_LOG_INFO(&amp;quot;Send button2 state change.\r\n&amp;quot;);            
		err_code = button_action ? ble_lbs_on_button_change(&amp;amp;m_lbs, 3) : ble_lbs_on_button_change(&amp;amp;m_lbs, 2);
        if (err_code != NRF_SUCCESS &amp;amp;&amp;amp;
            err_code != BLE_ERROR_INVALID_CONN_HANDLE &amp;amp;&amp;amp;
            err_code != NRF_ERROR_INVALID_STATE)
        {
            APP_ERROR_CHECK(err_code);
        }
				break;

    default:
        APP_ERROR_HANDLER(pin_no);
        break;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This sends a 0 or 1 if the first button is released/pressed, and a 2 or 3 if the second button is released/pressed.&lt;/p&gt;
&lt;p&gt;On the client side you define a second LED, and then alter the following case in lbs_c_evt_handler in main&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;case BLE_LBS_C_EVT_BUTTON_NOTIFICATION:
        {
            NRF_LOG_INFO(&amp;quot;Button state changed on peer to 0x%x.\r\n&amp;quot;, p_lbs_c_evt-&amp;gt;params.button.button_state);
            if (p_lbs_c_evt-&amp;gt;params.button.button_state==0x1)
            {
                bsp_board_led_on(LEDBUTTON_LED);
            }
            else if(p_lbs_c_evt-&amp;gt;params.button.button_state==0x0)
            {
                bsp_board_led_off(LEDBUTTON_LED);
            }
            else if(p_lbs_c_evt-&amp;gt;params.button.button_state==0x3)
            {
                bsp_board_led_on(LEDBUTTON_LED2);
            }
            else
            {
                bsp_board_led_off(LEDBUTTON_LED2);
            }						
        } break; // BLE_LBS_C_EVT_BUTTON_NOTIFICATION
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This toggles the correct led depending on what value was received from the server.&lt;/p&gt;
&lt;p&gt;You will need to add similar changes (but reverse roles) for an extra button at the central.&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;Jørn Frøysa&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>