-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainEnergia.ino
76 lines (70 loc) · 2.23 KB
/
mainEnergia.ino
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* Author: Evan Glazer
School: University of Central Florida
Class: EGN3211 Engineering Analysis and Computation
Program: mainEnergia.ino
Write a program for the MSP430 using Energia that will place an interrupt on the push2 button to blink either the red or green LED in one of
two particular patterns for each color LED. The first time the button is pushed the red LED should turn on for 1 second and then turn off. */
#include <io.h>
#define pin0mask (0x01 << 0)
#define pin3mask (0x01 << 3)
#define pin6mask (0x01 << 6)
int main(void)
{
// Variables
int pushed = 0; // flag to tell us when we've handled a button event
int blinkMode = 0; // toggle of modes
int blinkMask = pin0mask; // which light we need to blink
// stop watchdog timer
WDTCTL = WDTPW + WDTHOLD;
// configure pins 0,6 on port 1 as output pins
P1DIR = pin0mask | pin6mask;
// make sure green (pin 6) is turned off
P1OUT &= ~pin6mask;
// infinite loop
for( ; ; )
{
// this can cause a delay in length
for( int j = 0; j < 10000; j++ )
{
if((P1IN & pin3mask ) == 0)
{
// check to see if we don't try to handle this press again
if(!pushed)
{
pushed = 1;
blinkMode = (blinkMode + 1)%4;
}
// blink red bit 0 only
if(blinkMode == 0)
{
blinkMask = pin0mask;
P1OUT &= ~pin6mask;
}
// blink green pin 6 only
else if(blinkMode == 1)
{
blinkMask = pin6mask;
P1OUT &= ~pin0mask;
}
// blink both together
else if(blinkMode == 2)
{
blinkMask = pin0mask|pin6mask;
P1OUT |= pin0mask|pin6mask;
}
// blink both alternately
else
{
blinkMask = pin0mask|pin6mask;
P1OUT &= ~pin0mask;
P1OUT |= pin6mask;
}
}
}
else
{
pushed = 0;
}
}
P1OUT ^= blinkMask;
}