Strawbees CODE Documentation

    Strawbees CODE flow and block code documentation for Quirkbot.

    Strawbees CODE Overview

    Diversity of programming languages and paradigms is important because there is no programming language is better than the others. On Strawbees CODE learn to create code in 3 ways as different languages are great for different kinds of problems.

    Block and flow is visual programming. Block programming is connecting Scratch-based blocks while flow is a network of boxes, also known as nodes, continuously sending data. The colorful nature of the blocks and nodes makes it easier to describe the process of what’s happening with the Quirkbot on screen. Text is a traditional method of writing programs. On Strawbees CODE text is written as C++ text like a regular Arduino compatible board.

    Sensing the World

    Using Quirkbot enables interactive systems to be created. When programming generally you will use a combination of the color-coded node categories, Input, Brains, and Output to make your system do what you want.

    Block Programming

    Block programming is snapping drag-and-drop blocks together to create scripts. These scripts are composed to create a sequential, step-by-step set of instructions similar to Scratch blocks.

    Block Categories

    The blocks on Strawbees CODE is based on MIT Media Lab’s Scratch blocks. Refer to the Scratch Wiki for more extensive information about the blocks.

    Input Blocks

    Nodes getting information from the physical world.

    Is Touched

    Parameters

    • place -  The physical place (horn, left arm, right arm, left leg, or right leg) to trigger circuit touch on the Quirkbot.

    Value of Circuit Touch

    Parameters

    • place -  The physical place (horn, left arm, right arm, left leg, or right leg) to trigger circuit touch based on value of how much pressure is applied on the Quirkbot's pad.

    Value of Light Sensor

    Parameters

    • place -  The physical place (horn, left arm, right arm, left leg, or right leg) the light sensor is based on value of how much light the Quirkbot senses.

    Parameters

    • place -  The physical place (horn, left arm, right arm, left leg, or right leg) for the light sensor to determine the value of how much light is present or absence of.

    Output Blocks

    Blocks with the ability to control something in the physical world.

    Set Servo Position

    Parameters

    • place - Where the servo (1 or 2) is connected. Connection requires the servo backpack.
    • position - Set the position of the Servo Motor, 0 = Min, 1 = Max, 0.5 = Middle.

    Transition Servo Position Over Time

    Parameters

    • place - Where the servo (1 or 2) is connected. Connection requires the servo backpack.
    • position -  The position ranging from 0 to 1.
    • duration - The duration of the transition, in seconds.
    • easing - The “shape” of the transition (linear, sine, quad, cubic, quart, quint, expo, circ, back, elastic, or bounce).

    Set Continuous Servo Speed

    Parameters

    • place - Where the continuous servo (1 or 2) is connected. Connection requires the servo backpack.
    • speed - Control the rotation speed of the servo from 0 to 1.

    Set Continuous Servo Direction

    Parameters

    • place - Where the continuous servo (1 or 2) is connected. Connection requires the servo backpack.
    • direction - Control the direction of the rotation of the continuous servo, where 0 = Clockwise, and 1 = Counterclockwise.

    Set LED Light

    Parameters

    • place - Where the LED is placed (left eye, right eye, left mouth, right mouth, horn, left arm, right arm, left leg, or right leg) on the Quirkbot.
    • light intensity - Set brightness of the LED, 0 to 1.

    Set Dual Color LED Light

    Parameters

    • place - Where the LED is placed (horn, left arm, right arm, left leg, or right leg) on the Quirkbot.
    • light intensity - Set brightness of the LED, 0 to 1.

    Key Tap

    Parameters

    • key - The key to type.

    Key Press

    Parameters

    • key - The key to press and held down until release key command.

    Key Release

    Parameters

    • key - The key to let go of a key press.

    Hold Key

    Parameters

    • key - The key to hold down.
    • duration - Number of seconds a key is held down once it's been pressed.

    Control Blocks

    Control blocks are the blocks that control scripts.

    Pauses the script for the amount of time.

    A loop that repeats the specified number of times.

    A loop that will continuously run forever. The forever block can yield to other commands within the program.

    Checks the condition so that if the condition is true, the blocks inside it will activate.

    Checks the condition so that if the condition is true, the blocks inside the first half will activate. If the condition is false, the blocks inside the second half will activate.

    Pauses the script until the condition is true.

    Operator Blocks

    Operator blocks perform math functions with numbers and string handling.

    The value of the addition.

    The value of the subtraction.

    The value of the multiplication.

    The value of the division.

    Picks a random number between the two limits.

    The condition for checking if a value is greater than the other.

    The condition for checking if a value is less than the other.

    The condition for checking if two values are equal.

    True if both conditions are true.

    True if either condition is true.

    Makes the condition checked if it is false, not true, or true, not false.

    The remainder of the division.

    Rounds the value to the nearest whole number.

    The absolute value (abs), square root (sqrt), sine (sin), cosine (cos), tangent (tan), asine (asin), acosine (acos), atangent (atan), natural logarithm (ln), logarithm (log), exponential function (e^), or base 10 exponential function (10^) of a specified value.

    Variable Blocks

    Variables blocks are the blocks that hold variables and lists.

    The variable's value.

    Sets the specified variable to the amount.

    Changes the specified variable by the amount.

    Events

    Event blocks control events and trigger the program. Strawbees CODE uses 2 Event blocks:

    When the program is uploaded to the Quirkbot, the block script activates.

    The event is activated when triggered by an input.

    My Blocks

    My Blocks are user-made custom blocks.

    Defines a custom block.

    Defines a custom block.

    An input for a value, set by the definition My Block.

    A true/false value.

    Flow Programming

    Flow is a visual programming language connecting nodes together to send data from one to another continuously. Flow-based programming  works with visual nodes. This paradigm suited for thinking in a general way about systems and overview of what you want to do instead of explaining it in step-by-step instructions. Using Flow programming is great for prototyping a variety of functions and not having to rewrite lines of code.

    Parts of a Node

    Connections

    Connections send data from one node to another. Make a connection by dragging the outlet of a node and dropping it in the parameter of another node. Once connected, data flows continuously from the outlet to the parameter.

    Parameters

    Parameters hold values that are important to the node. By changing the values, you change how the node works. You decide if a parameter is fixed or connected to an outlet. A fixed parameter’s value doesn’t change. A connected parameter’s value changes when the connected outlet changes.

    Number Parameters

    Many nodes have number parameters. Set their value by using the slider or by typing directly into the box. Most number parameters go from 0 to 1, enabling you to connect them directly to most outlets.

    Option Parameters

    Some nodes have option parameters. Select their value by clicking on an item from the drop-down list, or by writing the exact name of the option in the box.

    Many input and output nodes have a place option parameter (horn, left arm, right arm, left leg, or right leg) that presents where they exist in the physical world.

    Min and Max Parameters

    Many nodes have minimum and maximum (min and max) number parameters that control the smallest and largest values sent by the outlet.

    Input Nodes

    Nodes getting information from the outside world.

    Circuit Touch

    Turns the arms, legs or horn into a circular touch sensor. It detects when a weak current flows from the front to pad to ground. The ground can be the left eye or the back pads of the arms, legs, or horn. Because it's very sensitive, the current can flow through your body or anything else that has water in it, or is otherwise conductive (like metals). To activate the sensor, simply pinch the arm that you choose as the place.

    Parameters

    • place - The physical place on the Quirkbot (horn, left arm, right arm, left leg, or right leg) where to use the touch sensing.
    • sensitivity - How sensitive the touch reacts to a trigger, 0 = low, 1 = high.
    • min - The value sent to the outlet when the sensor goes to off, that is when you release it.
    • max - The value sent to the outlet when the sensor goes to on, that is when you touch it.

    Outlet

    • Sends out the max value when touched, and the min value when released.

    Light Sensor

    Reads an analog value from a physical light sensor connected to the arms, legs, or horn of the Quirkbot. It gives the light sensor power from the front pad and reads the back pad to determine the amount of light hitting the sensor. It also works with other sensors based on resistance.

    Parameters

    • place - The physical place on the Quirkbot (horn, left arm, right arm, left leg, or right leg) where you have attached the sensor.
    • min - The minimum value that the node will send to the outlet.
    • max - The maximum value that the node will send to the outlet.

    Outlet

    • Sends out a value based on the sensor reading, mapped to the range defined by the min and max values.

    Squeeze Sensor

    Self-calibrating version of the Light Sensor node. Reads an analog value from a physical light sensor connected to the arms, legs, or horn of the Quirkbot. It continuously calibrates the value to get the maximum range. It gives the light sensor power from the front pad and reads the back pad to determine the amount of light hitting the sensor. Also works with other sensors based on resistance.

    Parameters

    • place - The physical place on the Quirkbot (horn, left arm, right arm, left leg, or right leg) where you have attached the sensor.
    • min - The minimum value that the node will send to the outlet.
    • max - The maximum value that the node will send to the outlet.

    Outlet

    • Sends out a value based on the sensor reading, mapped to the range defined by the min and max values.

    IR Proximity

    Control the DIY IR Proximity backpack. The IR Proximity detects the amount of infrared light from an IR-LED that reflects from back to an IR Detector.

    Parameters

    • min - The minimum value that the node will send to the outlet.
    • max - The maximum value that the node will send to the outlet.

    Outlet

    • Sends out a value based on the IR light reading, mapped to the range defined by the min and max values.

    Sonar

    For using the DIY Kit backpack to connect to a Grove Ultrasonic Ranger from Seeed Studio. The Sonar measures the distance to an object by bouncing ultrasound in its surface.

    Parameters

    • place - Where the Grove Ultrasonic Ranger is connected to the backpack.
    • max distance (m) - Maximum distance the sensor responds to in meters.
    • min - The minimum value that the node will send to the outlet.
    • max - The maximum value that the node will send to the outlet.

    Outlet

    • Sends out a value based on the distance reading, mapped to the range defined by the min and max values.

    Analog Sensor

    Reads an analog value. Checks how much voltage is applied to a physical input on the Quirkbot that has analog read capability. This can be used by connecting external electronic components such as potentiometers or resistors.

    Parameters

    • place - The physical place on the Quirkbot (Horn Back, Left Arm Back, Right Arm Back, Left Leg Back, Right Leg Back, Backpack 1, Backpack 2, Left Leg Front, or Left Arm Front) where you want to read the analog input.
    • min - The minimum value that the node will send to the outlet.
    • max - The maximum value that the node will send to the outlet.

    Outlet

    • Sends out a value based on the analog reading, mapped to the range defined by the min and max values.

    Digital Sensor

    Read a digital value. Checks if there is voltage, or not, applied to a physical input on the Quirkbot that has digital read capability. This can be used by connecting external electronic components such as buttons and switches.

    Parameters

    • place - The physical place on the Quirkbot (Horn Back, Left Arm Back, Right Arm Back, Left Leg Back, Right Leg Back, Backpack 1, Backpack 2, Horn Front, Left Leg Front, Right Leg Front, Left Arm Front, or Right Arm Front) where you want to read the digital input.
    • min - The value that the node will send to the outlet if there is no voltage applied.
    • max - The value that the node will send to the outlet if there is voltage applied.

    Outlet

    •  Sends either min or max depending on the state of the input.

    Brain Nodes

    Nodes that manipulates or generates information.

    Wave

    A waveform generator. Create a wave that oscillates (continuously swings back and forth) between two numbers. There are a number of different Waveforms (types of waves) that can be selected. The Wave node can be used in many situations like moving a servo motor back and forth, blinking an LED, or iterating through a list from the List node.

    Parameters

    • length (s) - Length of the period of the waveform in seconds.
    • type - The type of waveform (Sine, Triangle, Square, Pulse, Ramp Up, or Ramp Down).
    • min - The lowest value, also called trough, of the wave.
    • max - The highest value, also called peak, of the wave.
    • offset - Offset of the period of the waveform, 0 to 1, where 0 is no offset, and 1 is a full period.

    Outlet

    • A continuous wave oscillating between the min and max values.

    Randomizer

    Send out a random number at a given interval.

    Parameters

    • interval (s) - The time in seconds between sending out the random number.
    • min - Minimum possible value of the random number.
    • max - Maximum possible value of the random number.

    Outlet

    • The random number between the min and max values.

    Time

    Counts the number of seconds elapsed since the Quirkbot is powered up. Can be used together with the comparison node to trigger time based events.

    Outlet

    • Time in seconds and hundredths of seconds since power on.

    Math

    Perform a common arithmetic operation with two numbers. Addition, subtraction, multiplication, division and modulo operations are available.

    Parameters

    • in - The first operand in the arithmetic operation. 
    • operation - The type of arithmetic operation (+ Add, - Subtract, x Multiply, / Divide or % Modulo). 
    • value - The second operand in the arithmetic operation.

    Outlet

    • Send out the result of the operation of in and value.

    Comparison

    Compares two values and evaluates the result. The number going to in is compared to the number in value, and the type of comparison is selected with operation. If the result of the comparison is “true” (for example if in is 1, operation is == Equal, and value is 1) then the number in then is sent to the outlet. If the comparison is “false” (for example, if in is 0, operation is > Greater, and value is 1) the number in else is sent to the outlet. This is a powerful node that can be used in many ways.

    Parameters

    • in - The number to compare.
    • operation - The type of comparison to make (== Equal, != Different, > Greater, >= Greater or equal, < Less, or <= Less or equal).
    • value - The number that in should be compared to.
    • then - The number sent to the outlet if the result of the comparison is “true.”
    • else - The number sent to the outlet if the result of the comparison is “false.”

    Outlet

    • Sends value from either then or else depending on the state of the inputs.

    Logic

    Three common logic gates: AND, OR and XOR. When adding more than 2 items (inputs) the logic gates are automatically chained together.

    Parameters

    • operation - The type of logic gate (AND, OR, or XOR).
    • items - Inputs for the logic gates. Use 0 or 1 as values. Press + to add more inputs.
    • open - The value that is sent to the outlet if the values in the items evaluates as “true.”
    • close - The value that is sent to the outlet if the values in the items evaluates as “false.”

    Outlet

    • Sends either open or close depending on the state of the items and operation.

    Statistics

    Performs a statistical analysis on a number of input items. Operations available are: Average value, Minimum value, Maximum value, and a Summation of all the values.

    Parameters

    • operation - The type (Average, Minimum, Maximum, or Summation) of analysis to use.
    • items - Inputs for the analysis. Use 0 or 1 as values. Press + to add more inputs.

    Outlet

    • The statistical evaluation based on the operation applied to the input items.

    Constrain

    Constrain any number to be kept inside a limited range. The number sent to in will go unchanged to the outlet if it lies between the values in min and max. If it’s higher than max then max will be sent to the outlet. If it’s lower than min then min will be sent to the outlet.

    Parameters

    • in - The number or stream of numbers that we want to constrain.
    • min - The minimum value that is allowed to be sent to the outlet.
    • max - The maximum value that is allowed to be sent to the outlet.

    Outlet

    • The constrained stream of numbers.

    Converter

    Convert a stream of numbers from one range to another range. This node can be used to amplify, compress, shift, or invert a range. This can be useful in many situations, for instance to change the numbers coming from an input node, to better match the behavior wanted in an output node.

    Parameters

    • in - The stream of numbers that you want to convert.
    • in min - The lowest expected number that will go to in.
    • in max - The highest expected number that will go to in.
    • out min - What the number coming to in will be converted to if it is the same as in min. (Can be set higher than out max if you want to invert the range).
    • out max - What the number coming to in will be converted to if it is the same as in max. (Can be set lower than out min to invert the range).

    Outlet

    • Sends the converted number based on in and the other values.

    Gate

    Gate is used to turn on and off a stream of numbers. It's inserted between two other nodes to stop or allow data to go from one to the other.

    Parameters

    • in - The input values to stop or allow to pass.
    • trigger - 0 = The gate is closed and will stop data. 1 = The gate is open and will allow data to go to the outlet.

    Outlet

    • Any data from in when the gate is open.

    List

    Create a list of any numbers or values. You can add up to 100 items by clicking the + sign and removing items by clicking the - sign next to them. The items on the list can also be used as routable inputs for any stream of numbers.

    Parameters

    • in - Choose which item is sent to the outlet. 0 = the first, and 1 = the last item. Items between first and last are selected by numbers between 0 and 1 (equally divided).
    • items - Holds any mix of values or inputs from other nodes to be sent to the outlet.

    Outlet

    • The value from any of the items as chosen by in.

    Sequence

    Create a sequence of any numbers and values. You can specify how long it will take for the sequence to run through all the values, and trigger a run. After a run, the sequence will stop, and is ready to trigger again.

    Parameters

    • trigger - Start the run of the sequence every time the value goes from 0 to 1. (What is called a rising edge).
    • duration (s) - Time in seconds it takes for the sequence to run when triggered.
    • items - Holds any mix of values or inputs from other nodes to be sent to the outlet.

    Outlet

    • Outputs the items one by one when the sequence is triggered.

    Counter

    Counts from 0 by a certain amount every time it receives a trigger pulse. There is currently no way to reset the counter.

    Parameters

    • trigger - Makes the counter count every time the value goes from 0 to 1. (What is called a rising edge). 
    • amount - The counter will increase its internal state (the number it is currently at in the count) by this amount each time it receives a trigger pulse. If the value is negative, the counter will count down.

    Outlet

    • Sends out its new internal state each time it receives a trigger pulse.

    Output Nodes

    Nodes with the ability to control something in the physical world.

    LED

    Control Light-Emitting Diodes (LEDs). It controls both LEDs integrated in the Quirkbot like the eyes, or loose, external LEDs you attach to the arms, legs, and horn.

    Parameters

    • light intensity - Set brightness of the LED, 0 to 1.
    • place - Where the LED is placed (left eye, right eye, left mouth, right mouth, horn, left arm, right arm, left leg, or right leg) on the Quirkbot.

    Dual Color LED

    Control Light-Emitting Diodes (LEDs) with two colors. The red-blue LEDs that come with the Quirkbot kits are such LEDs. To use this node connect the LEDs to the arms, legs, or horn.

    Parameters

    • light intensity - Set brightness of the LED, 0 to 1.
    • color - Range: set color mix of the LED. For Red-Blue LEDs: 0 = Red, 1 = Blue, and 0.5 = Equal mix.
    • place - Where the LED is placed (horn, left arm, right arm, left leg, or right leg) on the Quirkbot.

    Servo Motor

    Control servo motors connected to the servo motor backpack. Servo motors have an arm that can move to a specific position. Maximum movement is a little less than half a rotation, about 120 - 180 degrees, depending on the motor.

    Parameters

    • position - The position of the servo motor, 0 = Min, 1 = Max, 0.5 = Middle etc.
    • place - Where the servo (1 or 2) is connected. Connection requires the servo backpack.

    Continuous Servo

    For controlling continuously rotating servo motors. These types of motors, sometimes referred to as "360 servos," have two things you can control: the speed of the rotation, and the direction of the rotation. This is unlike the other servo motors, where you can tell the motor to move its arm to a specific location.

    Parameters

    • speed - Control the rotation speed of the continuous servo from 0 to 1.
    • direction - Control the direction of the rotation of the continuous servo, where: 0 = Clockwise, and 1 = Counterclockwise.
    • place - Where the continuous servo (1 or 2) is connected. Connection requires the servo backpack.

    Buzzer

    Creates a simple tone and sends it to a physical output pin on the Quirkbot. This can be used with the DIY buzzer backpack or by connecting a small speaker or piezo element to the Quirkbot.

    Parameters

    • note - The note to play. Can be set by selecting a note from the list, or sending the note value from another node, or sending a value between 0 and 1.
    • place - The physical place on the Quirkbot where you want to connect the speaker.

    Key Press

    Makes the Quirkbot act like an external USB keyboard. When connected to the computer, it can send key presses from a defined key.

    Parameters

    • trigger - 1 = Key press down, 0 = Key release.
    • key - The key to press.

    Key Sequence

    Makes the Quirkbot act like an external USB keyboard. When connected to the computer, it can send a sequence of key presses. The sequence can be sent from, for example, a List node.

    Parameters

    • key - Creates a key press as soon as it gets a new key.
    • hold time - Number of seconds a key is held down once it's been pressed.

    Voltage Output

    Control physical outputs of the Quirkbot. Set a voltage between 0 volts and the battery voltage (3.2 - 4.2V). The node is using pulse-width modulation (PWM) and can be used on any physical place on the Quirkbot. The pads on the arms, legs, and horn are protected with current limiting resistors, but if using the backpack outputs be careful not to create a short circuit that can damage the Quirkbot.

    Parameters

    • in - Set output voltage from 0 to 1, where 0 = 0 volts and 1 = battery voltage.
    • place - The physical place (Horn Back, Left Arm Back, Right Arm Back, Left Leg Back, Right Leg Back, Backpack 1, Backpack 2, Backpack 3, Backpack 4, Backpack 5, Backpack 6, Horn Front, Left Arm Front, Right Arm Front, Left Leg Front, or Right Leg Front) on the Quirkbot where you want to output a voltage.