-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbutton.c
More file actions
47 lines (39 loc) · 727 Bytes
/
button.c
File metadata and controls
47 lines (39 loc) · 727 Bytes
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
38
39
40
41
42
43
44
45
46
47
#include <msp430.h>
#include "button.h"
#define TRUE 1
void configureP2PinAsButton(char pin)
{
P2DIR &= ~pin;
P2OUT |= pin;
P2REN |= pin;
}
char isP2ButtonReleased(char pin)
{
return P2IN & pin;
}
void waitForP2ButtonRelease(char pin)
{
while (!isP2ButtonReleased(pin)) {}
debounce();
}
char isP2ButtonPressed(char pin)
{
return !(P2IN & pin);
}
char pollP2Buttons(char buttonsToPoll[], char numberOfButtonsToPoll)
{
int i;
while (TRUE)
{
for (i = 0; i < numberOfButtonsToPoll; i++) {
if (isP2ButtonPressed(buttonsToPoll[i]))
{
return buttonsToPoll[i];
}
}
}
}
void debounce()
{
__delay_cycles(1000);
}