Simple demo for a ShiftBrite RGB LED module that cycles through different colors.
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 //ShiftBrite Demo 00003 DigitalOut latch(p15); 00004 DigitalOut enable(p16); 00005 //Cycles through different colors on RGB LED 00006 SPI spi(p11, p12, p13); 00007 //Use SPI hardware to write color values to LED driver chip 00008 void RGB_LED(int red, int green, int blue) { 00009 unsigned int low_color=0; 00010 unsigned int high_color=0; 00011 high_color=(blue<<4)|((red&0x3C0)>>6); 00012 low_color=(((red&0x3F)<<10)|(green)); 00013 spi.write(high_color); 00014 spi.write(low_color); 00015 latch=1; 00016 latch=0; 00017 } 00018 00019 int main() { 00020 int red=0; 00021 int green=0; 00022 int blue=0; 00023 spi.format(16,0); 00024 spi.frequency(500000); 00025 enable=0; 00026 latch=0; 00027 wait(2); 00028 for (red = 0; red<50; red = red+10) { 00029 for (blue = 0; blue<50; blue = blue+10) { 00030 for (green = 0; green<50; green = green+10) 00031 00032 { 00033 RGB_LED( red, green, blue); 00034 wait(.25); 00035 } 00036 } 00037 } 00038 00039 }
Generated on Sun Jul 17 2022 06:13:17 by
1.7.2