INTRODUCTION
If you’re Arduino user and want to try micro:bit, you can program your micro:bit using Arduino IDE. In this tutorial, I will share with how to setup and program your micro:bit using Arduino IDE.
VIDEO
This video shows how to program your micro:bit using Arduino IDE
HARDWARE PREPARATION
This is the list of items used in the video.
Sample Code
micro:bit board json link
https://sandeepmistry.github.io/arduino-nRF5/package_nRF5_boards_index.json
You can use following code for controlling LED and read push button status (basic lesson).
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; | |
} | |
} |
Thank You
References:
Thanks for reading this tutorial. If you have any technical inquiry, please post at Cytron Technical Forum.