element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Ultimate RoadTest
  • Challenges & Projects
  • Design Challenges
  • Ultimate RoadTest
  • More
  • Cancel
Ultimate RoadTest
Blog The Bread & Butter : 10
  • Blog
  • Forum
  • Documents
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: HNTE
  • Date Created: 12 Jun 2012 9:40 AM Date Created
  • Views 1211 views
  • Likes 2 likes
  • Comments 1 comment
  • ads1131
  • cc3000
  • colour
  • led
  • rgb
  • eagle_pcb
  • bread_&_butter
  • ultimate_roadtest
  • tlc59025
Related
Recommended

The Bread & Butter : 10

HNTE
HNTE
12 Jun 2012

June 12th : Light it Up

Here is a quick video of my little display showing of its true colours. Unfortunately the quality is pretty shocking, I can never seem to get a good video of my light displays (anyone who knows some tricks for filming bright LEDs let me know).

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

I use Bit Angle Modulation (BAM) for the colour fading, 8 bit modulation allows me to generate 16 million or so colours. I am sure there are plenty of different ways to implement BAM but this is my way and it works, I store the current animation frame in a 9x3 matrix and the interrupt does the rest.

 

//BIT ANGLE MODULATION IN AN INTERRUPT
unsigned char bitpos = 0x00;
unsigned char bitcount = 0x00;
unsigned int bitlength = 0x01;

void Timer0_A3_ISR(void){

      if(bitcount == 0){
           HIGH(OE);
           load_matrix(); //LOAD THE ARRAY ONTO THE MATRIX
           LOW(OE);
      }

      bitcount += 0x01;

      if(bitcount >= bitlength){
           bitpos += 0x01;
           bitlength = bitlength<<0x01;
           bitcount = 0x00;
      }

      if(bitpos >= 8){
           bitpos = 0x00;
           bitcount = 0x00;
           bitlength = 0x01;
           state |= update;
      }
}

//LOAD THE DATA ONTO THE LED DRIVER BOARD
void load_matrix(void){
      int x, y;

      for(x = 0; x < 9; x++){
           for(y = 0; y < 3; y++){
                if((matrix[x][y].red)&(0x01<<bitpos)){
                     HIGH(SDIR);
                }
                if((matrix[x][y].green)&(0x01<<bitpos)){
                     HIGH(SDIG);
                }
                if((matrix[x][y].blue)&(0x01<<bitpos)){
                     HIGH(SDIB);
                }
     
                PULSE(CLK);
                LOW(SDI_ALL);
           }
      }

      PULSE(LE);
}

 

 

Because the launchpad is pretty strapped for memory and it is a bit sluggish when it comes to playing with floating point numbers, I needed a new way to generate a colour wheel. Usually I create a large array in memory, or use sine functions to generate the colours, this time I decided to go with a clever little conditional function.

My getColour function can generate 768 different colours, you hand the function an integer between 0 and 768 and it will spit out a colour from the colour wheel. I painted a picture below to try and explain myself a little better, the numbers in the image are the integer you hand to the getColour function... Obviously the function fades the colours a little better than I did in paint. 

 

typedef struct{
      unsigned char red;
      unsigned char green;
      unsigned char blue;
}colour;

colour getColour(int c){
      colour result;

      while(c >= 768){
           c-=768;
      }

      if(c >= 0 && c < 256){
           result.red = c;
           result.green = 0;
           result.blue = 255-c;
      }else if(c >= 256 && c < 512){
           c-=256;
           result.red = 255-c;
           result.green = c;
           result.blue = 0;
      }else if(c >= 512 && c < 768){
           c-=512;
           result.red = 0;
           result.green = 255-c;
           result.blue = c;
      }

      return result;
}

 

 

image

 

The Bread & Butter : 11

  • Sign in to reply
  • DAB
    DAB over 13 years ago

    It looks like you have a good start at a full color output device.

    Have you decided how you are going to use it yet?

     

    Anyway, good demo and code post.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube