Powerbrain - Tinkerbots

ARDUINO BIBLIOTHEK POWERBRAIN

The Powerbrain is the heart of every Tinkerbots robot. Movements and measurements are performed by the modules, but the Powerbrain has to coordinate timings and manage all modules in parallel. Nevertheless, it can still do some special tricks.

FUNCTION OVERVIEW

FUNCTION DESCRIPTION

 

    NAME

TBPowerbrain

    DESCRIPTION

If you want to use some of the special functions of the Powerbrain, you will need to declare one object, on which you can perform the calls.

    SYNTAX

TBPowerbrain;

    PARAMETER

None

    RETURN

None

    EXAMPLE

 

#include “TBPowerbrain.h”TBPowerbrain heart;

void setup()
{}

void loop()
{
/* Detect different key presses and play different pitches for each */
if( heart.isPlusPressed() )
heart.playSound(400,300);

if( heart.isMinusPressed() )
heart.playSound(500,300);

if( heart.isPlayPressed() )
heart.playSound(600,300);

if( heart.isRecordPressed() )
heart.playSound(700,300);

delay(500);
}

 

    NAME

isPlusPressed()

    DESCRIPTION

Check if the plus button on the Powerbrain is pressed.

    SYNTAX

isPlusPressed();

    PARAMETER

None

    RETURN

true or false (Arduino boolean)

    EXAMPLE

 

#include “TBPowerbrain.h”TBPowerbrain heart;

void setup()
{}

void loop()
{
/* Detect different key presses and play different pitches for each */
if( heart.isPlusPressed() )
heart.playSound(400,300);

if( heart.isMinusPressed() )
heart.playSound(500,300);

if( heart.isPlayPressed() )
heart.playSound(600,300);

if( heart.isRecordPressed() )
heart.playSound(700,300);

delay(500);
}

 

    NAME

isMinusPressed()

    DESCRIPTION

Check if the minus button on the Powerbrain is pressed.

    SYNTAX

isMinusPressed();

    PARAMETER

None

    RETURN

true or false (Arduino boolean)

    EXAMPLE

 

#include “TBPowerbrain.h”TBPowerbrain heart;

void setup()
{}

void loop()
{
/* Detect different key presses and play different pitches for each */
if( heart.isPlusPressed() )
heart.playSound(400,300);

if( heart.isMinusPressed() )
heart.playSound(500,300);

if( heart.isPlayPressed() )
heart.playSound(600,300);

if( heart.isRecordPressed() )
heart.playSound(700,300);

delay(500);
}

 

    NAME

isPlayPressed()

    DESCRIPTION

Check if the play button on the Powerbrain is pressed.

    SYNTAX

isPlayPressed();

    PARAMETER

None

    RETURN

true or false (Arduino boolean)

    EXAMPLE

 

#include “TBPowerbrain.h”TBPowerbrain heart;

void setup()
{}

void loop()
{
/* Detect different key presses and play different pitches for each */
if( heart.isPlusPressed() )
heart.playSound(400,300);

if( heart.isMinusPressed() )
heart.playSound(500,300);

if( heart.isPlayPressed() )
heart.playSound(600,300);

if( heart.isRecordPressed() )
heart.playSound(700,300);

delay(500);
}

 

    NAME

isRecordPressed()

    DESCRIPTION

Check if the record button on the Powerbrain is pressed.

    SYNTAX

isRecordPressed();

    PARAMETER

None

    RETURN

true or false (Arduino boolean)

    EXAMPLE

 

#include “TBPowerbrain.h”TBPowerbrain heart;

void setup()
{}

void loop()
{
/* Detect different key presses and play different pitches for each */
if( heart.isPlusPressed() )
heart.playSound(400,300);

if( heart.isMinusPressed() )
heart.playSound(500,300);

if( heart.isPlayPressed() )
heart.playSound(600,300);

if( heart.isRecordPressed() )
heart.playSound(700,300);

delay(500);
}

 

    NAME

showModuleColors()

    DESCRIPTION

Activate the LEDs on all connected modules. They will light with the module’s color, so you can identify the module in Arduino.

This function is also always executed, if you connect an USB cable to your Powerbrain.

    SYNTAX

showModuleColors();

    PARAMETER

None

    RETURN

None

    EXAMPLE

 

#include “TBPowerbrain.h”
#include “TBPivot.h”TBPowerbrain heart;
TBPivot piv1(GREEN),piv2(BLUE);void setup()
{}

void loop()
{
/* To see the module color during runtime (without connected USB) */
heart.showModuleColors();

/* Move to outer positions with half speed */
piv1.setPosition(0,50);
piv2.setPosition(180,50);
delay(2000);

/* Hide module colors and move back */
heart.hideModuleColors();
piv1.setPosition(180,50);
piv2.setPosition(0,50);
delay(2000);

}

 

    NAME

hideModuleColors()

    DESCRIPTION

Deactivate the LEDs on all connected modules.

This function is also always executed, if you disconnect an USB cable from your Powerbrain.

    SYNTAX

hideModuleColors();

    PARAMETER

None

    RETURN

None

    EXAMPLE

 

#include “TBPowerbrain.h”
#include “TBPivot.h”TBPowerbrain heart;
TBPivot piv1(GREEN),piv2(BLUE);void setup()
{}

void loop()
{
/* To see the module color during runtime (without connected USB) */
heart.showModuleColors();

/* Move to outer positions with half speed */
piv1.setPosition(0,50);
piv2.setPosition(180,50);
delay(2000);

/* Hide module colors and move back */
heart.hideModuleColors();
piv1.setPosition(180,50);
piv2.setPosition(0,50);
delay(2000);

}

 

    NAME

blinkLED()

    DESCRIPTION

Sometimes you want to show your robot is in a specific state. For this purpose, you can configure the LED of the Powerbrain to show different colors and sequences.

    SYNTAX

blinkLED(color, period, cycles);

    PARAMETER

color: Color the Powerbrain’s LED should emit.
Values: RED, GREEN, BLUE, MINT, PURPLE, YELLOW, WHITE

period: ON-time of the LED (in milliseconds). E.g. to achieve two blinks a second you have an ON-time of 250 ms.
Values:    0 – 65535 (in milliseconds)

cycles: Number of cycles the LED toggling should perform. If you want it to blink infinite number of times, put a zero here.
Values:    1 – 65535
0 – infinite blinking

    RETURN

None

    EXAMPLE

 

#include “TBPowerbrain.h”TBPowerbrain heart;

void setup()
{}

void loop()
{
heart.blinkLED(RED,300,3)
delay(3000);

heart.blinkLED(MINT,150,6);
delay(3000);

heart.blinkLED(BLUE,450,2);
delay(3000);

}

 

    NAME

playSound()

    DESCRIPTION

You surely noticed the Powerbrain can make sounds! Using this function, you can create custom melodies or even build your very own instrument.

    SYNTAX

playSound(frequency, timeout);

    PARAMETER

frequency: Pitch of the note to play (in Hertz).
Values:    0 – 1500

timeout: Duration of the tone in milliseconds.
Values:    0 – 65535

    RETURN

None

    EXAMPLE

 

#include “TBPowerbrain.h”TBPowerbrain heart;
TBPivot piv1(GREEN),piv2(BLUE);void setup()
{}

void loop()
{
for( unsigned int freq = 300 ; freq <= 1500 ; freq +=300 )
{
//play tones at 300, 600, 900, 1200 and 1500 Hz
heart.playSound(freq,500);
delay(500);
}
}

 

    NAME

setLEDColor()

    DESCRIPTION

Set the Powerbrain’s LED to a specific color. This way you could identify two different Powerbrains, or like in blinkLED() show different statuses.

    SYNTAX

setLEDColor(color);

    PARAMETER

color: Light the Powerbrain LED in a specific color.
Values:   RED, GREEN, BLUE, MINT, PURPLE, YELLOW, WHITE

    RETURN

None

    EXAMPLE

 

#include “TBPowerbrain.h”TBPowerbrain heart;

void setup()
{}

void loop()
{
/* This one is a bit tricky! Execute and see for yourself */
for( unsigned int light = BLACK ; light <= WHITE ; light++)
{
heart.setLEDColor(light);
delay(1000);
}
}

 

    NAME

setRefreshTime()

    DESCRIPTION

Set a different refresh interval for the update of the modules. Sensor and position values will be updated with the given period.

    SYNTAX

setRefreshTime(refreshTime);

    PARAMETER

refreshTime: various update times for the sensors – shorter time = faster update
Values:   REFRESH_TIME_25_MS,REFRESH_TIME_50_MS,REFRESH_TIME_100_MS, . . . , REFRESH_TIME_500_MS (see Tinkerbots.h for all)

    RETURN

None

    NAME

switchOff()

    DESCRIPTION

Command the Powerbrain to switch off. A restart can only be performed if the Powerbrain is not connected to a cable.

    SYNTAX

switchOff();

    PARAMETER

None

    RETURN

None