Msp430f5529lp double click

The ignition of the red LED will be done using SW1 (P2.1). Similarly, the ignition of the green LED will be done using SW2 (P1.1). Upon application startup, both LEDs will have the same blink frequency. By double-clicking SW2 (P1.1), the blink frequency of the green LED will double."

CAN ANYONE HELP ME TO SOLVE THE EXERCISE?

#define SW1 P2_1
#define SW2 P1_1

int leftbutton=0;
int rightbutton=0;
int buttonState =0;
int lastbuttonState=0;


void setup() {

  pinMode(RED_LED , OUTPUT);
  pinMode(GREEN_LED , OUTPUT);
  
  pinMode(SW1 , INPUT_PULLUP);
  pinMode(SW2, INPUT_PULLUP);
}

void loop() {
  rightbutton=digitalRead(SW1);
  leftbutton=digitalRead(SW2);

  digitalWrite(RED_LED, HIGH);
  digitalWrite(GREEN_LED , HIGH);
  delay(250);
  digitalWrite(RED_LED, LOW);
  digitalWrite(GREEN_LED , LOW);
  delay(250);
  
  }

I DO THIS UNTIL NOW

moderator edit: code tags added

he ignition of the red LED will be done using SW1 (P2.1). Similarly, the ignition of the green LED will be done using SW2 (P1.1). Upon application startup, both LEDs will have the same blink frequency. By double-clicking SW2 (P1.1), the blink frequency of the green LED will double."

CAN ANYONE HELP ME TO SOLVE THE EXERCISE?

#define SW1 P2_1
#define SW2 P1_1

int leftbutton=0;
int rightbutton=0;
int buttonState =0;
int lastbuttonState=0;

void setup() {

pinMode(RED_LED , OUTPUT);
pinMode(GREEN_LED , OUTPUT);

pinMode(SW1 , INPUT_PULLUP);
pinMode(SW2, INPUT_PULLUP);
}

void loop() {
rightbutton=digitalRead(SW1);
leftbutton=digitalRead(SW2);

digitalWrite(RED_LED, HIGH);
digitalWrite(GREEN_LED , HIGH);
delay(250);
digitalWrite(RED_LED, LOW);
digitalWrite(GREEN_LED , LOW);
delay(250);

}

I DO THIS UNTIL NOW

moderator edit: code tags added

Hello @mpanis10 -
Adding a wiring diagram here will help understand how the buttons will act when pressed.

1 Like

@mpanis10, please do not cross-post. Threads merged.

1 Like

I made something to show how buttons, timing and events work. All you need to do is count the button presses inside a time interval.

A simulation...

And source...

#define SW2 P1_1

int leftbutton = 0;
int rightbutton = 0;

int buttonStateL = 0;
int buttonStateR = 0;

int lastbuttonStateL = 0;
int lastbuttonStateR = 0;

//****************************************
// for the simulation
// https://wokwi.com/projects/367172147215229953

#define P2_1 2 // redefine pin
#define P1_1 4 // redefine pin

#define RED_LED 5 // LED pin
#define GREEN_LED 3 // LED pin

bool RED_LED_state = HIGH;
bool GREEN_LED_state = HIGH;

// timers
int RED_LED_event = 800;
int GREEN_LED_event = 800;

// event new start timers
unsigned long RED_LED_previous_time = 0;
unsigned long GREEN_LED_previous_time = 0;

unsigned long currentMillis();
//****************************************

void setup() {
  Serial.begin(115200);
  welcome();

  Serial.print("RED ");
  Serial.print(RED_LED_event);
  Serial.print(" GREEN ");
  Serial.println(GREEN_LED_event);

  pinMode(RED_LED, OUTPUT);
  pinMode(GREEN_LED, OUTPUT);

  pinMode(SW1, INPUT_PULLUP);
  pinMode(SW2, INPUT_PULLUP);
}

void loop() {

  unsigned long currentTime = millis();  // start main timer

  if ( currentTime - RED_LED_previous_time >= RED_LED_event ) {  // check event timer
    RED_LED_state = !RED_LED_state; // change LED state
    digitalWrite(RED_LED, RED_LED_state); // write to LED pin
    RED_LED_previous_time = currentTime;    //update new start timer
  }

  if ( currentTime - GREEN_LED_previous_time >= GREEN_LED_event ) {  // check event timer
    GREEN_LED_state = !GREEN_LED_state; // change LED state
    digitalWrite(GREEN_LED, GREEN_LED_state); // write to LED pin
    GREEN_LED_previous_time = currentTime;    //update new start timer
  }

  rightbutton = digitalRead(SW1);
  leftbutton = digitalRead(SW2);

  if (!rightbutton) {
    delay(150); // debounce
    GREEN_LED_event = GREEN_LED_event - 50;
    Serial.print("RED ");
    Serial.print(RED_LED_event);
    Serial.print(" GREEN ");
    Serial.println(GREEN_LED_event);
    if (GREEN_LED_event < 201) {
      GREEN_LED_event = 1000;
      Serial.println(GREEN_LED_event);
    }
  }

  if (!leftbutton) {
    delay(150); // debounce
    RED_LED_event = RED_LED_event - 50;
    Serial.print("RED ");
    Serial.print(RED_LED_event);
    Serial.print(" GREEN ");
    Serial.println(GREEN_LED_event);
    if (RED_LED_event < 201) {
      RED_LED_event = 1000;
      Serial.println(RED_LED_event);
    }
  }
}

void welcome() {
  Serial.print("Frequency for each LED starts at ");
  Serial.print(RED_LED_event);
  Serial.println("ms.");
  Serial.println("Pressing either button reduces frequency by 50ms.");
  Serial.print("Reducing either frequency below 200ms resets frequency to ");
  Serial.print(RED_LED_event);
  Serial.println("ms.\n");
}

I write the code on Energia

HI, @mpanis10
Welcome to the forum.

Is this a school/college/university project?

Thanks... Tom... :smiley: :+1: :coffee: :australia:

university project

So is this your project idea, or a set task?
If a set task can yo please post the EXACT wording of the task sheet?

Can we please have a circuit diagram?
An image of a hand drawn schematic will be fine, include ALL power supplies, component names and pin labels.
We need to see how you have wired the LEDs and buttons.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

1 Like

#define SW1 P2_1
#define SW2 P1_1

int leftbutton=0;
int rightbutton=0;

int buttonState1 =0;
int buttonState2 =0;

int lastbuttonState1=0;
int lastbuttonState2=0;

int RED_LED_state = HIGH;
int GREEN_LED_state = HIGH;

int RED_LED_TIMER=500;
int GREEN_LED_TIMER=500;

unsigned long RED_LED_previous_time = 0;
unsigned long GREEN_LED_previous_time = 0;

void setup() {

pinMode(RED_LED , OUTPUT);
pinMode(GREEN_LED , OUTPUT);

pinMode(SW1 , INPUT_PULLUP);
pinMode(SW2, INPUT_PULLUP);
}

void loop() {
rightbutton=digitalRead(SW1);
leftbutton=digitalRead(SW2);

digitalWrite(RED_LED, HIGH);
digitalWrite(GREEN_LED , HIGH);
delay(250);
digitalWrite(RED_LED, LOW);
digitalWrite(GREEN_LED , LOW);
delay(250);

unsigned long currentTime = millis();

if ( currentTime - GREEN_LED_previous_time >= GREEN_LED_TIMER ) {
GREEN_LED_state = !GREEN_LED_state;
digitalWrite(GREEN_LED, GREEN_LED_state);
GREEN_LED_previous_time = currentTime;
}
if (leftbutton) {
delay(150); // Καθυστέρηση 150
GREEN_LED_TIMER = GREEN_LED_TIMER - 50;

if (GREEN_LED_TIMER < 200) {  
  GREEN_LED_TIMER = 1000; 
 
}

}

}

WRITE THIS CODE ON C WITH CODE COMPOSER STUDIO (CCS)

No thanks, will not do that.

Your topic has been moved to a more suitable location on the forum. See the topics in Uncategorized - Arduino Forum why you should not post where you posted and how to get the best out of this forum.

1 Like

Draw a diagram.
Indicate LED pins.
Indicate button pins.

The code works.
Looks familiar.

1 Like

Hi,
Cross post reported.

University project..

Tom... :smiley: :+1: :coffee: :australia:

I have merged your topics due to them having too much overlap on the same subject matter @mpanis10.

In the future, please only create one topic for each distinct subject matter and be careful not to cause them to converge into parallel discussions.

The reason is that generating multiple threads on the same subject matter can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Thanks in advance for your cooperation.

@mapneto, after you supply those items, you should next proceed to DO YOUR OWN WORK as expected of a university student!!!

Break it down into manageable sub tasks.

We are a few steps further :wink:

CCS is an IDE of Texas Instruments so I start wondering if this is still an Arduino question.

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;

When is the assignment due?

1 Like