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.
Dependencies: Multi_WS2811_Mic FastAnalogIn USBDevice mbed
main.cpp
00001 #include "mbed.h" 00002 #include "FastAnalogIn.h" 00003 #include "WS2811.h" 00004 #include "Colors.h" 00005 00006 unsigned const nLEDs = 30;//MAX_LEDS_PER_STRIP; 00007 unsigned const DATA_OUT_PIN1 = 7; // PTC7 00008 00009 FastAnalogIn mic0(A0, 0); 00010 FastAnalogIn mic1(A1, 0); 00011 FastAnalogIn mic2(A2, 0); 00012 Serial pc(USBTX, USBRX); 00013 00014 DigitalOut ledR(LED_RED); 00015 DigitalOut ledG(LED_GREEN); 00016 DigitalOut ledB(LED_BLUE); 00017 00018 static void showSolidColor(WS2811 &strip, uint8_t r, uint8_t g, uint8_t b) 00019 { 00020 unsigned nLEDs = strip.numPixels(); 00021 for (unsigned i = 0; i < nLEDs; i++) { 00022 strip.setPixelColor(i, r, g, b); 00023 } 00024 strip.show(); 00025 } 00026 00027 static void clearScreen(WS2811 &strip) 00028 { 00029 unsigned nLEDs = strip.numPixels(); 00030 for (unsigned i = 0; i < nLEDs; i++) { 00031 strip.setPixelColor(i, 0, 0, 0); 00032 } 00033 strip.show(); 00034 } 00035 00036 int main(void) { 00037 uint16_t i = 0; 00038 uint16_t buff0[500]; 00039 uint16_t buff1[500]; 00040 uint16_t buff2[500]; 00041 char pc_read = 0; 00042 pc.baud(921600); 00043 ledR = ledG = ledB = 1; 00044 WS2811 lightStrip1(nLEDs, DATA_OUT_PIN1); 00045 lightStrip1.begin(); 00046 00047 while (true){ 00048 pc_read = 0; 00049 for(i = 0; i < 251; i++){ 00050 buff0[i] = int(1000*mic0.read()); 00051 buff1[i] = int(1000*mic1.read()); 00052 buff2[i] = int(1000*mic2.read()); 00053 } 00054 for(i = 0; i < 251; i++){ 00055 pc.printf("%d,%d,%d\n", buff0[i], buff1[i], buff2[i]); 00056 } 00057 00058 while(pc_read != 'Y'){ 00059 while(!pc.readable()); 00060 pc_read = pc.getc(); 00061 switch(pc_read){ 00062 case 'Y': 00063 pc.printf("Go\n"); 00064 break; 00065 00066 case 'R': 00067 ledR = 0; 00068 ledG = 1; 00069 ledB = 1; 00070 break; 00071 00072 case 'G': 00073 ledR = 1; 00074 ledG = 0; 00075 ledB = 1; 00076 break; 00077 00078 case 'B': 00079 ledR = 1; 00080 ledG = 1; 00081 ledB = 0; 00082 break; 00083 00084 case '1': 00085 clearScreen(lightStrip1); 00086 lightStrip1.setPixelColor(0, ledR*100, ledG*100, ledB*100); 00087 lightStrip1.setPixelColor(1, ledR*100, ledG*100, ledB*100); 00088 lightStrip1.setPixelColor(2, ledR*100, ledG*100, ledB*100); 00089 lightStrip1.setPixelColor(3, ledR*100, ledG*100, ledB*100); 00090 lightStrip1.setPixelColor(4, ledR*100, ledG*100, ledB*100); 00091 break; 00092 00093 case '2': 00094 clearScreen(lightStrip1); 00095 lightStrip1.setPixelColor(5, ledR*100, ledG*100, ledB*100); 00096 lightStrip1.setPixelColor(6, ledR*100, ledG*100, ledB*100); 00097 lightStrip1.setPixelColor(7, ledR*100, ledG*100, ledB*100); 00098 lightStrip1.setPixelColor(8, ledR*100, ledG*100, ledB*100); 00099 lightStrip1.setPixelColor(9, ledR*100, ledG*100, ledB*100); 00100 break; 00101 00102 case '3': 00103 clearScreen(lightStrip1); 00104 lightStrip1.setPixelColor(10, ledR*100, ledG*100, ledB*100); 00105 lightStrip1.setPixelColor(11, ledR*100, ledG*100, ledB*100); 00106 lightStrip1.setPixelColor(12, ledR*100, ledG*100, ledB*100); 00107 lightStrip1.setPixelColor(13, ledR*100, ledG*100, ledB*100); 00108 lightStrip1.setPixelColor(14, ledR*100, ledG*100, ledB*100); 00109 break; 00110 00111 case '4': 00112 clearScreen(lightStrip1); 00113 lightStrip1.setPixelColor(15, ledR*100, ledG*100, ledB*100); 00114 lightStrip1.setPixelColor(16, ledR*100, ledG*100, ledB*100); 00115 lightStrip1.setPixelColor(17, ledR*100, ledG*100, ledB*100); 00116 lightStrip1.setPixelColor(18, ledR*100, ledG*100, ledB*100); 00117 lightStrip1.setPixelColor(19, ledR*100, ledG*100, ledB*100); 00118 break; 00119 00120 case '5': 00121 clearScreen(lightStrip1); 00122 lightStrip1.setPixelColor(20, ledR*100, ledG*100, ledB*100); 00123 lightStrip1.setPixelColor(21, ledR*100, ledG*100, ledB*100); 00124 lightStrip1.setPixelColor(22, ledR*100, ledG*100, ledB*100); 00125 lightStrip1.setPixelColor(23, ledR*100, ledG*100, ledB*100); 00126 lightStrip1.setPixelColor(24, ledR*100, ledG*100, ledB*100); 00127 break; 00128 00129 case '6': 00130 clearScreen(lightStrip1); 00131 lightStrip1.setPixelColor(25, ledR*100, ledG*100, ledB*100); 00132 lightStrip1.setPixelColor(26, ledR*100, ledG*100, ledB*100); 00133 lightStrip1.setPixelColor(27, ledR*100, ledG*100, ledB*100); 00134 lightStrip1.setPixelColor(28, ledR*100, ledG*100, ledB*100); 00135 lightStrip1.setPixelColor(29, ledR*100, ledG*100, ledB*100); 00136 break; 00137 00138 default: 00139 break; 00140 00141 } 00142 lightStrip1.show(); 00143 WS2811::startDMA(); 00144 } 00145 } 00146 }
Generated on Wed Jul 20 2022 00:32:27 by
1.7.2