Libraries.Robots.BirdBrain.Hummingbird Documentation

The Hummingbird class allows the user to control a single Hummingbird robotics kit from BirdBrain Technologies. Use of this class requires a Hummingbird 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.Hummingbird
class Main
action Main
   
   Hummingbird hummingbird

   //wave a servo attached to port 1
   repeat 4 times
     hummingbird:SetPositionServo(1, 90)
     hummingbird:Pause(1)
     hummingbird:SetPositionServo(1, 180)
     hummingbird:Pause(1)
   end

   hummingbird: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.Hummingbird
Hummingbird hummingbird
hummingbird: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.Hummingbird
Hummingbird hummingbird
output "X Acceleration: " + hummingbird:GetAcceleration("x")
hummingbird: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.Hummingbird
Hummingbird hummingbird
output "Button A: " + hummingbird:GetButton("A")
hummingbird: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.Hummingbird
Hummingbird hummingbird
output "Compass: " + hummingbird:GetCompass()
hummingbird:Disconnect()

GetDial(integer port)

This action returns dial value at a given port after processing the raw sensor value retrieved.

Parameters

  • integer port: The port that the dial is attached to (Range: 1 to 3).

Return

integer: The dial value.

Example

use Libraries.Robots.BirdBrain.Hummingbird
Hummingbird hummingbird
output "Hummingbird Dial on port 1: " + hummingbird:GetDial(1)
hummingbird:Disconnect()

GetDistance(integer port)

This action returns distance sensor value at a given port after processing the raw sensor value retrieved.

Parameters

  • integer port: The port that the sound sensor is attached to (Range: 1 to 3).

Return

integer: The distance sensor value.

Example

use Libraries.Robots.BirdBrain.Hummingbird
Hummingbird hummingbird
output "Hummingbird Distance on port 3: " + hummingbird:GetDistance(3)
hummingbird: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()

GetLight(integer port)

This action returns light sensor value at a given port after processing the raw sensor value retrieved.

Parameters

  • integer port: The port that the light sensor is attached to (Range: 1 to 3).

Return

integer: The light sensor value.

Example

use Libraries.Robots.BirdBrain.Hummingbird
Hummingbird hummingbird
output "Hummingbird Light on port 1: " + hummingbird:GetLight(1)
hummingbird:Disconnect()

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.Hummingbird
Hummingbird hummingbird
output "Z Magnetometer: " + hummingbird:GetMagnetometer("z")
hummingbird: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.Hummingbird
Hummingbird hummingbird
output "Microbit Orientation: " + hummingbird:GetOrientation()
hummingbird:Disconnect()

GetSound(integer port)

This action returns sound sensor value at a given port after processing the raw sensor value retrieved.

Parameters

  • integer port: The port that the sound sensor is attached to (Range: 1 to 3).

Return

integer: The sound sensor value.

Example

use Libraries.Robots.BirdBrain.Hummingbird
Hummingbird hummingbird
output "Hummingbird Sound on port 2: " + hummingbird:GetSound(2)
hummingbird:Disconnect()

GetSound()

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

Return

integer: Sound level.

Example

use Libraries.Robots.BirdBrain.Hummingbird
Hummingbird hummingbird
output "Sound: " + hummingbird:GetSound()
hummingbird: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.Hummingbird
Hummingbird hummingbird
output "Temperature: " + hummingbird:GetTemperature()
hummingbird:Disconnect()

GetVoltage(integer port)

This action returns voltage value at a given port after processing the raw sensor value retrieved.

Parameters

  • integer port: The port that the dial is attached to (Range: 1 to 3).

Return

number: The voltage value.

Example

use Libraries.Robots.BirdBrain.Hummingbird
Hummingbird hummingbird
output "Hummingbird Voltage on port 1: " + hummingbird:GetVoltage(1)
hummingbird:Disconnect()

Hummingbird()

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.Hummingbird
Hummingbird hummingbird
output "Is Shaking?: " + hummingbird:IsShaking()
hummingbird:Disconnect()

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.Hummingbird
Hummingbird hummingbird
hummingbird:Output("Hello world")
hummingbird: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.Hummingbird
Hummingbird hummingbird
//Display a smiley face for 1 second
hummingbird:SetDisplay("0000001010000001000101110")
hummingbird:Pause(1)
hummingbird:SetDisplay("0000000000000000000000000")
hummingbird: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.Hummingbird
Hummingbird hummingbird
//Play middle C for 1 beat.
hummingbird:PlayNote(60, 1)
hummingbird: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.Hummingbird
Hummingbird hummingbird
hummingbird:Print("Hello world")
hummingbird: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.Hummingbird
Hummingbird hummingbird
//Display a smiley face on the micro:bit LED array
hummingbird:SetDisplay("0000001010000001000101110")
hummingbird:Disconnect()

SetLED(integer port, integer intensity)

This action sets the LED at a given port to a specific light intensity.

Parameters

  • integer port: The port that the LED is attached to (Range: 1 to 3).
  • integer intensity: The intensity of the LED (Range: 0 to 100).

Example

use Libraries.Robots.BirdBrain.Hummingbird
Hummingbird hummingbird
//Set the LED attached to port 1 to the maximum brightness
hummingbird:SetLED(1, 100)
hummingbird: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.Hummingbird
Hummingbird hummingbird
// Turn on the middle LED of the LED array.
hummingbird:SetPoint(3, 3, 1)
hummingbird:Disconnect()

SetPositionServo(integer port, integer angle)

This action sets the position servo at a given port to a specific angle.

Parameters

  • integer port: The port that the position servo is attached to (Range: 1 to 4).
  • integer angle

Example

use Libraries.Robots.BirdBrain.Hummingbird
Hummingbird hummingbird
//Set the servo attached to port 1 to 90 degrees
hummingbird:SetPositionServo(1, 90)
hummingbird:Disconnect()

SetRotationServo(integer port, integer speed)

This action sets the rotation servo at a given port to a specific speed.

Parameters

  • integer port: The port that the rotation servo is attached to (Range: 1 to 4).
  • integer speed: The speed of the rotation servo (Range: -100 to 100).

Example

use Libraries.Robots.BirdBrain.Hummingbird
Hummingbird hummingbird
//Set the servo attached to port 2 to 50% speed
hummingbird:SetRotationServo(2, 50)
hummingbird:Disconnect()

SetTriLED(integer port, integer red, integer green, integer blue)

This action sets the triLED at a given port to a specific color.

Parameters

  • integer port: The port that the LED is attached to (Range: 1 to 2).
  • integer red: The intensity of red light of the triLED (Range: 0 to 100).
  • integer green: The intensity of green light of the triLED (Range: 0 to 100).
  • integer blue: The intensity of blue light of the triLED (Range: 0 to 100).

Example

use Libraries.Robots.BirdBrain.Hummingbird
Hummingbird hummingbird
//Set the LED attached to port 1 to bright white
hummingbird:SetTriLED(1, 100, 100, 100)
hummingbird:Disconnect()

StopAll()

This action turns off all the outputs.

Example

use Libraries.Robots.BirdBrain.Hummingbird
Hummingbird hummingbird
hummingbird:StopAll()
hummingbird:Disconnect()