1. (mainEnergia.ino) Write a program for the MSP430 using Energia that will plac
ID: 3768863 • Letter: 1
Question
1. (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. The second time the button is pushed the red LED should turn on for 1 second, turn off for 1 second, turn back on for 1 second, and off again. The third time the button is pushed the green LED should turn on for 1 second and then turn off. The fourth time the button is pushed the green LED should turn on for 1 second, turn off for 1 second, turn back on for 1 second, and off again. The fifth time the button is pushed the red LED should turn on for 1 second and then turn off. The sixth time the button is pushed the red LED should turn on for 1 second, turn off for 1 second, turn back on for 1 second, and off again.... (Etc. etc. etc.)
Explanation / Answer
void displayIntLong(long x)
// takes a long between 0~99999 and sends it to the MC14489
{
int numbers[5];
byte a=0;
byte b=0;
byte c=0; // will hold the three bytes to send to the MC14489
// first split the incoming long into five separate digits
numbers[0] = int ( x / 10000 ); // left-most digit (will be BANK5)
x = x % 10000;
numbers[1] = int ( x / 1000 );
x = x % 1000;
numbers[2] = int ( x / 100 );
x = x % 100;
numbers[3] = int ( x / 10 );
x = x % 10;
numbers[4] = x % 10; // right-most digit (will be BANK1)
// now to create the three bytes to send to the MC14489
// build byte c which holds digits 4 and 5
c = numbers[3];
c = c << 4; // move the nibble to the left
c = c | numbers[4];
// build byte b which holds digits 3 and 4
b = numbers [1];
b = b << 4;
b = b | numbers[2];
// build byte a which holds the brightness bit, decimal points and digit 1
a = B10000000 | numbers[0]; // full brightness, no decimal points
// now send the bytes to the MC14489
digitalWrite(enable, LOW);
shiftOut(data, clock, MSBFIRST, a);
shiftOut(data, clock, MSBFIRST, b);
shiftOut(data, clock, MSBFIRST, c);
digitalWrite(enable, HIGH);
delay(10);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.