Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

Button use

$
0
0

Hi everybody,

 

I'm new here and beginner in programming both C and MSP430.

 

I'm trying to understand how to use the button on the TI MSP430 launchpad.

 

The goal is only to light on the green LED when I press the button.

 

The button on the board is labelled P1.3. Therefore I suppose it's connected on the bit 3 of port 1.

 

I wrote the following code in Energia, but the green LEDs is off, and nothing happens when I push the button.

#define RedOn P1OUT |= 0b00000001
#define GreenOn P1OUT |= 0b01000000
#define RedOff P1OUT &= 0b11111110
#define GreenOff P1OUT &= 0b10111111

int main()
{
  P1DIR |= 0b00000001; // 1.0 = Output, red LED
  P1DIR |= 0b01000000; // 1.6 = Output, green LED
  P1DIR &= 0b11110111; // 1.3 = Input, push button
 
  // Test : At first, only the red LED should be on
  RedOn;
  GreenOff;
  
  while(1)
  {
    if (P1IN & 0b00001000 != 0)
    {
      GreenOff;
    }
    else
    {
      GreenOn;
    }
  }
}

What is wrong with this code ? Is the bit #3 test not correct ? Isn't it the P1.3 I should use ?

 

Also, I prefer to not use "Arduino style" coding, with functions like digitalWrite and digitalRead.

 

Thanks in advance for any help.

 

Tom


Viewing all articles
Browse latest Browse all 2077

Trending Articles