Public Hummingbird Methods
NOTE: If you issue Bluetooth commands very close together (< 100 ms), it is possible that some commands may be skipped. For example, if you set the color of the tri-color LED to green and then immediately set it to red, you may not see the effect of the green command.
setLED(port: Int, intensity: Int)
Description: Sets an LED to a given intensity value. The method requires the port number of the LED (1-3) and an intensity value from 0-100. An intensity value of 0 turns the LED off.
setTriLED(port: Int, red: Int, green: Int, blue: Int)
Description: Sets a tri-color LED to a given color by setting the intensities of the red, green, and blue elements inside it . The method requires the port number of the tri-color LED (1-2) and three intensity values from 0-100. Setting all three intensity values to 0 turns the LED off.
hummingbird.setTriLED(1, 75, 0, 75)
setPositionServo(port: Int, angle: Int)
Description: Sets a position servo to a given angle. The method requires the port number of the servo (1-4) and an angle from 0°-180°.
setRotationServo(port: Int, speed: Int)
Description: Sets a rotation servo to spin at a given speed. The method requires the port number of the servo (1-4) and a speed between -100 and 100. A speed of 0 turns the motor off.
playNote(note: Int, beats: Double)
Description: Plays a note using the buzzer on the Finch. The method requires an integer representing the note (32-135) and a number giving the number of beats (0-16). The number of beats can be a decimal number.
Description: Sets the LED array of the micro:bit to display a pattern defined by an array. Each value in the array must be 0 (off) or 1 (on). The first five values in the array correspond to the five LEDs in the first row, the next five values to the second row, etc.
Description: Print a string on the micro:bit LED array. The string must have 15 or fewer characters and should contain only digits and English letters (upper or lower case).
Description: Stops all outputs. This includes the LED display for the micro:bit and all lights and motors for the Hummingbird.
Description: This function sends a Bluetooth command to calibrate the compass. When the Hummingbird receives this command, it will place dots on the micro:bit screen as it waits for you to tilt the Hummingbird in different directions. If the calibration is successful, you will then see a check on the micro:bit screen. Otherwise, you will see an X.
Hummingbird Sensor State
You can access the following within the
timestamp: Date Time of the sensor reading
batteryVoltage: Float Voltage of Hummingbird battery
isStale: Boolean True when data is out of date
sensor1: HummingbirdSensor Value of the Hummingbird sensor in port 1. Each of the Hummingbird sensor ports supports different types of sensors, so this value has a data type HummingbirdSensor that computes all of the possibilities.
sensor1.distance: Intif you are using a distance sensor in port 1. This value is the distance in centimeters.
sensor1.dial: Intif you are using the dial. This value is between 0 and 100.
sensor1.light: Intif you are using the light sensor. This value is between 0 and 100.
sensor1.voltage: Doubleif you want the voltage at the port, which is between 0 and 3.3 V.
sensor2: HummingbirdSensor Value of the Hummingbird sensor in port 2. See the options for
sensor3: HummingbirdSensor Value of the Hummingbird sensor in port 3. See the options for
acceleration: Array<Double> Acceleration in m/s2 in the x, y, and z directions
magnetometer: Array<Double> Magnetometer readings in µT in the x, y, and z directions
compass: Int? Degrees from North; undefined when acceleration in the z direction is 0
buttonA: Boolean True when button A is pressed
buttonB: Boolean True when button B is pressed
shake: Boolean True when Hummingbird is being shaken