Libraries.Robots.BirdBrain.Microbit Documentation

The Microbit class allows the user to control a single BBC micro:bit. Use of this class requires a micro:bit which is running BirdBrain Technologies' firmware and is connected to the computer over bluetooth via the BlueBird Connector app (firmware and software available at https://learn.birdbraintechnologies.com/install-shortcuts/).

Example Code

use Libraries.Robots.BirdBrain.Microbit
class Main
action Main
   
   Microbit microbit

   //If the A button is being pressed, display a smiley face. Otherwise display a frown.
   if microbit:GetButton("A")
     microbit:SetDisplay("0000001010000001000101110")
   else
     microbit:SetDisplay("0000001010000000111010001")
   end

   microbit:Disconnect()

end
end

Inherits from: Libraries.Language.Object

Actions Documentation

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Disconnect()

This action closes the http connection to save memory. It should be used at the end of every program.

Example

use Libraries.Robots.BirdBrain.Microbit
Microbit microbit
microbit:Disconnect()

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)

GetAcceleration(text axis)

This action returns the acceleration in the given direction (X, Y, or Z) in meters per second squared.

Parameters

  • text axis: The direction of which the acceleration will be returned.

Return

number: Acceleration in meters per second squared.

Example

use Libraries.Robots.BirdBrain.Microbit
Microbit microbit
output "X Acceleration: " + microbit:GetAcceleration("x")
microbit:Disconnect()

GetButton(text button)

This action checks whether the specified micro:bit button is pressed. The function prints an error if the inputs are not in the specified range.

Parameters

  • text button: The button that will be checked (Range: "A", "B", "LOGO").

Return

boolean: true if the button is pressed and false otherwise.

Example

use Libraries.Robots.BirdBrain.Microbit
Microbit microbit
output "Button A: " + microbit:GetButton("A")
microbit:Disconnect()

GetCompass()

This action returns the direction in degrees from north.

Return

integer: The direction in degrees (Range: 0 to 360).

Example

use Libraries.Robots.BirdBrain.Microbit
Microbit microbit
output "Compass: " + microbit:GetCompass()
microbit:Disconnect()

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

GetMagnetometer(text axis)

This action returns the magnetometer value in the given direction (X, Y, or Z) in microtesla.

Parameters

  • text axis: The direction of which the magnetometer value will be returned.

Return

integer: Magnetometer value in microtesla.

Example

use Libraries.Robots.BirdBrain.Microbit
Microbit microbit
output "Z Magnetometer: " + microbit:GetMagnetometer("z")
microbit:Disconnect()

GetOrientation()

This action provides information about the device's current orientation.

Return

text: The orientation of the device. (Range: Screen up, Screen down, Tilt left, Tilt right, Logo up, or Logo down).

Example

use Libraries.Robots.BirdBrain.Microbit
Microbit microbit
output "Microbit Orientation: " + microbit:GetOrientation()
microbit:Disconnect()

GetSound()

This action returns the current sound level from the micro:bit sound sensor.

Return

integer: Sound level.

Example

use Libraries.Robots.BirdBrain.Microbit
Microbit microbit
output "Sound: " + microbit:GetSound()
microbit:Disconnect()

GetTemperature()

This action returns the current temperature in degrees Celsius from the micro:bit temperature sensor.

Return

integer: Temperature in degrees Celsius.

Example

use Libraries.Robots.BirdBrain.Microbit
Microbit microbit
output "Temperature: " + microbit:GetTemperature()
microbit:Disconnect()

IsShaking()

This action tells you whether the micro:bit is being shaken.

Return

boolean: A boolean value telling you the shake state.

Example

use Libraries.Robots.BirdBrain.Microbit
Microbit microbit
output "Is Shaking?: " + microbit:IsShaking()
microbit:Disconnect()

Microbit()

Output(text message)

This action lets the LED Array display a given message.

Parameters

  • text message: The message that will be displayed on the LED Array.

Example

use Libraries.Robots.BirdBrain.Microbit
Microbit microbit
microbit:Output("Hello world")
microbit:Disconnect()

Pause(number seconds)

This action pauses the program for a time in seconds.

Parameters

  • number seconds: Amount of time the program should pause.

Example

use Libraries.Robots.BirdBrain.Microbit
Microbit microbit
//Display a smiley face for 1 second
microbit:SetDisplay("0000001010000001000101110")
microbit:Pause(1)
microbit:SetDisplay("0000000000000000000000000")
microbit:Disconnect()

PlayNote(integer note, number beats)

This action sets the micro:bit buzzer to play the given note for the given duration.

Parameters

  • integer note: Midi note number to play (Range: 32 to 135).
  • number beats: Duration in beats (Range: 0 to 16); each beat is one second.

Example

use Libraries.Robots.BirdBrain.Microbit
Microbit microbit
//Play middle C for 1 beat.
microbit:PlayNote(60, 1)
microbit:Disconnect()

Print(text message)

This action lets the LED Array display a given message.

Parameters

  • text message: The message that will be displayed on the LED Array.

Example

use Libraries.Robots.BirdBrain.Microbit
Microbit microbit
microbit:Print("Hello world")
microbit:Disconnect()

SetDisplay(text ledValues)

This action lets the LED Array display a pattern based on an array of 1s and 0s.

Parameters

  • text ledValues: The list of integers that the function takes in to set the LED Array. 1 means on and 0 means off.

Example

use Libraries.Robots.BirdBrain.Microbit
Microbit microbit
//Display a smiley face on the micro:bit LED array
microbit:SetDisplay("0000001010000001000101110")
microbit:Disconnect()

SetPoint(integer row, integer column, integer value)

This action turns on or off a single LED on the micro:bit LED array.

Parameters

  • integer row
  • integer column
  • integer value: The value of the LED (0 for off, 1 for on).

Example

use Libraries.Robots.BirdBrain.Microbit
Microbit microbit
// Turn on the middle LED of the LED array.
microbit:SetPoint(3, 3, 1)
microbit:Disconnect()

StopAll()

This action turns off all the outputs.

Example

use Libraries.Robots.BirdBrain.Microbit
Microbit microbit
microbit:StopAll()
microbit:Disconnect()