A hardware innovation platform for makers to grow inspirations into differentiating products.


Buttons can be used as basic digital inputs for Microcontrollers. This program keeps the LED1 on as long as the button is pressed press.


  • Arch Board
  • Grove - Button


Import the following code to mbed online compiler

#include "mbed.h"

DigitalOut led(LED1);    // Configure LED1 pin as output
DigitalIn button(P1_14); // Configure P1_14 pin as input

int main()
    while(1) {
        led.write(;    /* read the state of input  pin P1_14 and write it to output port pin LED1*/

We use DigitalIn class to get the button's input. The function returns a value 1 if button is pressed and 0 if released. This value is written to LED1 using led.write().

More information of DigitalIn can be found at mbed handbook.

All wikipages