Microbit Class Methods

 

Constructors

Method Signature: public Microbit()
Description: Constructor that creates an object corresponding to a micro:bit. This method assumes that the micro:bit is the only device connected in the BlueBird Connector.
Example: myBit = new Microbit();

Method Signature: public Microbit(String device)
Description: Constructor that creates an object corresponding to a micro:bit. This method requires a string equal to “A”, “B”, or “C” that specifies the letter of the device in the BlueBird Connector.
Example: myBit = new Microbit("A");

Output Methods

Method Signature: public void setDisplay(int[] ledValues)
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.
Example: int patternArray[] = {0,0,0,0,0,1,1,1,1,1,0,0,1,0,0,1,1,1,1,1,0,0,0,0,0};
myBit.setDisplay(patternArray);

Method Signature: public void setPoint(int row, int column, int value)
Description: Turn on or off a single LED on the micro:bit display. The position of the LED is given by the row and column parameters, which should both be between 1 and 5. The value of the LED must be 0 (off) or 1 (on).
Example: myBit.setPoint(3,3,1);

Method Signature: public void print(String message)
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).
Example: myBit.print("hello");

Method Signature: public void playNote(int note, double beats)
Description: Plays a note using the buzzer on the micro:bit. The method requires a integer representing the note (32-135) and a double giving the number of beats (0-16). One beat corresponds to one second. If you are using a micro:bit without a Hummingbird, this function can only be used with the micro:bit V2.
Example: myBit.playNote(60,0.5);

Method Signature: public void stopAll()
Description: Stops all outputs. This includes the LED display for the micro:bit and all lights and motors for the Hummingbird Bit.
Example: myBit.stopAll();

Input Methods

Method Signature: public boolean getButton(String button)
Description: Takes a string corresponding to a micro:bit button (“A”, “B”, or “Logo”) and returns a boolean value that is true if the button is being pressed, and false otherwise. The Logo button is only present on a micro:bit V2, so this option cannot be used with a micro:bit V1.
Example: System.out.println("Button A is pressed: " + myBit.getButton("A"));

Method Signature: public boolean isShaking()
Description: Returns a boolean that indicates whether or not the micro:bit is shaking.
Example: System.out.println("Shake Status: " + myBit.isShaking());

Method Signature: public String getOrientation()
Description: Returns a string that represents the orientation of the micro:bit. The possible values are “Screen up”, “Screen down”, “Tilt left”, “Tilt right”, “Logo up”, “Logo down”, and “In between”.
Example: System.out.println("Orientation: " + myBit.getOrientation());

Method Signature: public double[] getAcceleration()
Description: Returns an array that contains the acceleration in m/s2 in the x, y, and z directions.
Example: System.out.println("Acceleration in x-direction: " + myBit.getAcceleration()[0]);

Method Signature: public int getCompass()
Description: Returns the direction of the micro:bit in degrees from magnetic north (0°-359°). The compass should be calibrated in the BlueBird Connector before using this method.
Example: System.out.println("Compass Heading: " + myBit.getCompass());

Method Signature: public int[] getMagnetometer()
Description: Returns an array that contains the value of the magnetic field in µT in the x, y, and z directions. The compass should be calibrated in the BlueBird Connector before using this method.
Example: System.out.println("Magnetic Field in x-direction: " + myBit.getMagnetometer()[0]);

Method Signature: public int getSound()
Description: Returns the sound measured by the micro:bit. The sound measurement is an integer between 0 and 100 (arbitrary units). This function can only be used with the micro:bit V2.
Example: System.out.println("Sound: " + bird.getSound());

Method Signature: public int getTemperaure()
Description: Returns the temperature in degrees Celsius measured by the micro:bit. This function can only be used with the micro:bit V2.
Example: System.out.println("Temperature: " + bird.getTemperature());

Other

Method Signature: public void pause(double numSeconds)
Description: Pauses the program for a number of seconds.
Example: myBit.pause(1.5);

Method Signature: public void disconnect()
Description: Closes the http connection to the micro:bit. This method should be called at the end of each program.
Example: myBit.disconnect();

Hummingbird Class Methods

 
Hummingbird is a subclass of Microbit

Constructors

Method Signature: public Hummingbird()
Description: Constructor that creates an object corresponding to a Hummingbird Bit. This method assumes that the Hummingbird Bit is the only device connected in the BlueBird Connector.
Example: myBit = new Hummingbird();

Method Signature: public Hummingbird(String device)
Description: Constructor that creates an object corresponding to a Hummingbird Bit. This method requires a string equal to “A”, “B”, or “C” that specifies the letter of the device in the BlueBird Connector.
Example: myBit = new Hummingbird("A");

Output Methods

Method Signature: public void setLED(int port, int intensity)
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.
Example: myBit.setLED(1,100);

Method Signature: public void setTriLED(int port, int redIntensity, int greenIntensity, int blueIntensity)
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.
Example: myBit.setTriLED(1,75,0,75);

Method Signature: public void setPositionServo(int port, int angle)
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°.
Example: myBit.setPositionServo(1,90);

Method Signature: public void setRotationServo(int port, int speed)
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.
Example: myBit.setRotationServo(1,100);

Method Signature: public void playNote(int note, double beats)
Description: Plays a note using the buzzer on the Hummingbird Bit. The method requires a integer representing the note (32-135) and a double giving the number of beats (0-16). One beat corresponds to one second.
Example: myBit.playNote(60,0.5);

Input Methods

Method Signature: public int getLight(int port)
Description: Takes an integer corresponding to the sensor port (1-3) and returns the intensity measured by the light sensor. The light measurement is a an integer between 0 and 100 (arbitrary units).
Example: System.out.println("Light Sensor: " + myBit.getLight(1));

Method Signature: public int getDial(int port)
Description: Takes an integer corresponding to the sensor port (1-3) and returns the position of the dial sensor. The dial position is a an integer between 0 and 100 (arbitrary units).
Example: System.out.println("Dial Sensor: " + myBit.getDial(1));

Method Signature: public int getDistance(int port)
Description: Takes an integer corresponding to the sensor port (1-3) and returns the distance in centimeters measured by the distance sensor. The sensor detects distance most accurately in the range of 2-200 cm.
Example: System.out.println("Distance Sensor: " + myBit.getDistance(1));

Method Signature: public int getSound(int port)
Description: Takes an integer corresponding to the sensor port (1-3) and returns the intensity measured by the sound sensor. The sound measurement is a an integer between 0 and 100 (arbitrary units).
Example: System.out.println("Sound Sensor: " + myBit.getSound(1));

Method Signature: public double getVoltage(int port)
Description: Takes an integer corresponding to the sensor port (1-3) and returns the voltage measured by any sensor. The voltage measurement is a double between 0 and 3.3 V.
Example: System.out.println("Sensor Voltage: " + myBit.getVoltage(1));

Back to Top