Show Menu
Cheatography

Code BBC Micro:bit from Arduino IDE Cheat Sheet by

Explanation of how code BBC Micro:bit from Arduino IDE.

1. Start Arduino IDE

Start your Arduino IDE, then click on the Prefer­ences.

Prefer­ences.

2. Add the URL

Additional Board Manager URL

3. Open Tools

Open Tools>­Boa­rd>­Boards Manager from the menu bar, search for nRF5 and install “Nordic Semico­nductor nRF5 Boards” by Sandeep Mistry

4. Select Micro:bit

Select Micro:bit Select BBC micro:bit from the Boards menu. Set SoftDevice to S110. And set the Port to the Micro:bit COM port.

5. Upload the code

Upload the code to your Micro:bit. Don't worry about the red warnings below. Open the Serial Monitor and push the button of your Micro:bit. Enjoy!

Code </>

/*
Plugga Studios Tutorial for Micro:bit
Follow on Instagram for more!
*/
const int COL1 = 3; // Column #1 control
const int LED = 26; // 'row 1' led

const int BUTTON_A = 5; // The number of the pushbutton pin
const int BUTTON_B = 11; // The number of the pushbutton pin

long previousMillis = 0;
long currentMillis = 0;
int interval = 500;
boolean ledState = false;
boolean buttonAPressed = false;
boolean buttonBPressed = false;

void setup()
{
  Serial.begin(9600);

  Serial.println("microbit is ready!");

  pinMode(BUTTON_A, INPUT);
  pinMode(BUTTON_B, INPUT);

  // Because the LEDs are multiplexed,
  // we must ground the opposite side of the LED
  pinMode(COL1, OUTPUT);
  digitalWrite(COL1, LOW);

  pinMode(LED, OUTPUT);
}

void loop()
{
  currentMillis = millis();
  if (currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;

    ledState = !ledState;
    digitalWrite(LED, ledState);
  }
  
  if (digitalRead(BUTTON_A) == LOW &&
      buttonAPressed == false) {
    buttonAPressed = true;

    Serial.println("Button A is pressed.");
  }
  else if (digitalRead(BUTTON_A) == HIGH &&
      buttonAPressed == true) {
    buttonAPressed = false;
  }

  if (digitalRead(BUTTON_B) == LOW &&
      buttonBPressed == false) {
    buttonBPressed = true;

    Serial.println("Button B is pressed.");
  }
  else if (digitalRead(BUTTON_B) == HIGH &&
      buttonBPressed == true) {
    buttonBPressed = false;
  }
}
           

Help Us Go Positive!

We offset our carbon usage with Ecologi. Click the link below to help us!

We offset our carbon footprint via Ecologi
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Sublime Text 2 Windows Keyboard Shortcuts
          Oracle SQL Developer Keyboard Shortcuts
          ISTQB Test Automation Engineering Cheat Sheet

          More Cheat Sheets by Plugga

          BBC Micro:bit coding from Arduino IDE Cheat Sheet