forked from toddbranch/buttons
/
example.c
38 lines (30 loc) · 934 Bytes
/
example.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
38
//
// Example program demonstrating the use of button.h
// Toggles Launchpad LEDs on each button push
//
#include <msp430g2553.h>
#include "button.h"
int exampleMain()
{
WDTCTL = WDTPW|WDTHOLD;
configureP1PinAsButton(BIT1|BIT2|BIT3); // configure pins 1, 2, and 3 as buttons
P1DIR |= BIT0|BIT6; // set launchpad LEDs to output
while (1) {
char buttons[] = {BIT1, BIT2, BIT3};
char pressedButton = pollP1Buttons(buttons, 3);
switch (pressedButton) {
case BIT1:
// do something in response
break;
case BIT2:
// do something in response
break;
case BIT3:
// toggle LEDs and wait for release
P1OUT ^= BIT0|BIT6;
waitForP1ButtonRelease(BIT3);
break;
}
}
return 0;
}