The start of the extinguishing of the red LED will be triggered by using SW1 (P2.1). Similarly, the start of the extinguishing of the green LED will be triggered by using SW2 (P1.1). startup, both LEDs will have the same extinguishing frequency. With a double click of SW2 (P1.1), the extinguishing frequency of the green LED will be doubled.
Write this on Code Composer Studio.
#include <msp430.h>
#define SW1 BIT1
#define SW2 BIT2
#define RED_LED BIT0
#define GREEN_LED BIT6
int leftbutton = 0;
int rightbutton = 0;
int buttonState1 = 0;
int buttonState2 = 0;
int lastbuttonState1 = 0;
int lastbuttonState2 = 0;
int RED_LED_state = 1;
int GREEN_LED_state = 1;
unsigned long GREEN_LED_TIMER = 500;
unsigned long GREEN_LED_previous_time = 0;
void setup() {
WDTCTL = WDTPW | WDTHOLD;
P1DIR |= (RED_LED + GREEN_LED);
P1OUT &= ~(RED_LED + GREEN_LED);
P1DIR &= ~(SW1 + SW2);
P1REN |= (SW1 + SW2);
P1OUT |= (SW1 + SW2);
GREEN_LED_previous_time = millis();
}
void loop() {
rightbutton = !(P1IN & SW1);
leftbutton = !(P1IN & SW2);
P1OUT |= (RED_LED + GREEN_LED);
__delay_cycles(250000);
P1OUT &= ~(RED_LED + GREEN_LED);
__delay_cycles(250000);
unsigned long currentTime = millis();
if (currentTime - GREEN_LED_previous_time >= GREEN_LED_TIMER) {
GREEN_LED_state = !GREEN_LED_state; /
if (GREEN_LED_state)
P1OUT |= GREEN_LED;
else
P1OUT &= ~GREEN_LED;
GREEN_LED_previous_time = currentTime;
}
if (leftbutton) {
__delay_cycles(150000);
GREEN_LED_TIMER -= 500;
if (GREEN_LED_TIMER < 200) {
GREEN_LED_TIMER = 1000;