Jump to content
Jakey319

MSP432 Energia bug: Button.ino example, adding delay over 250ms breaks sketch

Recommended Posts

In the standard Button example in Energia (Examples->02.Digital->Button), it works fine when I upload it to the MSP432P401R. But if I add a delay to the loop that is greater than 250ms, then the LED that's supposed to turn back on when the button is released, never turns back on.

If the delay is less than 250ms, then the sketch works as expected.

Why do you think this happens?

const int buttonPin = PUSH2;     // the number of the pushbutton pin
const int ledPin =  GREEN_LED;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT_PULLUP);     
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }
  delay(500); //BUG: when this is here, then the LED never turns back on
}

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×