nRF51 Example 3 - Key scan

My Demo

keyScan
Please click “more” on the right!

My assignment:

Change the Delay(10000) to nrf_delay_ms(20)

Part of my source files

key.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "key.h"
#include "nrf_delay.h"
void KEY_Init(void)
{
//Configure GPIO pins as in Pullup input
nrf_gpio_cfg_input(21,NRF_GPIO_PIN_PULLUP);
nrf_gpio_cfg_input(22,NRF_GPIO_PIN_PULLUP);
nrf_gpio_cfg_input(23,NRF_GPIO_PIN_PULLUP);
nrf_gpio_cfg_input(30,NRF_GPIO_PIN_PULLUP);
}
void Delay(uint32_t temp)
{
for(; temp!= 0; temp--) ;
}
uint8_t KEY_Down(uint8_t KEY_X)
{
/*Check the Key */
if( nrf_gpio_pin_read(KEY_X)== 0 )
{
/*Delay for a while to prevent unexpected read*/
// Delay(10000);
nrf_delay_ms(20);
if(nrf_gpio_pin_read(KEY_X)== 0 )
{
/*Wait for the Key released */
while(nrf_gpio_pin_read(KEY_X)== 0 );
return 0;
}
else
return 1;
}
else
return 1;
}

Download my files

This work is licensed under a Creative Commons Attribution 4.0 International License.