Buttons

Create a new sketch and upload the following code to read the button presses in the Serial Console

const int buttonA = 5;     // the number of the pushbutton pin
const int buttonB = 11;     // the number of the pushbutton pin

void setup() {  
  Serial.begin(9600);
  
  Serial.println("microbit is ready!");
  
  pinMode(buttonA, INPUT);  
  pinMode(buttonB, INPUT);   
}

void loop(){
  if (! digitalRead(buttonA)) {
    Serial.println("Button A pressed");
  }
  if (! digitalRead(buttonB)) {
    Serial.println("Button B pressed");
  }
  delay(10);
}

Open up the Serial console at 9600 baud and press the reset button on the back of the microbit to restart the software

You will see the welcome message and then try pressing some buttons!

Last updated on 2017-09-27 at 01.05.00 PM Published on 2017-09-27 at 01.15.13 PM