Powerbrain

Other libraries:
Grabber
Motor
Pivot
Twister
IR Sensor
Light Sensor

Arduino Library 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();

       setup()
       {}
      
       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();

       setup()
       {}
      
       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();

       setup()
       {}
      
       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();

       setup()
       {}
      
       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();

       setup()
       {}
      
       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);

       setup()
       {}
      
       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);

       setup()
       {}
      
       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();
     
       setup()
       {}
      
       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);

       setup()
       {}
      
       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();

       setup()
       {}
      
       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