Simplified version of FFT code - drives on-board LED as a "Colour Organ".
Dependencies: FastAnalogIn NVIC_set_all_priorities mbed-dsp mbed
Fork of KL25Z_FFT_Demo_tony by
Diff: main.cpp
- Revision:
- 1:7c7539fba82b
- Parent:
- 0:b8c9dffbbe7e
- Child:
- 2:aa24865dfef5
--- a/main.cpp Tue Jun 17 14:03:36 2014 +0000 +++ b/main.cpp Thu Jul 10 06:54:57 2014 +0000 @@ -45,7 +45,7 @@ // Max allowed FFT_SIZE is 64 //////////////////////////////////////////////////////////////////////////////// -int SLOWDOWN = 4; // Create an optical delay in spectrumLoop - useful when only one RGB led is used. +int SLOWDOWN = 0; // Create an optical delay in spectrumLoop - useful when only one RGB led is used. // Only active when nonzero. // A value >= 1000 and <= 1000 + PIXEL_COUNT fixes the output to a single frequency // window = a single color. @@ -58,6 +58,7 @@ const int PIXEL_COUNT = 3; // Number of pixels (RGB LED). You should be able to increase this without // any other changes to the program. const int MAX_CHARS = 65; // Max size of the input command buffer +int PRINT_ON = 0; // flag to send chars continually to serial output //////////////////////////////////////////////////////////////////////////////// // INTERNAL STATE @@ -234,7 +235,7 @@ //////////////////////////////////////////////////////////////////////////////// void parseCommand(char* command) -{ +{ if (strcmp(command, "GET MAGNITUDES") == 0) { for (int i = 0; i < FFT_SIZE; ++i) { printf("%f\r\n", magnitudes[i]); @@ -265,15 +266,22 @@ printf("%d\r\n", SLOWDOWN); } else if (strstr(command, "SET SLOWDOWN") != NULL) { SLOWDOWN = (typeof(SLOWDOWN)) atoi(command+(sizeof("SET SLOWDOWN")-1)); - } - + } else if (strcmp(command, "GET HUES") == 0) { + for (int i = 0; i < PIXEL_COUNT; ++i) { + printf("%f\r\n", hues[i]); + } + } else if (strcmp(command, "GET FREQUENCIES") == 0) { + for (int i = 0; i < PIXEL_COUNT; ++i) { + printf("%f\r\n", frequencyWindow[i]); + } + } else if (strcmp(command, "PRINT_ON") == 0) { + PRINT_ON = 1; + } else if (strcmp(command, "PRINT_OFF") == 0) { + PRINT_ON = 0; + } // Update spectrum display values if sample rate was changed. if (strstr(command, "SET SAMPLE_RATE_HZ ") != NULL) { spectrumSetup(); - } else if (strcmp(command, "GET HUES") == 0) { - for (int i = 0; i < PIXEL_COUNT; ++i) { - printf("%f\r\n", hues[i]); - } } @@ -365,11 +373,15 @@ if (LEDS_ENABLED == 1) { spectrumLoop(); } - + wait_ms(10); // Restart audio sampling. samplingBegin(); - printf("this will make it work "); - } + if (PRINT_ON == 1) { + for (int i = 0; i < PIXEL_COUNT; ++i) { + printf("%f\r\n", hues[i]); + } + } + } // Parse any pending commands. if(commandRecv) {