Ardublock/Arduino Reference Library

The Arduino programming language is the main language used to program Arduino and Arduino-based microcontroller boards like Hummingbird Duo. The language is a simplified version of the Java programming language applied to the specific needs of creating programs for microcontrollers. It is much easier than Java to get started with, and due to the code converters built into the CREATE Lab Visual Programmer and Ardublock, it is even possible to begin by composing a program in a graphical environment as a starting point.

Ardublock is a blocks-based graphical environment for creating Arduino programs. Those who have experience using Scratch 2.0 or Snap! with Hummingbird will find many of Ardublock’s programming structures familiar. As Ardublock allows users to see the Arduino code behind the blocks, and as it allows downloading of the program to the Hummingbird Duo, it is a great next step for those who are familiar with Scratch or Snap! Programming.

Ardublock was developed by David Li and HE Qichen. Our branch of Ardublock has been customized for Hummingbird Duo.

Ardublock

 

Ardublock BlocksThe core Ardublock blocks are divided into categories described below. Each block provides a helpful hint as to its function when you hover over it with a mouse.

  • Control: These blocks determine the logical flow of a program; blocks include structures like delay, loop, while, and if/else.
  • Pins: These blocks provide control over the Arduino side pins. You do not need them if working with the Hummingbird Duo’s top-side connectors.
  • Tests: These blocks contain logical tests, such as whether one number is less than or greater than another.
  • Math Operators: These blocks allow you to perform mathematical operations like +,-,*,/, as well as absolute value, modulus, and more.
  • Variables/Constants: These blocks contain constant number blocks, as well as ways to set different types of variables (integers, floats, chars) to specific values.
  • Communication: These blocks provide ways to send information over serial or I2C ports.
  • Storage: These blocks provide access to an Arduino’s permanent EEPROM memory storage.
  • Code Blocks: These blocks allow you to write custom Arduino code into your Ardublock program.

Duo Block Descriptions

Ardublock Duo Block DescriptionsIn addition to the core Ardublock blocks, our version of Ardublock also contains a number of blocks used for reading Duo sensors and setting Duo outputs. These are:

  • LED: Sets the brightness of one of the four single color LED ports with an intensity ranging from 0 to 255.
  • TRI-COLOR LED: Sets the brightness and color of one of the two tri-color LED ports with red, green, and blue intensities ranging from 0 to 255.
  • STATUS: Sets the brightness of the Duo’s green STATUS LED with an intensity ranging from 0 to 255.
  • MOTOR: Sets the direction and speed of one of Duo’s two gear motor ports. Negative velocity values cause the motor to spin in the opposite direction of positive velocity values.
  • SERVO: Sets the angle of one Duo’s four servo ports from 0 degrees to 180 degrees.
  • VIBRATION: Sets the intensity of vibration from 0 to 255 for one of Duo’s two vibration motor ports.
  • SENSOR: Reads the raw value of one of Duo’s four sensor ports. This value ranges from 0 to 1023, with 0 corresponding to 0 volts, and 1023 corresponding to 5 volts.
  • SYSTEM VOLTAGE: Reads the voltage of the Duo’s Auxiliary Power port. The value returned is a floating point value from 0.0 to 10.0 volts. Values below 2.0 generally mean no power supply is attached. This can be used for low battery warning if the Duo is being powered solely from this port.

Arduino

 

Initialization

void init()
Fully initializes the Hummingbird. By default it will set as outputs all LED and Vibration motor pins (Arduino pins 2 to 12), it will also enable intensity control for LEDs (using Timer 3) and for vibration motors (using Timer 1). This is the recommended initialization method if you use Hummingbird Duo only with top side connectors.

void initOnlyMotorsAndServos()
Initializes just the SPI communication with Hummingbird’s integrated motor/servo controller. All regular Arduino pins except for digital I/O pin 8 are left alone. Pin 8 is the slave select line for SPI communication with the motor/servo controller and is set to output. This is the recommended initialization method if you use Hummingbird Duo with Arduino shields, even if you also connect some kit components to the top side connectors.

void init(boolean turnOnLEDFading, boolean turnOnVibrationSpeed, boolean turnOnLEDandVibrationOutputs)
Provides user control over specific initialization steps.
Parameters:

  • turnOnLEDFading: Initializes software interrupt on Timer 3 that provides intensity control of the LEDs. If this is not initialized, the LED functions only turn LEDs on or off and Timer 3 is free for user control.
  • turnOnVibrationSpeed: Initializes speed control over the vibration motors, using Timer 1. If this is not initialized, the vibration motors can only be turned on or off and Timer 1 is free for user control.
  • turnOnLEDandVibrationOutputs: Sets Arduino pins 2-7 and 9-13 as outputs.

LEDs

void setLED(byte port, byte intensity)
Sets the intensity of the LED on port 1, 2, 3, or 4.
Parameters:

  • port: The LED’s port: 1, 2, 3, or 4.
  • intensity: The intensity of light from the LED, 0 is off, 255 is fully on. If LED fading is turned off, all non-zero values will result in the LED being fully on.

void setStatusLED(byte intensity)
Sets the intensity of the green status LED (also tied to ‘L’ LED on the Arduino side).
Parameter:

  • intensity: The intensity of light from the LED, 0 is off, 255 is fully on. If LED fading is turned off, all non-zero values will result in the LED being fully on.

void setTriColorLED(byte port, byte red, byte green, byte blue)
Sets the color and brightness of the tri-color LED on port 1 or 2.
Parameters:

  • port: The LED’s port: 1 or 2.
  • red: The intensity of red light from the LED, 0 is off, 255 is fully on. If LED fading is turned off, all non-zero values will result in the red LED being fully on.
  • green: The intensity of green light from the LED, 0 is off, 255 is fully on. If LED fading is turned off, all non-zero values will result in the green LED being fully on.
  • blue: The intensity of blue light from the LED, 0 is off, 255 is fully on. If LED fading is turned off, all non-zero values will result in the blue LED being fully on.

void turnOnLEDFade() and void turnOffLEDFade()
Turns on or off fading control over the LEDs.

Motors and Servos

void setMotor(byte port, int power)
Sets the power to a gear motor on port 1 or 2.
Parameters:

  • port: The gear motor’s port: 1 or 2.
  • power: The power sent to the motor, the range is -255 to 255: 0 is off, 255 is full speed in one direction, -255 is full speed in the other direction. The motor has a dead zone where it will not spin for values between approximately -30 to 30.

void setServo(byte port, byte degrees)
Sets the angle of the servo on ports 1, 2, 3 or 4.
Parameters:

  • port: The servo’s port: 1, 2, 3, or 4.
  • degrees: The servo angle, specified in degrees, with a range of 0 to 180.

void setVibration(byte port, byte intensity)
Sets the intensity of the vibration motor on port 1 or 2.
Parameters:

  • port: The vibration motor’s port: 1 or 2.
  • intensity: The speed of the vibration motor, 0 is off, 255 is fully on. If vibration motor speed control is turned off, all non-zero values will result in full speed for the motor.

void turnOnVibrationMotorSpeed() and void turnOffVibrationMotorSpeed()
Turns speed control on or off for vibration motors.

Sensors

float readInputVoltage()
Returns a reading in volts of the voltage of VIN. Voltages higher than 10V will read as 10V.

int readSensorValue(byte port)
Reads the analog value at the port specified. Values can range from 0 to 1023, with 0 corresponding to 0V and 1023 corresponding to 5V.
Parameter:

  • port: The sensor’s port: 1, 2, 3, or 4.