RGB LEDS of the neopixels

Dependencies:   C12832_lcd PixelArray WS2812 mbed

Fork of WS2812_Example by Brian Daniels

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "WS2812.h"
00003 #include "PixelArray.h"
00004 #include "C12832_lcd.h"
00005 
00006 #define WS2812_BUF 3
00007 #define NUM_COLORS 9
00008 #define NUM_LEDS_PER_COLOR 3
00009 PixelArray px(WS2812_BUF);
00010 
00011 // See the program page for information on the timing numbers
00012 // The given numbers are for the K64F
00013 WS2812 ws(p9, WS2812_BUF, 5, 10, 10, 15);
00014 
00015 //LCD Setup
00016 C12832_LCD lcd;  
00017 
00018 Serial pc(USBTX, USBRX); // tx, rx
00019 
00020 void LED_Colour(int red , int green ,int blue , int bright)
00021     {
00022     int colorbuf[NUM_COLORS] = {0x000000};
00023     //int colorbuf[NUM_COLORS] = {0x000000,0x00f0ff,0x00ff00,0x00ffff,0xffffff,0x00ff00,0x00ffff,0x0000ff,0xff00ff};
00024     
00025     colorbuf[0] = red*0xffff + green*0xff + blue*0x00;
00026     
00027     pc.printf("Colour: %x \n\r",colorbuf[0]);
00028     // for each of the colours (j) write out 10 of them
00029     // the pixels are written at the colour*10, plus the colour position
00030     // all modulus 60 so it wraps around
00031     for (int i = 0; i < WS2812_BUF; i++) {
00032         px.Set(i, colorbuf[(i / NUM_LEDS_PER_COLOR) % NUM_COLORS]);
00033     }
00034 
00035     // now all the colours are computed, add a fade effect using intensity scaling
00036     // compute and write the II value for each pixel
00037     for (int j=0; j<WS2812_BUF; j++) {
00038         // px.SetI(pixel position, II value)
00039         //px.SetI(j%WS2812_BUF, 0xff+(0xf*(j%NUM_LEDS_PER_COLOR)));     //full brightness
00040         px.SetI(j%WS2812_BUF, 0xf +(0xf*(j%NUM_LEDS_PER_COLOR)));        //Dim lighting
00041     }       
00042 }
00043 int main()
00044 {
00045 
00046     ws.useII(WS2812::PER_PIXEL); // use per-pixel intensity scaling
00047     
00048      while (1) {
00049  
00050         LED_Colour(125, 125 ,125 , 125);
00051         wait(1);
00052         }
00053 }