Cheatography
https://cheatography.com
Explanation of how code BBC Micro:bit from Arduino IDE.
1. Start Arduino IDE
Start your Arduino IDE, then click on the Preferences. |
2. Add the URL
Add the URL below into the Additional Board Manager URL text box. |
|
Additional Board Manager URL
3. Open Tools
Open Tools>Board>Boards Manager from the menu bar, search for nRF5 and install “Nordic Semiconductor 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;
}
}
|
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by Plugga