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

  1. 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.
  1. Compile the program, load it into the MSP432, and control the LED color sequencing

#include #include "msp.h" void SysTick_Delay(uint16_t delayms); void SysTick_Init(void); void delayms(uint32_t ms); void whitebutton(void); void bluebutton(void); void Redlight(void); void Greenlight(void); void Yellowlight(void); int buttonCheckP2_7(void);

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; iSEL0 &= ~BIT6; //gpio P2->SEL1 &= ~BIT6; P2->DIR &= ~BIT6; //direction is input (0) P2->REN |= BIT6; //enable resistor P2->OUT |= BIT6; //set default state to a 1 } void bluebutton(void){ P2->SEL0 &= ~BIT7; //gpio P2->SEL1 &= ~BIT7; P2->DIR &= ~BIT7; //direction is input (0) P2->REN |= BIT7; //enable resistor P2->OUT |= BIT7; //set default state to a 1 } void Redlight(void){ P5->SEL0 &= ~BIT5; //GPIO for P2.0, SEL = 00 P5->SEL1 &= ~BIT5; //GPIO P5->OUT |= ~BIT5; //enable resistor P5->DIR |= BIT5; //Set P2.0 as output } void Greenlight(void){ P5->SEL0 &= ~BIT4; //GPIO for P2.1 P5->SEL1 &= ~BIT4; //GPIO P5->OUT |= ~BIT4; //enable resistor P5->DIR |= BIT4; //Set P2.1 as output } void Yellowlight(void){ P4->SEL0 &= ~BIT7; //GPIO for P2.2 P4->SEL1 &= ~BIT7; //GPIO P4->OUT |= ~BIT7; //enable resistor P4->DIR |= BIT7; //Set P2.2 as output } int buttonCheckP2_7(void) { if(!(P2->IN & BIT7)) // If P1.4 is pressed (pressed == GND) { SysTick_Delay(0); if(!(P2->IN & BIT7)) // check again (Debounce) If P1.4 is pressed (pressed == GND) { uint8_t delayed = 0; while(!(P2->IN & BIT7) && delayed < 100) { delayed++; SysTick_Delay(3000); } SysTick_Delay(0); //__delay_cycles(300000) return 1; } else { return 0; } } else { // button not pressed return 0; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!