HCColorDuino - ColorDuino library

Useful guides, libraries, and example sketches to support our Arduino based products.
Post Reply
admin
Site Admin
Posts: 865
Joined: Sun Aug 05, 2012 4:02 pm

HCColorDuino - ColorDuino library

Post by admin » Thu Jul 17, 2014 11:47 am

Description:

This library is written to work with the ColourDuino (HCDVBD0015) development board. This Arduino compatible board is specifically designed to drive a 3 colour RGB LED dot matrix displays and uses an ATmega328p device loaded with the Arduino bootloader. This allows the development board to be programmed directly from the Arduino development environment (via a suitable TTL serial adaptor). For a suitable LED matrix please see the following item in our store (HCMODU0053). This librar,y together with the development board and previously mentioned RGB dot matrix module, will allow simple control of the display from an Arduino sketch including controlling individual LED's and scrolling numbers and text in different colours. Although the library can be used on it's own, it works best when used with out HCTimer2 library also found on this forum and most of the example sketches make use of this additional library.

You will need to download (please log in to download the library) and unzip this library to the Arduino development environments library area

On Windows:
My Documents\Arduino\libraries\
My Documents\Arduino\libraries\
My Documents\Arduino\libraries\

On Mac:
Documents/Arduino/libraries/
Documents/Arduino/libraries/
Documents/Arduino/libraries/
or similarly for Linux.


To use the library just include the HCColorDuino.h header file and create an instance of the ColorDuino library. E.g:

Code: Select all

HCColorDuino HCColorDuino;
The following functions are available with this library:

Code: Select all

HCColorDuino.Refresh();
This function refreshes the matrix display and must be frequently executed (about every 2ms is ideal).

Code: Select all

HCColorDuino.RGBColourCorrection(R, G, B);
Corrects for different brightnesses (luminosity) in the three red green and blue LED's so that when mixing the 3 colours the correct is colour obtained. This function only needs to be executed once at the start of the sketch. Valid correction values are between 0 to 255. See example sketches for recommended values when used with our RGB matrix module.

Code: Select all

HCColorDuino.print("Text");
Loads a string of alphanumeric text into the character buffer for output to the matrix display.

Code: Select all

HCColorDuino.print(number);
Loads a singed integer number into the character buffer for output to the matrix display.

Code: Select all

HCColorDuino.print(number, decimalPlace);
Loads a singed integer number into the character buffer for output to the matrix display. parameter decimalPlace allows for specifying the position of a decimal point.

Code: Select all

HCColorDuino.ClearMatrix();
Clears the matrix display.

Code: Select all

HCColorDuino.SetFontFG(R, G, B);
Sets the foreground colour of any text or numbers output of the matrix. Valid values are between 0 to 255.

Code: Select all

HCColorDuino.SetFontBG(R, G, B);
Sets the background colour of any text or numbers output of the matrix. Valid values are between 0 to 255.

Code: Select all

HCColorDuino.SetBG(R, G, B);
Sets the background colour of the matrix. Valid values are between 0 to 255.

Code: Select all

Plot(R, G, B, col, row);
Sets the RGB colour of an individual LED on the matrix. Where R, G, & B define the red green and blue colours and col/row are the column and row position of the LED. Valid values for R G and B are between 0 to 255 and 0 to 7 for col and row.

Code: Select all

HCColorDuino.ScrollOn(StartPos, StopPos, Speed, ScrollType);
Enables background scrolling of any text or numbers in the character buffer where:

StartPos sets the column start position to start scrolling from.

StopPos sets the column position to scroll to.

Speed sets the scroll speed. Valid values are from 0 to 255.

ScrollType sets how the text will be scrolled. SCROLLOFF will stop scrolling the text. SINGLESHOT will scroll the text to the specified end point and then stop. CONTINUOUS will scroll to the specified end point and then start at the beginning again.

Code: Select all

HCColorDuino.ScrollOff();
Turns off background scrolling.

Code: Select all

HCColorDuino.GetScrollPos();
Returns the current position (unsinged int) of the scrolling text.

Code: Select all

HCColorDuino.ClearBuffer();
Clears any text or numbers in the character buffer.

Code: Select all

HCColorDuino.DisplayPos(Position);
Will output any text in the character buffer at the specified column position.


Example sketch:

Code: Select all

/* FILE:    Hello_World.cpp
   DATE:    16/07/14
   VERSION: 0.1
   AUTHOR:  Andrew Davies

This is a basic example of how to use the ColourDuino module (HCDVBD0015 & HCMODU0053)
together with the HCColorDuino library to display a simple scrolling text message.

You may copy, alter and reuse this code in any way you like, but please leave
reference to HobbyComponents.com in your comments if you redistribute this code.
This software may not be used directly for the purpose of selling products that
directly compete with Hobby Components Ltd's own range of products.

THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
REASON WHATSOEVER.
*/

/* Include the HCColorDuino library */
#include "HCColorDuino.h"

/* Create an instance of the library */
HCColorDuino HCColorDuino;

void setup()
{  
  /* Calibrate the LED matrix display for differences in RGB luminace */
  HCColorDuino.RGBColourCorrection(25, 63, 63);
  /* Set the RGB colour of the font. Valid values are from 0 to 255 for 
     each colour */
  HCColorDuino.SetFontFG(0,0,255);
  
  /* Set the RGB colour of the fonts background. */
  HCColorDuino.SetFontBG(10,0,0);
 
  /* Turn on continuous auto-scrolling. Scroll from position 0 to 111 
     at a scroll speed of 230 (255 max) */
  HCColorDuino.ScrollOn(0, 111, 230, CONTINUOUS);
}

/* Main program */
void loop()
{
  /* Write some text to the character buffer */
  HCColorDuino.print("HELLO WORLD!");
  while(1)
  {
    /* Continuously refresh the the LED matrix */
    HCColorDuino.Refresh();
    delay(1);
  }
}
Example sketch using with HCTimer2 library:

Code: Select all

/* FILE:    Hello_World_Using_HCTimer2.cpp
   DATE:    16/07/14
   VERSION: 0.1
   AUTHOR:  Andrew Davies

This is a basic example of how to use the ColourDuino module (HCDVBD0015 & HCMODU0053)
together with the HCColorDuino and HCTimer2 library to display a simple scrolling text
message. By using the HCTimer2 library the hardware timer 2 can be re-tasked to refresh
the matrix display in the background.

You may copy, alter and reuse this code in any way you like, but please leave
reference to HobbyComponents.com in your comments if you redistribute this code.
This software may not be used directly for the purpose of selling products that
directly compete with Hobby Components Ltd's own range of products.

THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
REASON WHATSOEVER.
*/

/* Include the HCTimer2 library */
#include <HCTimer2.h>

/* Include the HCColorDuino library */
#include "HCColorDuino.h"

/* Create an instance of the library */
HCColorDuino HCColorDuino;


void setup()
{
  /* Calibrate the LED matrix display for differences in RGB luminace */
  HCColorDuino.RGBColourCorrection(25, 63, 63);
  
  /* Set the RGB colour of the font. Valid values are from 0 to 255 for 
     each colour */
  HCColorDuino.SetFontFG(0,0,255);
  
  /* Set the RGB colour of the fonts background. */
  HCColorDuino.SetFontBG(10,0,0);
 
  /* Turn on continuous auto-scrolling. Scroll from position 0 to 111 
     at a scroll speed of 230 (255 max) */
  HCColorDuino.ScrollOn(0, 111, 230, CONTINUOUS);


  /* Initialise the HCTimer2 library with a 2.4mS interval */  
  HCTimer2Init(T2_CLK_DIV_256, 150);
}

/* Main program */
void loop()
{
    /* Display some text */
    HCColorDuino.print("HELLO WORLD!");
    
    /* Nothing else to do ! */
    while(1);
}


/* Refresh the matrix display in the background */
void HCTimer2()
{
    HCColorDuino.Refresh();
}

Library:
HCColorDuino.zip
This library can be used as is, but is best used in conjunction with our HCTimer2 library found here: http://forum.hobbycomponents.com/viewto ... =43&t=1336
This additional library is also needed for some of the example sketches.
You do not have the required permissions to view the files attached to this post.

Post Reply

Return to “Arduino”