Question: I need help modifying my code (below) from CCS to make my MSP432 do what is asked below. As of right now an LED will
I need help modifying my code (below) from CCS to make my MSP432 do what is asked below. As of right now an LED will light up by the press of a button and continue in a sequence of other LED's. I just need help changing my code to make the LEDs go through a sequence by holding the button down.
Part II Sequencing colored LEDs using a timer and pushbutton
- Modify your program from Part I so that the following happens:
- Upon startup or reset, the LEDs should be OFF.
- When you press and hold down a pushbutton the green LED (only the green LED) lights for 1 second followed by the yellow LED on for 1 second and then only the red LED on for 1second.
Determine a way to generate both one second and five millisecond delay intervals
using the SysTick timer.
- This sequence should repeat as long as the pushbutton is depressed. When the pushbutton is released the sequencing pauses with the current LED remaining ON.
- Pressing and holding down the pushbutton again will start up the sequence of lighting LEDs where it left off.
- Compile the program, load it into the MSP432, and control the LED color sequencing
#include
void main(void){ bluebutton(); Redlight(); Greenlight(); Yellowlight(); SysTick_Init(); WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD;
while(1){ if(buttonCheckP2_7()) {
if(P5->OUT & BIT5) //green on { P5->OUT &= ~BIT5; //turn green off P4->OUT |= BIT7; //turn yellow on } else if(P4->OUT & BIT7) //yellow on { P4->OUT &= ~BIT7; //turn yellow off P5->OUT |= BIT4; // turn on red } else if(P5->OUT & BIT4) //red on { P5->OUT &= ~BIT4; //turn off red P5->OUT |= BIT5; //turn on green } else // nothing on so light up green { P5->OUT &= ~BIT5; //turn off green P4->OUT |= BIT7; //turn on yellow } } }
}
void SysTick_Init(void) { SysTick -> CTRL = 0; SysTick -> LOAD = 3000000-1; // max reload value SysTick -> VAL = 0; SysTick -> CTRL = 5; } void SysTick_Delay(uint16_t delayms){ SysTick -> LOAD = ((delayms * 3000) - 1); SysTick -> VAL = 1; while((SysTick->CTRL &= BIT(16))); } void delayms(uint32_t ms) { uint32_t i; for(i=0; i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
