Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 00003 DigitalOut latch(p15); 00004 DigitalOut enable(p16); 00005 DigitalIn r(p5); 00006 DigitalIn g(p6); 00007 DigitalIn b(p7); 00008 00009 SPI spi(p11, p12, p13); 00010 00011 void RGB_LED(int red, int green, int blue) { 00012 unsigned int low_color=0; 00013 unsigned int high_color=0; 00014 high_color=(blue<<4)|((red&0x3C0)>>6); 00015 low_color=(((red&0x3F)<<10)|(green)); 00016 spi.write(high_color); 00017 spi.write(low_color); 00018 latch=1; 00019 latch=0; 00020 } 00021 00022 int main() { 00023 int red=0; 00024 int green=0; 00025 int blue=0; 00026 spi.format(16,0); 00027 spi.frequency(500000); 00028 enable=0; 00029 latch=0; 00030 wait(2); 00031 while(1) { 00032 if (r == 1){ 00033 if (red < 255) red += 5; 00034 } else { 00035 if (red > 0) red -= 5; 00036 } 00037 if (b == 1){ 00038 if (blue < 255) blue += 5; 00039 } else { 00040 if (blue > 0) blue -= 5; 00041 } 00042 if (g == 1){ 00043 if (green < 255) green += 5; 00044 } else { 00045 if (green > 0) green -= 5; 00046 } 00047 RGB_LED(red, green, blue); 00048 wait(0.5); 00049 } 00050 00051 }
Generated on Tue Jul 26 2022 18:28:37 by
1.7.2