This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Buttons on the mbed TestBed

So we wrote this program in class that's supposed to turn one of the LEDs on the LPC1768 on/off using the buttons on the TestBed. My question is in regards to how the bits in the FIOPIN register change when the buttons are pressed.
This is the program:

LPC_PINCON->PINSEL3 = LPC_PINCON->PINSEL3 & 0xFFFFFCF; //setting LED as GPIO
LPC_GPIO1->FIODIR = LPC_GPIO1->FIODIR |(1<<18); //setting LED as output
LPC_GPIO1->FIOSET = LPC_GPIO1->FIOSET| (1<<18); //Turning LED on(This line may be redundant at this position)
//the buttons BTN1 and BTN2 are by default set to input

while(1){
    if ((((LPC_GPIO0->FIOPIN)>>16)&0x1)==0){
        wait(200); //debounce
        LPC_GPIO1->FIOSET |= (1<<LED0);
    }
    else if(!(((LPC_GPIO0->FIOPIN)>>6)&0x1)){
        wait(200); //debounce
        LPC_GPIO1->FIOCLR |= (1<<LED0);
    }

Based on my understanding of how the buttons work, this is how I assume the program will run:
PS: BTN1 is at P0.6 and BTN2 is at P0.16
1. When the program starts(before any buttons are pressed) FIOPIN bits 6 and 16 are both 0. So the LED is on.
2. Assume we press BTN2. Then FIOPIN bit 6 is 0, and bit 16 is 1, so LED turns off.
3. Now press BTN1. Bit 6 is now 1 and bit 16 is still 1. LED is still off.
4. Press BTN2. Bit 6 is still 1, but bit 16 is now 0. LED will turn on.

Is this correct?
PS: I don't have access to the microcontroller at home, that's why I'm assuming and simulating what would/might happen if so and so.

My assumption is that the buttons aren't press and hold buttons, i.e. when you press a button it's state(1/0) gets changed in the FIOPIN register till it gets pressed again.